phonegap/phonegap-plugin-push

cordova run android not working

Closed this issue Β· 165 comments

Expected Behaviour

I'm trying to do 'cordova run android'

Actual Behaviour

Error: /Users/giladkaplan1/Projects/Production/EPAActive/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • Where:
    Script '/Users/giladkaplan1/Projects/Production/EPAActive/platforms/android/phonegap-plugin-push/XXXXXX-push.gradle' line: 12

  • What went wrong:
    A problem occurred evaluating root project 'android'.

Failed to apply plugin [id 'com.google.gms.google-services']
For input string: "+"

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Cordova CLI version and cordova platform version

cordova : 6.5.0
ionic: 2.2.3

cordova platform version android                     6.2.1

Plugin version

I'm using this version because i need FCM
cordova plugin version | grep phonegap-plugin-push phonegap-plugin-push 2.0.0-rc3 "PushPlugin"

Please help!!!! I'm stuck for 2 whole days on this error

thanks

@giladKaplan I don't think the problem is coming from this plugin. It is probably another plugin that is using the + to include dependencies.

@giladKaplan Could you post your list of installed cordova plugins and the content of the file /Users/giladkaplan1/Projects/Production/EPAActive/platforms/android/phonegap-plugin-push/XXXXXX-push.gradle?

@fredgalvao ,

XXXXXX-push.gradle

`import java.util.regex.Pattern

def doExtractStringFromManifest(name) {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile(name + "="(.*?)"")
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return matcher.group(1)
}

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

android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
}

defaultConfig {
    applicationId = doExtractStringFromManifest("package")
}

}
`

List of plugins

"cordova-custom-config": {},
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-epa": {},
"cordova-plugin-google-analytics": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"phonegap-plugin-push": {}

@giladKaplan try building without cordova-plugin-google-analytics

