I have added the plugin OneSignal for push notifications. (found it on the ionic market place, it looked cool)
However, since I added it I can no longer build my apk!
The error is "more than one library with package name ‘com.google.android.gms’ "
And indeed after checking my build.gradle in my android folder, I found:
compile "com.google.android.gms:play-services-gcm:7.3.0"
compile “com.google.android.gms:play-services-analytics:7.3.0”
But I did remove the plugin ionic analytics! Yet it sticks to my build.gradle, even when I erase it/delete the line, it comes back when I try to build…
Can you run ionic plugin list and ionic -version and post the results. This will help us reproduce the issue. Could you also post the full error from the console you’re seeing?
play-services-gcm and play-services-analytics isn’t the cause of your build error. They are not conflicting as they are just parts of gms (Google Play services).
If you still running into build issues after removing a plugin you might have to do a clean build to reset gradle. I have seen issues with other plugins before as well where a clean build is needed.
@eduzera The 'plugin.google.maps' includes 'com.google.playservices' as an ANT like dependency. I don’t see an updated Google Map plugins using the new gradle way of including Google Play services so you will need to use our compat version instead.
Please follow our Clean Build Guide and instead of adding 'onesignal-cordova-plugin' add 'onesignal-cordova-plugin-pgb-compat'. Lastly you will also need to the run the following: ionic plugin add cordova-plugin-android-support-v4
I’m testing a completely blank app with the OneSignal plugin and I am getting the aforementioned error as well. If I use the cordova-plugin-pgb-compat version of the plugin the app builds but it seems that notificationOpenedCallback() is never actually getting called, any ideals?
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find com.google.android.gms:play-services-gcm:7.3.0.
Searched in the following locations:
https://repo1.maven.org/maven2/com/google/android/gms/play-services-gcm/7.3.0/play-services-gcm-7.3.0.pom
https://repo1.maven.org/maven2/com/google/android/gms/play-services-gcm/7.3.0/play-services-gcm-7.3.0.jar
Required by:
:android:unspecified
> Could not find com.google.android.gms:play-services-analytics:7.3.0.
Searched in the following locations:
https://repo1.maven.org/maven2/com/google/android/gms/play-services-analytics/7.3.0/play-services-analytics-7.3.0.pom
https://repo1.maven.org/maven2/com/google/android/gms/play-services-analytics/7.3.0/play-services-analytics-7.3.0.jar
Required by:
:android:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
c:\Dev\ExactSupportCentre\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "c:\Dev\ExactSupportCentre\platforms\android\gradlew cdvBuildDebug -b c:\Dev\ExactSupportCentre\platforms\android\build.gradle -Dorg.gradle.daemon=true"
Error: c:\Dev\ExactSupportCentre\platforms\android\cordova\build.bat: Command failed with exit code 1
at ChildProcess.whenDone (C:\Users\CHRISM~1\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
I think I’ve figured it, just waiting for SDK manager to finish updating.
I’ve got two versions of the SDK on my computer, one that I installed myself for cordova, the other that the Android studio bundles. Turned out I was updating the wrong instance of the SDK, so will report back once I’ve managed to install the Google Play Services package for the correct SDK
OK, I had to install some additional packages through the SDK manager to get things going.
Under the extras folder,
Google Play Services
Google Repository
Android Support Repository (Android Support Library was already installed for me)
@CT14_IT In the SDK Manager the “Android Support Repository” and “Google Repository” are needed. This is shown on step 3. Android of our setup guide.
"cordova-plugin-pgb-compat" should only be used if you have other plugins that include either the “Android Support Library” or “Google Play services” that haven’t been updated to use the new gradle dependencies like the OneSignal plugin does. We have a OneSignal Compatibility guide you can see for when our compat plugin should be used instead of our normal one.
You said that notificationOpenedCallback() was not firing for you when opening a notification. Is that working for you now?
Hi @OneSignal, yeah all working now. I couldn’t figure out why it wasn’t working, I had added the correct dependencies through SDK Manager, but it seemed it was being ignored.
The issue was, I was updating the wrong instance of the Android SDK, it seems to have caught a few people out in general for Cordova/Android dev.
@pierro I added each of the plugins you listed to a new ionic project and was not able to reproduce a build issue. Are you seeing a compile error when if you add these plugins to a brand new project?
I noticed some of your plugin versions are older, what version of Cordova do you have installed. You can run cordova -version to see this. We recommend being on version 5.0 or later. You can update Cordova by running npm install -g cordova then double check it with -version.
Correct, OneSignal requires both the “Android Support Library” v4 and “Google Play services”. If you’re missing either one in the APK a user will show up on the OneSignal dashboard however they will show as unsubscribed.
@pierro Good to hear your up and running now. You won’t see Google Play Services or the Android Support library listed under cordova plugin list as they are being added as gradle dependencies. You will see the following line in <project-root>/platforms/android/build.gradle.
These depend on the Android Support Library so you don’t see these listed even in the gradle fiel. These are both pulled from the the Android SDK by gradle which is why these are required to be installed and updated.