Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
🐛 Issue #1188: Strings.xml google_app_id conflict with google-service…
Browse files Browse the repository at this point in the history
…s.json
  • Loading branch information
macdonst committed May 4, 2017
1 parent f84574a commit b41580f
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 127 deletions.
226 changes: 101 additions & 125 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,129 +14,105 @@
Windows uses Microsoft WNS Notifications.
</description>

<<<<<<< HEAD
<license>MIT</license>
<js-module src="www/push.js" name="PushNotification">
<clobbers target="PushNotification"/>
</js-module>
<engines>
<engine name="cordova" version=">=6.4.0"/>
<engine name="cordova-android" version=">=6.0.0"/>
<engine name="cordova-ios" version=">=4.3.0"/>
</engines>
<preference name="SENDER_ID" default="85075801930"/>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="PushNotification">
<param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/>
</feature>
</config-file>
<config-file target="res/values/strings.xml" parent="/resources">
<string name="google_app_id" translatable="false">$SENDER_ID</string>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
<uses-permission android:name="${applicationId}.permission.PushHandlerActivity"/>
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<permission android:name="${applicationId}.permission.PushHandlerActivity" android:protectionLevel="signature"/>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.push.PushHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.PushHandlerActivity"/>
<receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler"/>
<!-- receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="${applicationId}"/>
</intent-filter>
</receiver -->
<service android:name="com.adobe.phonegap.push.GCMIntentService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.adobe.phonegap.push.PushInstanceIDListenerService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<!-- service android:name="com.adobe.phonegap.push.RegistrationIntentService" android:exported="false"/ -->
</config-file>
<framework src="push.gradle" custom="true" type="gradleReference"/>
<framework src="com.android.support:support-v13:23+"/>
<framework src="me.leolin:ShortcutBadger:1.1.14@aar"/>
<framework src="com.google.firebase:firebase-messaging:9.0.0" />
<source-file src="src/android/com/adobe/phonegap/push/GCMIntentService.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushHandlerActivity.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushPlugin.java" target-dir="src/com/adobe/phonegap/push/"/>
<!-- source-file src="src/android/com/adobe/phonegap/push/RegistrationIntentService.java" target-dir="src/com/adobe/phonegap/push/"/ -->
<source-file src="src/android/com/adobe/phonegap/push/PermissionUtils.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/BackgroundActionButtonHandler.java" target-dir="src/com/adobe/phonegap/push/"/>
</platform>
<platform name="browser">
<js-module src="www/browser/push.js" name="BrowserPush">
<clobbers target="PushNotification"/>
</js-module>
<asset src="src/browser/ServiceWorker.js" target="ServiceWorker.js"/>
<asset src="src/browser/manifest.json" target="manifest.json"/>
</platform>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="PushNotification">
<param name="ios-package" value="PushPlugin"/>
</feature>
</config-file>
<config-file target="*-Info.plist" parent="UIBackgroundModes">
<array>
<string>remote-notification</string>
</array>
</config-file>
<config-file target="*-Info.plist" parent="GCM_SENDER_ID">
<string>$SENDER_ID</string>
</config-file>
<config-file target="*-Info.plist" parent="IS_GCM_ENABLED">
<true/>
</config-file>
<config-file target="*-Debug.plist" parent="aps-environment">
<string>development</string>
</config-file>
<config-file target="*-Release.plist" parent="aps-environment">
<string>production</string>
</config-file>
<source-file src="src/ios/AppDelegate+notification.m"/>
<source-file src="src/ios/PushPlugin.m"/>
<header-file src="src/ios/AppDelegate+notification.h"/>
<header-file src="src/ios/PushPlugin.h"/>
<framework src="AddressBook.framework"/>
<framework src="libsqlite3.tbd"/>
<framework src="libz.tbd"/>
<!-- framework src="GoogleCloudMessaging" type="podspec" spec="~> 1.2.0"/>
<framework src="GGLInstanceID" type="podspec" spec="~> 1.2.1"/ -->
<!-- Start FCM Related Files -->
<header-file target-dir="FCM/Headers" src="src/ios/Firebase/Headers/Firebase.h" />

<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Analytics/FirebaseAnalytics.framework" framework="true" />
<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Analytics/FirebaseInstanceID.framework" framework="true" />
<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Analytics/GoogleInterchangeUtilities.framework" framework="true" />
<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Analytics/GoogleSymbolUtilities.framework" framework="true" />
<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Analytics/GoogleUtilities.framework" framework="true" />
<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Messaging/FirebaseMessaging.framework" framework="true" />
<source-file target-dir="FCM/Libraries" src="src/ios/Firebase/Messaging/GoogleIPhoneUtilities.framework" framework="true" />
<!-- End FCM Related Files -->
</platform>
<platform name="windows">
<hook type="after_plugin_install" src="hooks/windows/setToastCapable.js"/>
<js-module src="src/windows/PushPluginProxy.js" name="PushPlugin">
<runs/>
</js-module>
<config-file target="config.xml" parent="/*">
<preference name="WindowsToastCapable" value="true"/>
</config-file>
</platform>
<license>MIT</license>

<js-module src="www/push.js" name="PushNotification">
<clobbers target="PushNotification" />
</js-module>