I have the same issue :(
When I build without analytics it works as you said, but in my case I need both plugins :(
I'll try to look at analytics plugin issues

I opened up the generated android platform up in Android Studio and I was able to get the build further along. Basically some plugins add dependencies for play services e.g. googleplus. During the build

  compile "com.google.android.gms:play-services-auth:+"
  compile "com.google.android.gms:play-services-identity:+"

Cordova does some regex voodoo and changes mapped library numbers so even if you force a version it still uses the +.

From Cordova GradleBuilder.js
 // For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
    var SYSTEM_LIBRARY_MAPPINGS = [
        [/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
        [/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/, 'com.google.android.gms:play-services:+']

Whenever you run cordova build it will do the regex and replace a custom version number. E.g. 9.2.1 so that will break it. But I went in android studio and manually changed the numbers and did an android gradle build (without cordova build magic)

compile "com.google.android.gms:play-services-auth:9.2.1"
compile "com.google.android.gms:play-services-identity:9.2.1"

Now I am getting an error

Error:Execution failed for task ':transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

So the issues is it is a version conflict I belive as well as a cordova problem without being able to force a version number YAY! πŸ‘Ž

Hope this helps. We may need to see if there is a way for cordova (issue request) to not do this if a config value is manually set. IDK

Ok I set it to match the firebase messaging lib and it worked and built in android studio.

build.gradle

    compile "com.google.android.gms:play-services-auth:9.8.0"
    compile "com.google.android.gms:play-services-identity:9.8.0"
    compile "com.android.support:support-v13:25.1.0"
    compile "com.google.firebase:firebase-messaging:9.8.0"

Ok so I got it to work with cordova build.

I edited the other plugins (googleplus) plugin.xml and changed it to use a specific version that was compatible.

    <framework src="com.google.android.gms:play-services-auth:9.8.0" />
    <framework src="com.google.android.gms:play-services-identity:9.8.0" />

I deleted the android platform and rebuilt.

Which was funny, because I upgraded to the version that used cocoapods to avoid issues with duplicate symbols on IOS, but then it broke Android lol 😹

Here is a hacky πŸ”§ way to fix it temporarily so it will run and be fixed, basically create a custom cordova hook.

https://gist.github.com/ianlintner-wf/9b042900cd70b518b506fb989d7085c0

Put this hook in your config with the filename.
<hook src="scripts/gradle-fix.js" type="before_prepare" />

This may not fix your situation, but my limited knowledge of the cordova build process and gradle I managed to hack my way through the issue in cordova/ionic.

@ianlintner-wf thanks for looking into this. I'm going to talk to Joe today to see if we can get a true fix in cordova-android.

Hmm...the root cause of this issue is that this line https://github.com/phonegap/phonegap-plugin-push/blob/v2.0.x/push.gradle#L12 should be applied after the dependencies are setup. Trying to figure out a way to make that happen.

I did a little more digging. So the dependencies are not updated in the project.properties on build so if the plugins are updated I had to remove the platform android folder. There is probably good reason for this. (or in my case I didn't see it rebuilt)

I wrote the above script so I didn't have to hack/fork the node_modules/problem plugins configs. I don't know off hand if the config.xml overrides plugins. But basically the crux of the issue is version conflict and gradle barfs when other plugins try to use '+' as a version with the different versions com.google.android.gms:play-services & com.google.gms.google-services

The error message is not very descriptive and I have no gradle knowledge so I don't know why the '+' is an issue, but it is when other plugins use it and gets applied added to the project.properties for that library.

@ianlintner-wf the hook didn't do it for me. Any other suggestions? Thanks

I got around it by going to project.properties and changing
cordova.system.library.2=com.google.android.gms:play-services-analytics:+
to
cordova.system.library.2=com.google.android.gms:play-services-analytics:9.8.0

But this needs a proper fix

I don't using the analytics service and get the same error.

Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

Where:
Script 'C:\app\platforms\android\phonegap-plugin-push\android-push.gradle' line: 12

What went wrong:
A problem occurred evaluating root project 'android'.

Failed to apply plugin [id 'com.google.gms.google-services']
For input string: "+"

this is my project.properties

target=android-25
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-firebase/android-build.gradle
cordova.system.library.1=com.google.firebase:firebase-core:+
cordova.system.library.2=com.google.firebase:firebase-messaging:+
cordova.system.library.3=com.google.firebase:firebase-crash:+
cordova.system.library.4=com.google.firebase:firebase-config:+
cordova.system.library.5=com.android.support:support-v13:25.1.0
cordova.system.library.6=me.leolin:ShortcutBadger:1.1.14@aar
cordova.system.library.7=com.google.firebase:firebase-messaging:9.8.0
cordova.gradle.include.2=phonegap-plugin-push/android-push.gradle

@performatric it's the cordova-plugin-firebase. You should use either cordova-plugin-firebase or phonegap-plugin-push as they don't coexist well.

@performatric try changing to something like below then run the build:

cordova.system.library.1=com.google.firebase:firebase-core:9.8.0
cordova.system.library.2=com.google.firebase:firebase-messaging:9.8.0
cordova.system.library.3=com.google.firebase:firebase-crash:9.8.0
cordova.system.library.4=com.google.firebase:firebase-config:9.8.0
cordova.system.library.5=com.android.support:support-v13:25.1.0
cordova.system.library.6=me.leolin:ShortcutBadger:1.1.14@aar
cordova.system.library.7=com.google.firebase:firebase-messaging:9.8.0
cordova.gradle.include.2=phonegap-plugin-push/android-push.gradle

I tried, but returns the same error =/

jabit commented

I fixed the issue doing:
#cordova.system.library.1=com.google.android.gms:play-services-auth:+
#cordova.system.library.2=com.google.android.gms:play-services-identity:+
cordova.system.library.1=com.google.android.gms:play-services-auth:9.8.0
cordova.system.library.2=com.google.android.gms:play-services-identity:9.8.0

Based on another issue with GCM vs FCM, I needed to move to phonegap-plugin-push@2.0.0-rc5. Thus in order to do that I had to update my cordova platform update android@6.2.1 - which then also forced me to update cordova-plugin-admobpro@latest. Ok...got everything update and installed...then added back in phonegap-plugin-push@2.0.0-rc5...it adds just fine. But when I compile the app...well, it downloads damn near 100 *.pom files...and around the 100th 'download' it fails with error:

  • What went wrong:
    A problem occurred evaluating root project 'android'.

Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
For input string: "+"

Now, based on the above reading, I don't have plugin-firebase or plugin-analytics so I don't know what is causing this issue. How can I fix it?

Here are my plugins:
br.com.dtmtec.plugins.carrier 1.0.0 "Carrier"
cl.rmd.cordova.dialoggps 0.0.2 "DialogGPS"
com.lampa.startapp 0.1.4 "startApp"
com.ludei.webview.plus 2.4.3 "Webview+"
com.phonegap.plugins.nativesettingsopener 1.0 "Native settings"
com.verso.cordova.clipboard 0.1.0 "Clipboard"
com.vliesaputra.deviceinformation 1.0.1 "DeviceInformation"
cordova-custom-config 3.1.2 "cordova-custom-config"
cordova-instagram-plugin 0.5.4 "Instagram"
cordova-plugin-admobpro 2.29.0 "AdMob Plugin Pro"
cordova-plugin-appavailability 0.4.2 "AppAvailability"
cordova-plugin-appinfo 2.1.1 "AppInfo Plugin"
cordova-plugin-apprate 1.2 "AppRate"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-device-motion 1.2.3 "Device Motion"
cordova-plugin-device-orientation 1.0.5 "Device Orientation"
cordova-plugin-dialogs 1.3.1 "Notification"
cordova-plugin-email 1.2.6 "EmailComposer"
cordova-plugin-extension 1.5.1 "Cordova Plugin Extension"
cordova-plugin-fastrde-checkgps 1.0.0 "checkGPS"
cordova-plugin-file 4.3.1 "File"
cordova-plugin-geolocation 2.4.1 "Geolocation"
cordova-plugin-globalization 1.0.5 "Globalization"
cordova-plugin-inappbrowser 1.6.1 "InAppBrowser"
cordova-plugin-request-location-accuracy 2.2.0 "Request Location Accuracy"
cordova-plugin-sim 1.3.3 "SIM"
cordova-plugin-splashscreen 4.0.1 "Splashscreen"
cordova-plugin-statusbar 2.2.1 "StatusBar"
cordova-plugin-vibration 2.1.3 "Vibration"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-sms-plugin 0.1.11 "Cordova SMS Plugin"
cordova.plugins.diagnostic 3.4.2 "Diagnostic"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-facebook-plugin 0.12.0 "Facebook Connect"
phonegap-plugin-push 2.0.0-rc5 "PushPlugin"

@rolinger Just to rule it out: can you confirm you have your Android SDK updated as needed? (see the docs for directions on this)

hmmmm....I did all the automatic updates already. but when I look in my Android SDK Manager I see android support library - v23.2.1, but its not showing me that any updates are available. As well, there is no specific entry for Firebase Support Library - how/where can I get these installed if the SDK Manager does't even list them as options?

They are part of the Google Play services and Google repository entries, iirc.

@fredgalvao - uh, ok...read the install directions a bit more and now I am going to ask a really dumb question. I am on a windows system, and android update sdk --no-ui --filter "extra" - doesn't exist. Rather android doesn't exist. I have always updated via the SDK Manager, so this method is new to me. what is the Windows equivalent to android ?

In SDK Manager, these are installed:
Google Play Services: v41
Google Repository: v53

How can I force updates to android support library and firebase support library?

Recent versions of android changed that command, and I can't really help you with it. However, if you have the ones you mentioned plus the Android Support Repository updated looking at the SDK Manager, then that's not the issue on your case.

Would you be able to create an empty cordova project and try to add the push plugin to it? That will say for sure whether your issue is with the sdk manager or not.

What am I missing here, in the documentation it states you need:
Android Support Library version 25.1.0 FirebaseMessaging Library version 9.8.0

However, in my sdk manager I have the most recent version 23.2.1...there is no option to update to a higher version. As well, I don't have FirebaseMessaging in my SDK Manager. How can I upgrade/add these two sdk's? I did find the android bat file which is what everyone above was referencing, just not certain if I can get those two sdks with it.

I am stuck.

@fredgalvao @macdonst - uh...got it all working, but I don't even understand how. Please reference for my update: #1812

Well...spoke to soon. It all worked. Uninstall my app from my phone and reinstalled to test other "registration" components (not related)...did not touch any of the push stuff (esp after I finally got it all working again). And then this:

This is one from a 2.5 hours ago when I got β€œsuccess” but no message ever arrived:

Time Stamp: 12:50pm
PushID: cnt4-8F0D04:APA91bFCUNHdGa5xjjSIAt9U_3ITWwH53edDaYxc0WewrLLzoUpFtu7W8AUSreohWOACbb0LNHt3RAdWFf8QJSkcfqZo__UiUuy5uyfte8q6oK6ISVibAsVZW9eURjNs7o34fP8D2Sh1
object(stdClass)#4 (5) { ["multicast_id"]=> int(7727871665417217028) ["success"]=> int(1) ["failure"]=> int(0) ["canonical_ids"]=> int(0) ["results"]=> array(1) { [0]=> object(stdClass)#5 (1) { ["message_id"]=> string(35) "0:1498579447399689%94806eb594806eb5" } } }

Frustrated, I left the house to go run some errands, came back and tested again and got this:

Time Stamp: 3:15pm
PushID: cnt4-8F0D04:APA91bFCUNHdGa5xjjSIAt9U_3ITWwH53edDaYxc0WewrLLzoUpFtu7W8AUSreohWOACbb0LNHt3RAdWFf8QJSkcfqZo__UiUuy5uyfte8q6oK6ISVibAsVZW9eURjNs7o34fP8D2Sh1
object(stdClass)#4 (5) { ["multicast_id"]=> int(4811433973238781554) ["success"]=> int(0) ["failure"]=> int(1) ["canonical_ids"]=> int(0) ["results"]=> array(1) { [0]=> object(stdClass)#5 (1) { ["error"]=> string(13) "NotRegistered" } } }

I give up.

For what its worth. I moved over to the cordova-plugin-firebase plugin and pretty much got everything working with no extra cordova/ionic configurations. Simply just add the GoogleService files to the root of your project and compile. I think the 'phonegap-plugin-pushis more developed than thecordova-plugin-firebase` but I got what I needed for my app so I left it at that.

My problem is mostly the collision, I tried the gist to replace the x with actual numbers but even that ended up in a bunch of weird ios errors being spewed out on build, and after a few hours that is where I stopped looking into it.
Btw I was trying to go from 1 to 2 with this plugin to use fcm on ios but yeah somehow 2 collides with EddyVerbruggen/cordova-plugin-googleplus and 1 doesn't

With 2.0.0 released, @macdonst is this being fixed on cordova-android? Or is a 2.0.1 due already?

I solved it as follows:
Go to platform->android->project.properties and assign a version number for com.google.android.gms:play-services-base:11.0.1 (I matched it to the firebase-messaging version)
If you recompile now, it will complain about google-services.json file. You can create and download it from https://developers.google.com/mobile/add?refresh=1. Save that file in the root folder of your ionic project.
It should recompile now without errors.

I am still learning about this Firebase and GCM changes. I hope the setup works in the end.

hello everyone, I'm also struggling with this error.

Go to platform->android->project.properties and assign a version number for
cordova.system.library.5=com.google.android.gms:play-services-auth:11.0.1
cordova.system.library.6=com.google.android.gms:play-services-identity:11.0.1

And it got fixed

@macdonst any idea when to fix it, workaround, trick, whatever ? This plugin looks a perfect, brilliant and elegant implementation of client-side of push notification.
I'm considering move to https://github.com/arnesson/cordova-plugin-firebase til get phonegap-plugin-push working properly.

@faustoct If I'm not mistaken, this is being done/discussed through https://issues.apache.org/jira/browse/CB-13145 as a solution coming from inside cordova itself, rather than relying on plugin authors to agree on versions (which it seems some of them can't).

@fredgalvao thanks, I didn't know that ! I'm think to fork this project and set same version of existent googleplay-service of firebase plugin. Meantime keeping an eye on this major issue to get a proper fix/solution.

Please provide a solution for this problem. None of the above mentioned solutions worked for me. So I had to shift to https://github.com/arnesson/cordova-plugin-firebase

@karansharma27 I'm going to move temporarily to cordova-plugin-firebase til get phonegap-plugin-push working . It does support everything except upstream messaging . arnesson/cordova-plugin-firebase#380 (comment)

cordova-plugin-firebase does not support action buttons. Neither it is compatible with Hotline, so there is problem in notifications..

@fredgalvao isn't this problem (I'm currently facing it too) related to this topic we already discussed earlier this year?

jeduan/cordova-plugin-facebook4#507

ok so in my case was a classic conflict error, like discussed jeduan/cordova-plugin-facebook4#507

in my platform/android/project.properties I had to change following line to fix the conflict problem

Bad:

cordova.system.library.3=com.google.android.gms:play-services-analytics:+

Good:

cordova.system.library.3=com.google.android.gms:play-services-analytics:11.0.1

P.S.: Opened an issue in the analytics plugin about that problem danwilson/google-analytics-plugin#464

@peterpeterparker I have tried everything, still it doesn't work.

@karansharma27 check your platform/android/project.properties if you find any decencies ending with :+

if so, that might be the source of your conflict

@peterpeterparker Yes, it is. The thing in this one though is that @macdonst doesn't want to tackle it with a fixed version, it seems, so a proposition was made from withing cordova itself, to fix this specific case of the play services versions, which seems like the "most often one involved in this kind of issue" (I don't have those stats, and they don't obey the set of issues I dealt with recently), with a variable configurable by the user to specify which play services version will be ultimately used on the whole android project, regardless of which ones the plugins asked for (if any).

I for one don't agree with this approach, as it won't solve all issues (the :android-support group for example was responsible for quite a few of the issues I handled on this topic on many plugins). However, for "my approach" to win, we'd have to fight with all plugin authors over the argument that versions need to be specific instead of open-ended. And considering some authors still think it's okay to include alpha versions as dependencies, it's a zero-sum game for me ;).

@fredgalvao thx a lot for the clear summary of the current state

in my case the conflict comes from the analytics plugin, hopefully his author gonna be agree to set a specific version, also it's always a faster solution than including a fix in a all new version of cordova itself

Hey all,

Working with my teammates to fix this problem in Cordova/Cordova Android.

So right now we have:

<framework src="com.google.firebase:firebase-messaging:11.0.1"/>

and when it is done we can specify:

<preference name="FCM_VERSION" default="+"/>
<framework src="com.google.firebase:firebase-messaging:$FCM_VERSION"/>

Then users will be able to over-ride the FCM/Play services version to match other plugins that depend on the same framework but pin a specific version.

Sorry this is taking awhile but there is a bunch of moving parts. Unfortunately, this shouldn't even be an issue but the com.google.gms.google-services doesn't like wildcards.

This is what my project.properties files looks like:

android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-android-play-services-gradle-release/app-cordova-android-play-services-gradle-release.gradle
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.gradle.include.2=cordova-plugin-mauron85-background-geolocation/app-logtofile.gradle
cordova.system.library.2=com.google.android.gms:play-services-location:+
cordova.system.library.3=com.android.support:support-v4:+
cordova.system.library.4=com.android.support:support-v4:+
cordova.system.library.5=com.android.support:support-v13:25.1.0
cordova.system.library.6=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.7=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.3=phonegap-plugin-push/app-push.gradle

Changed all com.android.support:support-v4 to 24.1.1 and
com.google.android.gms:play-services-location to 11.0.1 gave the following error:

Execution failed for task ':transformClassesWithJarMergingForRelease'.
        > com.android.build.api.transform.TransformException: java.util.zip.ZipException:
        duplicate entry: com/google/android/gms/internal/zzceb.class 

@shyamal890 try support-v4:24.1.1+ not support-v4:24.1.1

furthermore, maybe still something to modify inside app-cordova-android-play-services-gradle-release.gradle and app-logtofile.gradle

support-v4:24.1.1+ causes the same issue as mentioned in the first comment. Spent around 5 hrs trying to solve this, now tired, going to sleep. Seriously hope @macdonst soon finds a solution to this.

@shyamal890 read my update from 3 hours ago. It's a tough problem to solve and has implications outside of this plugin.

The only real work around right now is to import the project in platforms/android into Android Studio and modify the project.properties so all play services, fcm, etc use the same version as @morariu mentions above.

I'm a plugin author and I often experience collisions with my plugins.

Could someone give this a try: cordova-google-api-version

Insert any desired version you wish to pin all plugins' google API dependencies at:

$ cordova plugin add cordova-google-api-version --variable GOOGLE_API_VERSION=11.2.0

All plugins are now pinned at this version.

To change the version, re-install the plugin:

$ cordova plugin add cordova-google-api-version --variable GOOGLE_API_VERSION=11.0.1

The gist of the plugin is to do this

Gradle ResolutionStrategy

I have a test app with the following plugins all requiring google APIs and the app builds successfully.

$ cordova plugins
cordova-google-api-version 0.0.1 "cordova-google-api-version"
com.googlemaps.ios 2.4.0 "Google Maps SDK for iOS"
cordova-background-geolocation-lt 2.8.3 "BackgroundGeolocation"
cordova-plugin-fcm 2.1.2 "FCMPlugin"
cordova-plugin-googlemaps 1.4.5 "cordova-googlemaps-plugin"
phonegap-plugin-push 2.0.0 "PushPlugin"

NOTE: the above plugin will not solve issues with this plugin where another plugin requests version :+.

:11.+ format is fine.

Perfect

@christocracy Please change the name of your plugin to cordova-google-api-version in your comment.

@tobiasmuecksch the problem with doing that is your edits will be lost when you $ cordova platform remove android. You cannot store those edits in source-control.

If you have multiple developers working on your project, you'd have to place those instructions into a README file and be sure to make sure you've made those changes before publishing your app.

@christocracy I totally agree. This has to be fixed. I just wanted to share the solution I found

In my company we created a npm script which every developer has to run after initializing the project (that includes this fix and more). That's a poor workaround - I know.

@tobiasmuecksch Did you try my new plugin mentioned above? It'll pin all plugins to your desired GOOGLE_API_VERSION as long as no other plugin uses :+ for version.

Update: I've just finished testing some changes in Apache Cordova (commons, cli, lib and android repos) that fixes (works around) this issues. Once Cordova releases all the components the plugin needs I'll release a new version of this plugin and start sending PR's to other affected plugins.

For now keep using @christocracy work around. The nice thing about the upcoming fix is that it does not require a hook to run so it will work on PhoneGap Build.

Hello, I still have a problem from my end

I would like to use both firebase ( analytics ) and firebase ( push notification FCM )

I am using phonegap build

in my config.xml I have

in my FCMPlugin.gradle
I have

buildscript

{
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
//apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

So far no + sign
But when I compile in PGB I have this error

FAILURE: Build failed with an exception.

  • Where:
    Script '/project/cordova-plugin-fcm/app-FCMPlugin.gradle' line: 13

  • What went wrong:
    A problem occurred evaluating script.

Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
For input string: "+"

Any idea ?

@canado you are stuck until the Cordova changes land.

@macdonst I am afraid to ask, but what do you mean ?

@macdonst would that be cordova-android 6.2.4 ?

Build Error: Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']

It looks like you have another dependency on a google play services lib with a generic verison *. You have to fix ALL dependency version(s) to be more more specific like 11.0.+. In order to do that fix version strings for any play services library you have in platforms/android/project.properties.

@canado read this comment: #1718 (comment)

@shyamal890 it will be cordova-android 6.3.0.

I'm having the same issue but @christocracy's solution isn't working for me. Here's my project.properties:

target=android-25
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-background-geolocation/ionicpeachdelivery-build.gradle
cordova.system.library.1=com.android.support:support-v13:25.1.0
cordova.system.library.2=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.3=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.2=phonegap-plugin-push/ionicpeachdelivery-push.gradle
cordova.system.library.4=com.squareup.okhttp3:okhttp:3+
cordova.gradle.include.3=cordova-google-api-version/ionicpeachdelivery-cordova-google-api-version.gradle

and cordova plugins:

cordova-background-geolocation 2.6.0 "BackgroundGeolocation"
cordova-google-api-version 0.0.1 "cordova-google-api-version"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-background-fetch 4.0.4 "CDVBackgroundFetch"
cordova-plugin-console 1.0.7 "Console"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-splashscreen 3.2.2 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-whitelist 1.2.2 "Whitelist"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"
ionic-plugin-deeplinks 1.0.15 "Ionic Deeplink Plugin"
ionic-plugin-deploy 0.6.7 "IonicDeploy"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-push 2.0.0 "PushPlugin"
uk.co.workingedge.phonegap.plugin.launchnavigator 4.0.2 "Launch Navigator"
{}

Been banging my head against the wall on this for 2 days now. Any solution would be super appreciated. Can't believe how hard it's been to get push notifications to work...

Scratch that. @christocracy's solution DID work. I just need to remove the android platform then re-add it after running his solution. Thanks @christocracy you've been a huge help in other areas of Ionic development too.

@vijay you mean Cordova development. Glad it worked.

@christocracy any solution for phonegap build ?
Thanks

I'm not that familiar with PGB. Does it not allow hook-scripts?

@christocracy PGB still does not support hook-scripts.

I guess that might be a security risk running arbitrary user-scripts. This plugin relies on a hook-script so it won't work for pgb

I am not familiar with hooks and I'm not sure hooks can be implemented.
But for the regular firebase, I had to fork the plugin, add it onto my account and change the files

Do you know any other plugin which could do the trick with phonegap build, in order to be able to do push notifications ?

thanks

I'm not actually here on this thread as a push user -- I'm here as a plugin author attempting to assist my users solve build-issues using my plugins alongside this push plugin.

Sorry, can't help you specifically with push issues.

I understand, your solution would have been perfect for me : (

I have this issue as well after upgrading all Android SDK API's. This is a relatively huge blocker, and although it can be hotfixed by workarounds, I think that this should have a very high priority.

Will also confirm that @asaxena48's solution worked for me. Changed
cordova.system.library.2=com.google.android.gms:play-services-analytics:+
to
cordova.system.library.2=com.google.android.gms:play-services-analytics:11.0.1

in the /platforms/android/project.properties-file.

Since we use this solution at work I wrote a more "formal" description of the issue and solution at our internal wiki, but I've created a GIST with the same content available here

Here I am after "trashing" a lot of hours...

Same situation of @ErlendEllingsen and @asaxena48

I was using cordova-plugin-googleplus
Here are my changes in order to build again:

file: plugins/cordova-plugin-googleplus/config.xml (replace + with latest number)
<framework src="com.google.android.gms:play-services-auth:11.4.0" /> <framework src="com.google.android.gms:play-services-identity:11.4.0" />

Then, file: platforms/android/project.properties (note the versions number)
cordova.system.library.2=com.google.android.gms:play-services-auth:11.4.0 cordova.system.library.3=com.google.android.gms:play-services-identity:11.4.0 cordova.system.library.4=com.android.support:support-v13:25.1.0 cordova.system.library.5=me.leolin:ShortcutBadger:1.1.17@aar cordova.system.library.6=com.google.firebase:firebase-messaging:11.4.0

Last: file platforms/android/build.gradle (added maven section)
allprojects { repositories { mavenCentral(); jcenter(); maven { url 'https://maven.google.com' } } }

(using Ionic 3.6.1)
Hope to help ya!

Ugh. I'm stuck on this again. Not sure what changed since last time but when I try @christocracy solution then remove and add the android platform it fails to build with:

BUILD FAILED

Total time: 1.892 secs

Error: /Users/vijay/branches/DeliveryApp/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • Where:
    Script '/Users/vijay/branches/DeliveryApp/platforms/android/phonegap-plugin-push/ionicpeachdelivery-push.gradle' line: 38

  • What went wrong:
    A problem occurred evaluating root project 'android'.

Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
For input string: "+"

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Package.json:

{
"name": "PeachDelivery",
"version": "1.0.8",
"author": "Peach Inc software@peachd.com",
"description": "",
"devDependencies": {
"babel-preset-es2015": "^6.13.2",
"beepbeep": "^1.2.0",
"connect": "^3.4.1",
"connect-livereload": "^0.5.4",
"del": "^2.2.0",
"express": "^4.11.1",
"glob": "^4.3.5",
"gulp": "^3.9.1",
"gulp-angular-templatecache": "^2.0.0",
"gulp-autoprefixer": "^3.1.1",
"gulp-babel": "^6.1.2",
"gulp-cached": "^1.1.0",
"gulp-changed": "^1.3.0",
"gulp-concat": "^2.6.0",
"gulp-iconfont": "^5.0.1",
"gulp-iconfont-css": "2.0.0",
"gulp-if": "^2.0.0",
"gulp-inject": "^3.0.0",
"gulp-jshint": "^2.0.0",
"gulp-json-editor": "^2.2.1",
"gulp-livereload": "^3.8.1",
"gulp-load-plugins": "^1.1.0",
"gulp-ng-annotate": "^1.1.0",
"gulp-ng-config": "^1.3.1",
"gulp-order": "^1.1.1",
"gulp-plumber": "^1.1.0",
"gulp-remember": "^0.3.0",
"gulp-rename": "^1.2.2",
"gulp-rev": "^6.0.0",
"gulp-sass": "^2.3.2",
"gulp-shell": "^0.5.1",
"gulp-sourcemaps": "^1.6.0",
"gulp-strip-css-comments": "^1.2.0",
"gulp-strip-debug": "^1.1.0",
"gulp-uglify": "^2.0.0",
"http-proxy-middleware": "^0.17.1",
"jshint": "2.9.3",
"jshint-stylish": "^2.1.0",
"json-file": "^0.1.0",
"lodash": "^4.15.0",
"lodash._basecopy": "latest",
"merge-stream": "^1.0.0",
"node-notifier": "^4.6.0",
"node-sass": "^3.8.0",
"open": "0.0.5",
"proxy-middleware": "^0.15.0",
"ripple-emulator": "^0.9.32",
"run-sequence": "^1.1.5",
"shelljs": "^0.5.3",
"stream-series": "^0.1.1",
"streamqueue": "^1.1.1",
"wiredep": "^3.0.0",
"yargs": "^3.31.0"
},
"scripts": {
"gulp": "./node_modules/.bin/gulp"
},
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
{
"locator": "https://github.com/apache/cordova-plugin-inappbrowser.git",
"id": "cordova-plugin-inappbrowser"
},
"cordova-plugin-splashscreen",
"cordova-plugin-dialogs",
"cordova-plugin-background-fetch",
"ionic-plugin-deploy",
"cordova-plugin-device@~1.1.2",
"cordova-plugin-whitelist@~1.2.2",
"cordova-plugin-splashscreen@~3.2.2",
"cordova-plugin-console@~1.0.3",
"cordova-plugin-background-fetch@~4.0.0",
"ionic-plugin-deploy@~0.6.4",
"uk.co.workingedge.phonegap.plugin.launchnavigator",
"cordova-plugin-statusbar@^2.2.3",
"ionic-plugin-deeplinks@^1.0.15",
"uk.co.workingedge.phonegap.plugin.launchnavigator@^4.0.2",
"phonegap-plugin-push",
"cordova-google-api-version"
],
"cordovaPlatforms": [
"ios",
"android"
],
"dependencies": {
"@ionic/cloud": "^0.9.0",
"cordova-android": "^6.2.3",
"cordova-background-geolocation": "git+https://github.com/transistorsoft/cordova-background-geolocation.git#2.6.0",
"cordova-google-api-version": "0.0.1",
"cordova-plugin-actionsheet": "^2.3.3",
"cordova-plugin-background-fetch": "^4.0.4",
"cordova-plugin-console": "^1.0.7",
"cordova-plugin-device": "^1.1.6",
"cordova-plugin-dialogs": "^1.3.3",
"cordova-plugin-splashscreen": "^3.2.2",
"cordova-plugin-statusbar": "^2.2.3",
"cordova-plugin-whitelist": "^1.2.2",
"ionic-native": "^2.2.12",
"ionic-plugin-deeplinks": "^1.0.15",
"ionic-plugin-deploy": "^0.6.7",
"phonegap-plugin-push": "^2.0.0",
"pubnub": "^4.2.5",
"pubnub-angular": "^4.0.2",
"uk.co.workingedge.phonegap.plugin.launchnavigator": "^4.0.5"
},
"cordova": {
"plugins": {
"uk.co.workingedge.phonegap.plugin.launchnavigator": {},
"cordova-background-geolocation": {
"LICENSE": ""
},
"cordova-plugin-background-fetch": {},
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-deploy": {},
"cordova-plugin-dialogs": {},
"cordova-plugin-statusbar": {},
"phonegap-plugin-push": {
"SENDER_ID": "188390060266"
},
"cordova-google-api-version": {
"GOOGLE_API_VERSION": "11.2.0"
}
},
"platforms": [
"android"
]
}
}

Config.xml:

Peach Delivery App Delivery app for Peach Inc Peach Inc

platforms/android/project.properties:

This file is automatically generated by Android Tools.

Do not modify this file -- YOUR CHANGES WILL BE ERASED!

This file must be checked in Version Control Systems.

To customize properties used by the Ant build system edit

"ant.properties", and override values to adapt the script to your

project structure.

To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):

#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

Project target.

target=android-25
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-background-geolocation/ionicpeachdelivery-build.gradle
cordova.gradle.include.2=cordova-google-api-version/ionicpeachdelivery-cordova-google-api-version.gradle
cordova.system.library.1=com.android.support:support-v13:25.1.0
cordova.system.library.2=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.3=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.3=phonegap-plugin-push/ionicpeachdelivery-push.gradle
cordova.system.library.4=com.squareup.okhttp3:okhttp:3+

Please help! I honestly can't believe how difficult it has been to get such a core plugin to work. This is a pretty big disincentive to stay in the cordova ecosystem

I wish we had the support and workforce of a core plugin on the push plugin. It really should be a core plugin, but it's not one yet.

@vijayb Can you post the content of the following files on your project?

  • platforms/android/cordova-background-geolocation/ionicpeachdelivery-build.gradle
  • platforms/android/cordova-google-api-version/ionicpeachdelivery-cordova-google-api-version.gradle
  • platforms/android/phonegap-plugin-push/ionicpeachdelivery-push.gradle

Hi Fred, here's the info requested. Let me know if it helps. Right now I'm almost willing to pay someone if they can get this to build for me with a working push notification.

ionicpeachdelivery-build.gradle:

repositories{    
  jcenter()
  flatDir{
      dirs 'src/android/libs'
   }
}

dependencies {
    compile 'com.google.android.gms:play-services-location:+'
    compile 'com.android.volley:volley:1.0.0'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile(name:'tslocationmanager', ext:'aar')
    // logback-android
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'com.github.tony19:logback-android-core:1.1.1-6'
    compile('com.github.tony19:logback-android-classic:1.1.1-6') {
        exclude group: 'com.google.android', module: 'android'
    }
}

ionicpeachdelivery-cordova-google-api-version.gradle

repositories{    
  // Google APIs 11.2.* are now hosted at Maven
  maven {
    url 'https://maven.google.com'
  }
}

def PLUGIN_NAME = "cordova-google-api-version"

// Fetch GOOGLE_API_VERSION var from properties.gradle
apply from: PLUGIN_NAME + '/properties.gradle'

// List of play-services libs to search for.
def GOOGLE_APIS = [
    'com.google.android.gms',
    'com.google.firebase'
]

println("+-----------------------------------------------------------------");
println("| " + PLUGIN_NAME + ": " + GOOGLE_API_VERSION);
println("+-----------------------------------------------------------------");

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group in GOOGLE_APIS) { details.useVersion GOOGLE_API_VERSION }
    }
}

