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

Commit

Permalink
Add resource-file way of copying google services files
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed May 5, 2017
1 parent a5c9e45 commit 46ba274
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
18 changes: 17 additions & 1 deletion docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,23 @@ or
cordova plugin add https://github.com/phonegap/phonegap-plugin-push
```

As of version 2.0.0 the SENDER_ID parameter has been removed at install time. Instead you put your google-services.json (Android) and/or GoogleService-Info.pList in the root folder of your project and the plugin's hooks will copy the file to the correct place in the platforms directory for you.
As of version 2.0.0 the SENDER_ID parameter has been removed at install time. Instead you put your google-services.json (Android) and/or GoogleService-Info.pList in the root folder of your project and then add the following lines into your plugin.xml.

In the platform tag for Android add the resource-file tag:

```
<platform name="android">
<resource-file src="google-services.json" target="google-services.json" />
</platform>
```

In the platform tag for iOS add the resource-file tag:

```
<platform name="ios">
<resource-file src="GoogleService-Info.plist" />
</platform>
```

> Note: if you are using Ionic you may need to specify the SENDER_ID variable in your package.json.
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<engine name="cordova-ios" version=">=4.4.0"/>
</engines>
<platform name="android">
<!-- hook type="before_plugin_install" src="scripts/copyAndroidFile.js"/ -->
<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"/>
Expand Down
32 changes: 10 additions & 22 deletions scripts/copyAndroidFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,17 @@ module.exports = function(ctx) {
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 project's root 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);
});

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;
Expand Down
3 changes: 2 additions & 1 deletion src/android/com/adobe/phonegap/push/FCMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void setNotification(int notId, String message){
@Override
public void onMessageReceived(RemoteMessage message){

Log.d(LOG_TAG, "onMessage - from: " + message.getFrom());
String from = message.getFrom();
Log.d(LOG_TAG, "onMessage - from: " + from);

Bundle extras = new Bundle();

Expand Down

0 comments on commit 46ba274

Please sign in to comment.