gonzaloaune / GCMPushPlugin

Push notifications for Cordova (GCM & Native support)
MIT License
37 stars 20 forks source link

Bits missing for a successful installation: update versions, missing repository, missing dependencies #16

Open robert4os opened 8 years ago

robert4os commented 8 years ago

Hi, great plugin! Thanks a lot!

I found the following steps necessary to successfully cli build with your plugin.

Maybe these steps could be automatised during plugin installation? Unfortunately I know too little about Cordova plugins yet. In any case, it would be helpful to mention them in your README file.

2) Save downloaded google.services.json to platforms/android (i.e. not app or mobile)

3) Check https://developers.google.com/cloud-messaging/android/client for current Versions com.google.gms:google-services:1.5.0-beta2 com.google.android.gms:play-services:8.3.0

4) Add classpath 'com.google.gms:google-services:1.5.0-beta2' to platforms/android/build.gradle

    if (gradle.gradleVersion >= "2.2") {
        dependencies {
            classpath 'com.android.tools.build:gradle:1.0.0+'
            classpath 'com.google.gms:google-services:1.5.0-beta2'
        }
    } else if (gradle.gradleVersion >= "2.1") {
        dependencies {
            classpath 'com.android.tools.build:gradle:0.14.0+'
            classpath 'com.google.gms:google-services:1.5.0-beta2'
        }
    } else {
        dependencies {
            classpath 'com.android.tools.build:gradle:0.12.0+'
            classpath 'com.google.gms:google-services:1.5.0-beta2'
}

5) Add jcenter to platforms/android/build.gradle

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
...    

6) Install plugin https://www.npmjs.com/package/cordova-plugin-gcmpushplugin

cordova plugin add cordova-plugin-gcmpushplugin

  • This will create a.o.
platforms/android/cordova-plugin-gcmpushplugin/hello-build-extras.gradle
plugins/cordova-plugin-gcmpushplugin/build-extras.gradle

7) Edit plugins/cordova-plugin-gcmpushplugin/build-extras.gradle

apply plugin: 'com.google.gms.google-services'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
classpath 'com.google.gms:google-services:1.5.0-beta2'
    }
}

dependencies {
 compile "com.google.android.gms:play-services:8.3.0"
}

8) Overwrite other extra file cp plugins/cordova-plugin-gcmpushplugin/build-extras.gradle platforms/android/cordova-plugin-gcmpushplugin/hello-build-extras.gradle

srameshr commented 8 years ago

This is amazing! Thanks a lot! This should be pushed to the main README.md page.

Along with this, I found few more issues

STEP 9:

cp plugins/cordova-plugin-gcmpushplugin/build-extras.gradle platforms/android/cordova-plugin-gcmpushplugin/android-build-extras.gradle

STEP 10: If you get an error like

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

Then you have to create a separate gradle file by name build-extras.gradle and place it inside platforms/android directory. Inside this file you have to add:

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

That's it!. It should build after this.

UPDATE App crashes as soon as it is launched.

UPDATE This is because, I was using cordova facebook plugin. If you are doing so, then remove your old cordova plugin and add this: https://github.com/jeduan/cordova-plugin-facebook4/ .

This plugin does not require any change in your UI code. Just replace plugin with your original facebook app name and facebook app id and you are done. Then remove the contents inside build-extras.gradle. That is it. You are done. It should build.

UPDATE The build broke again, with the following error:

Found com.google.android.gms:play-services-location:+, but version 8.3.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-location:+, but version 8.3.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-location:+, but version 8.3.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-location:+, but version 8.3.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-location:+, but version 8.3.0 is needed for the google-services plugin.
:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 8.3.0.

I tried everything, like:

@robert4os @gonzaloaune Any answers for this?

ritikadhyawala commented 8 years ago

@srameshr , Hey were you able to solve the problem? I am facing the same issue.

srameshr commented 8 years ago

Just use phonegap-push plugin. That is way better and maintained.

ritikadhyawala commented 8 years ago

ok thanks