ionicpeachdelivery-push.gradle

import java.util.regex.Pattern

def doExtractStringFromManifest(name) {
    def manifestFile = file(android.sourceSets.main.manifest.srcFile)
    def pattern = Pattern.compile(name + "=\"(.*?)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    return matcher.group(1)
}

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
        }
    }

    defaultConfig {
        multiDexEnabled true
        applicationId = doExtractStringFromManifest("package")
    }
}

buildscript {
        repositories {
      jcenter()
                        mavenLocal()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:+'
      classpath 'com.google.gms:google-services:3.0.0'
  }
}

// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

Finally, finally got push notifications working:
Had to manually go into these files and modify occurrences of '+' with appropriate version numbers explicitly

ionicpeachdelivery-push.gradle
ionicpeachdelivery-build.gradle

So basically pinning did not work for me. Not sure what happened from last time I tried this, but basically now I need to do this manual edit each time. So frustrating

@vijayb The only section that would need change is the following, as far as I know:

compile 'com.google.android.gms:play-services-location:+'

Did you have to change anything else? Can you clarify exactly what change you made so others can see, until we have a release from cordova-android?

@fredgalvao I did change exactly the section you mention. There was one other occurrence of a '+' in one of the gradle files that I also changed. I'm pretty sure it was this:

'com.android.tools.build:gradle:2.3.3'
which previously was:
'com.android.tools.build:gradle:+'