<engines>
<engine name="cordova" version=">=6.4.0"/>
<engine name="cordova-android" version=">=6.0.0"/>
<engine name="cordova-ios" version=">=4.3.0"/>
</engines>

<!-- android -->
<platform name="android">
<hook type="before_plugin_install" src="scripts/copyAndroidFile.js" />

<config-file target="res/xml/config.xml" parent="/*">
<feature name="PushNotification" >
<param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/>
</feature>
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.push.PushHandlerActivity" android:exported="true"/>
<receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler"/>
<service
android:name="com.adobe.phonegap.push.FCMService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.adobe.phonegap.push.PushInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</config-file>

<framework src="com.android.support:support-v13:23+" />
<framework src="me.leolin:ShortcutBadger:1.1.11@aar"/>
<!-- framework src="com.google.gms:google-services:3.0.0" /-->
<framework src="com.google.firebase:firebase-messaging:9+" />
<framework src="push.gradle" custom="true" type="gradleReference" />

<source-file src="src/android/com/adobe/phonegap/push/FCMService.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/PushHandlerActivity.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/PushPlugin.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/PermissionUtils.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/BackgroundActionButtonHandler.java" target-dir="src/com/adobe/phonegap/push/" />

</platform>

<!-- ios -->
<platform name="ios">

<config-file target="config.xml" parent="/*">
<feature name="PushNotification">
<param name="ios-package" value="PushPlugin"/>
</feature>
</config-file>

<config-file target="*-Info.plist" parent="UIBackgroundModes">
<array>
<string>remote-notification</string>
</array>
</config-file>

<source-file src="src/ios/AppDelegate+notification.m" />
<source-file src="src/ios/PushPlugin.m" />

<header-file src="src/ios/AppDelegate+notification.h" />
<header-file src="src/ios/PushPlugin.h" />

<!-- Start FCM Related Files -->
<framework src="FirebaseMessaging" type="podspec" spec="~> 1.2.1"/>

<!-- resource-file src="src/ios/GoogleService-Info.plist" target="Resources/GoogleService-Info.plist" / -->
<hook src="scripts/copy_file.js" type="after_prepare" />
<!-- End FCM Related Files -->
</platform>

<!-- windows -->
<platform name="windows">
<js-module src="src/windows/PushPluginProxy.js" name="PushPlugin">
<merges target="" />
</js-module>
<config-file target="config.xml" parent="/*">
<preference name="WindowsToastCapable" value="true" />
</config-file>
</platform>
>>>>>>> :bug: Issue #1188: Strings.xml google_app_id conflict with google-services.json
</plugin>
4 changes: 4 additions & 0 deletions push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def doExtractStringFromManifest(name) {
return matcher.group(1)
}

cdvPluginPostBuildExtras << {
apply plugin: 'com.google.gms.google-services'
}

android {
sourceSets {
main {
Expand Down
34 changes: 34 additions & 0 deletions scripts/copyAndroidFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = function(ctx) {
var fs = ctx.requireCordovaModule('fs'),
path = ctx.requireCordovaModule('path'),
os = require("os"),
readline = require("readline"),
deferral = ctx.requireCordovaModule('q').defer();

var settingsFile = path.join(ctx.opts.projectRoot, 'google-services.json');

fs.stat(settingsFile, function(err,stats) {
if (err) {
deferral.reject("To use this plugin on android you'll need to add a google-services.json file with the FCM project_info and place that into your www folder");
} else {

fs.createReadStream(settingsFile).pipe(fs.createWriteStream('platforms/android/google-services.json'));

var lineReader = readline.createInterface({
terminal: false,
input : fs.createReadStream('platforms/android/build.gradle')
});
lineReader.on("line", function(line) {
fs.appendFileSync('./build.gradle', line.toString() + os.EOL);
if (/.*\ dependencies \{.*/.test(line)) {
fs.appendFileSync('./build.gradle', '\t\tclasspath "com.google.gms:google-services:3.0.0"' + os.EOL);
}
}).on("close", function () {
fs.rename('./build.gradle', 'platforms/android/build.gradle', deferral.resolve);
});

}
});

return deferral.promise;
};
11 changes: 10 additions & 1 deletion scripts/copy_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ if(fileExists("GoogleService-Info.plist") && directoryExists("platforms/ios/")){
} catch(err) {
process.stdout.write(err);
}
}
}

if(fileExists("google-services.json") && directoryExists("platforms/android/")){
try {
var contents = fs.readFileSync("google-services.json").toString();
fs.writeFileSync("platforms/android/google-services.json", contents);
} catch(err) {
process.stdout.write(err);
}
}
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ public interface PushConstants {
public static final String IMAGE_TYPE_SQUARE = "square";
public static final String IMAGE_TYPE_CIRCLE = "circle";
public static final String GOOGLE_APP_ID = "google_app_id";
public static final String GCM_DEFAULT_SENDER_ID = "gcm_defaultSenderId";
}
2 changes: 1 addition & 1 deletion src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void run() {

Log.v(LOG_TAG, "execute: jo=" + jo.toString());

senderID = getStringResourceByName(GOOGLE_APP_ID);
senderID = getStringResourceByName(GCM_DEFAULT_SENDER_ID);

Log.v(LOG_TAG, "execute: senderID=" + senderID);

Expand Down

0 comments on commit b41580f

Please # to comment.