phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

cordova run android not working #1718

Closed giladKaplan closed 7 years ago

giladKaplan commented 7 years ago

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.

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

macdonst commented 7 years ago

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

fredgalvao commented 7 years ago

@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?

giladKaplan commented 7 years ago

@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": {}

macdonst commented 7 years ago

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

VitorHFLopes commented 7 years ago

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

ianlintner-wf commented 7 years ago

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

ianlintner-wf commented 7 years ago

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"
ianlintner-wf commented 7 years ago

Example of plugin that uses libraries GooglePlus: https://github.com/EddyVerbruggen/cordova-plugin-googleplus/blob/master/plugin.xml

ianlintner-wf commented 7 years ago

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 😹

ianlintner-wf commented 7 years ago

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.

macdonst commented 7 years ago

@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.

macdonst commented 7 years ago

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.

ianlintner-wf commented 7 years ago

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.

morariu commented 7 years ago

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

amritk commented 7 years ago

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

andrecbr commented 7 years ago

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
morariu commented 7 years ago

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

morariu commented 7 years ago

@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
andrecbr commented 7 years ago

I tried, but returns the same error =/

jabit commented 7 years ago

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

rolinger commented 7 years ago

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:

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"

fredgalvao commented 7 years ago

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

rolinger commented 7 years ago

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?

fredgalvao commented 7 years ago

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

rolinger commented 7 years ago

@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?

fredgalvao commented 7 years ago

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.

rolinger commented 7 years ago

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.

rolinger commented 7 years ago

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

rolinger commented 7 years ago

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.

AdriVanHoudt commented 7 years ago

Getting the same issue due to these lines https://github.com/EddyVerbruggen/cordova-plugin-googleplus/blob/master/plugin.xml#L32-L33 Anyone have a fix?

rolinger commented 7 years ago

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.

AdriVanHoudt commented 7 years ago

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

fredgalvao commented 7 years ago

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

asaxena48 commented 7 years ago

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.

Alberick commented 7 years ago

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

ninooppgeorge commented 7 years ago

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

faustoct1 commented 7 years ago

@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.

fredgalvao commented 7 years ago

@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).

faustoct1 commented 7 years ago

@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.

karansharma27 commented 7 years ago

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

faustoct1 commented 7 years ago

@karansharma27 I'm going to move temporarily to cordova-plugin-firebase til get phonegap-plugin-push working . It does support everything except upstream messaging . https://github.com/arnesson/cordova-plugin-firebase/issues/380#issuecomment-321752281

karansharma27 commented 7 years ago

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

peterpeterparker commented 7 years ago

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

https://github.com/jeduan/cordova-plugin-facebook4/issues/507

peterpeterparker commented 7 years ago

ok so in my case was a classic conflict error, like discussed https://github.com/jeduan/cordova-plugin-facebook4/issues/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 https://github.com/danwilson/google-analytics-plugin/issues/464

karansharma27 commented 7 years ago

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

peterpeterparker commented 7 years ago

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

if so, that might be the source of your conflict

fredgalvao commented 7 years ago

@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 ;).

peterpeterparker commented 7 years ago

@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

macdonst commented 7 years ago

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.

shyamal890 commented 7 years ago

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