in:

ionicpeachdelivery-push.gradle

I did both then tested and it worked. Not sure if they were both necessary but I was trying to be exhaustive because I had been banging my head against a wall on this for days and days

I figured you'd changed the gradle version too, hence the question. However, you should really revert that one back, as it has nothing to do with the issue at hand, and could mess with your build entirely in a future android gradle build release.

Interesting that @christocracy 's plugin didn't work anymore for you, as it does exactly that but in a hook. Unless somehow android/gradle switched the order at which things are loaded/versioned during prep phase...

Regardless, that solution (or changing the platforms/android/project.properties file) is the same I used before any workaround plugin came to town. I'm glad it worked for you.

That's a good point @fredgalvao . Thanks for your help on this.

Hey guys. Ok, so yes the workaround to pin the + in project.properties, appname-push.gradle and build.gradle worked, but naturally this now prevents you from reinstalling (or using cordova prepare) to install the platforms.

Any permanent solution for this aside from the actual cordova-android fix? Any idea when that is coming, btw? I know you guys have been working on it for quite some time..

cordova prepare does not override the content of project.properties unless cordova finds that some metadata has changed from outside of the shell, you should be safe to use it and not have the changes be lost. I do it on my own project, I can guarantee it can work.

The details on the issue from the cordova side can be checked here and in the related/associated links. I'd guess we'll be seeing a full suite of cordova releases in the next couple of weeks, but that's a word from someone who just reads the mailling lists, so it's speculation at best.

@fredgalvao Thanks! I've documented what the team needs to do for now, so it's not a huge blocker; waiting eagerly on the suite of releases :)

Update: Cordova-Android 6.3.0 vote has closed successfully so it should be released very soon. Then I'll be able to make the necessary updates to this plugin and send PR's to others.

@macdonst won't we need a common and lib release too? The issues originated from the discussion are on those two subprojects, and I actually don't even know of a cordova-android issue related to this.

@fredgalvao yes, it is common and lib which get distributed with cordova-android so I needed to wait for a release that bundled them.

The only thing that has worked for me :
1/ downgrade to phonegap-plugin-push@1.10.5
2/ remove this line from config.xml file :
<resource-file src="google-services.json" target="google-services.json" />

config
`
cordova@7.0.1
cordova-android@6.3.0
platform-tools@26.0.1
build-tools@26.0.2
sdk-tools@26.1.1

Android target: android-26
minSdkVersion: 16
`

build-extras.gradle

ext.postBuildExtras = {
    android {
        compileOptions {
            incremental true
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
        dexOptions {
            javaMaxHeapSize '5g'
        }
    }
}

plugins
cordova-plugin-appminimize 1.0 "AppMinimize"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-crosswalk-webview 2.3.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-globalization 1.0.7 "Globalization"
cordova-plugin-ionic-webview 1.1.8 "Ionic's WKWebView Engine"
cordova-plugin-ionic-webview-openblank 0.0.2 "OpenBlank"
cordova-plugin-nativestorage 2.2.2 "NativeStorage"
cordova-plugin-safariviewcontroller 1.4.7 "SafariViewController"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.4-dev "StatusBar"
cordova-plugin-vibration 2.1.5 "Vibration"
cordova-plugin-whitelist 1.3.2 "Whitelist"
ionic-plugin-deeplinks 1.0.14 "Ionic Deeplink Plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-barcodescanner 6.0.8 "BarcodeScanner"
phonegap-plugin-push 1.10.5 "PushPlugin"

I copy that, tried 2 days now for getting 2.X to running.
Updated Android-Studio, SDK-Updates, Cordova.
Removing and adding plattform didn't work aswell.

Only solution was to downgrade to 1.10.5 and evoila, working like a charm, coexisting with google analytics:

cordova-plugin-android-permissions 1.0.0 "Permissions"
cordova-plugin-appminimize 1.0 "AppMinimize"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-email-composer 0.8.9 "EmailComposer"
cordova-plugin-file 4.0.0 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-google-analytics 1.7.11 "Google Universal Analytics Plugin"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-push 1.10.5 "PushPlugin"

Even I have downgrade to 1.10.5. Now build happens successfully without any error. But as soon as I try to import components related to push notification ex :

import { Push, PushObject, PushOptions } from '@ionic-native/push';

I get error like Cannot find module ionic-native/push

My system info:

Cordova CLI: 7.0.1
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.1
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.7.4
Xcode version: Xcode 9.0 Build version 9A235

@coolvasanth did you install npm module aswell?
npm install --save @ionic-native/push

Hey @graphefruit thanks for your suggestion, now I could solve my issue Cannot find module ionic-native/push. But now I'm facing an another issue reported here:
#1998