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

cordova run android not working #1718

Closed
giladKaplan opened this issue May 11, 2017 · 165 comments
Closed

cordova run android not working #1718

giladKaplan opened this issue May 11, 2017 · 165 comments

Comments

@giladKaplan
Copy link

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

@macdonst
Copy link
Member

@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
Copy link
Collaborator

@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
Copy link
Author

giladKaplan commented May 14, 2017

@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
Copy link
Member

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

@VitorHFLopes
Copy link

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
Copy link

ianlintner-wf commented May 23, 2017

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
Copy link

ianlintner-wf commented May 23, 2017

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
Copy link

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

@ianlintner-wf
Copy link

ianlintner-wf commented May 23, 2017

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
Copy link

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
Copy link
Member

@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 macdonst added this to the Release 2.0.0 milestone May 25, 2017
@macdonst
Copy link
Member

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
Copy link

ianlintner-wf commented May 25, 2017

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
Copy link

morariu commented Jun 6, 2017

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

@amritk
Copy link

amritk commented Jun 7, 2017

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
Copy link

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
Copy link

morariu commented Jun 12, 2017

@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
Copy link

morariu commented Jun 12, 2017

@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
Copy link

I tried, but returns the same error =/

@jabit
Copy link

jabit commented Jun 13, 2017

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
Copy link

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"

@fredgalvao
Copy link
Collaborator

@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
Copy link

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?

@christocracy
Copy link

When you modify all those :+ there to 11.0.1, it will work.

Your task is to discover those other plugins you’re using which are importing the version “:+”

@nicholasjativa
Copy link

Awesome, thank you for clearing that up, and sorry about that.

@codinronan
Copy link

codinronan commented Dec 4, 2017

Yep I have a manual install step that when I remove and re-add the android platform I need to edit the platforms/android/build.gradle and platforms/android/project.settings files to update all the GMS service + specs to 11.0.1 (or 11.4.+ in my case, that also works)

@christocracy
Copy link

Manually editing project.properties is a hack. You need to fix the problem properly by finding the offending plugin responsible for importing the incorrect version of play services and align it to the same version required by plugin-push.

All plugins requiring play-services must align to the same version.

@acyio
Copy link

acyio commented Dec 4, 2017

Dependency hell in a nutshell, fellow developers. 😠

@christocracy
Copy link

This “dependency” hell is the fault of Cordova, which doesn’t provide you access to a build.grade to have the final say on dependencies. They try to abstract all that away, leaving you powerless.

These dependency clashes are far more easily solved in react-native.

@codinronan
Copy link

@christocracy in this case, the offending plugin is phonegap-plugin-push :) All my other GMS-consuming plugins use + as the version.

I haven't yet gotten around to trying with the flag. It should work if I just set FCM_VERSION=+ right?

@christocracy
Copy link

I wouldn't use version + with any plugin, it's a bad idea. Set a specific version (eg: 11.6.0) and align all plugin to use 11.6.0.

@codinronan
Copy link

codinronan commented Dec 4, 2017

@christocracy Right now that isn't an option for me. I have 5 different plugins that utilize GSM and all of them are set to + except for Push and none of them support FCM_VERSION or any similar mechanism.

This means phonegap-plugin-push is the odd man out. I'm simply asking if that will work, not whether it's the right thing to do. I am well aware it isn't but right now I have literally no other option unless I want to continue editing the build files by hand.

@christocracy
Copy link

christocracy commented Dec 4, 2017

@codinronan phonegap-plugin-push is absolutely, 100% not the odd man out. Those other plugins need to get with the times and expose the same mechanism for configuring play-services version as this plugin's FCM_VERSION.

You need to go talk to your other dependencies. The problem is not here. phonegap-plugin-push is doing the right thing.

@christocracy
Copy link

@codinronan Did you read my explanation here?

@codinronan
Copy link

codinronan commented Dec 4, 2017

@christocracy I didn't mean to suggest that this plugin is doing the wrong thing. It's the only one doing it right! I just meant it's the only one doing it differently.

I still need an answer to my question for an interim solution. Trying to get the other plugin authors to fix their plugins RIGHT NOW!!!!111111qqqq isn't going to work.

@christocracy
Copy link

@codinronan I have no solution for you. I'm not associated with phonegap-plugin-push. I don't even use this plugin. I'm a plugin author myself. This plugin just happens to be famous for conflicting with my plugins in the same manner you're experiencing with your other plugins.

@codinronan
Copy link

@christocracy ❤️ We're in the pits together! :) No worries. I'll give it a shot and see what happens..

@christocracy
Copy link

@codinronan I'm no longer in the pits. I've implemented the same FCM_VERSION mechanism in my plugins so users can align my plugins properly with phonegap-plugin-push. Everything is golden now :)

@chadmilden
Copy link

chadmilden commented Jan 17, 2018

This is still an issue, I can get it working by manually setting versions in the .gradle file, however phonegapbuild is not working.

It looks like they have added a feature to the next release (7.2.0). https://issues.apache.org/jira/browse/CB-13145

Adding something like: <preference name="PlayServicesVersion" value="11.0.1" /> in the config.xml should fix the issue once 7.2.0 is released.

@codinronan
Copy link

codinronan commented Jan 17, 2018

@chadmilden I have a cordova prepare hook to fix this for now. This is not something that can be fixed at a single plugin level, it needs Cordova support.

In the meantime, the script I use is documented here:

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

And inside config.xml:

    <platform name="android">
        <hook src="scripts/gms-gradle-fix.js" type="before_prepare" />
        ... etc ...
    </platform>

@chadmilden
Copy link

chadmilden commented Jan 17, 2018

this looks like it's what I need, but I can't get the phonegapbuild site to execute the hook.

it's uploading correctly, I tried a hook type of: before_prepare, after_prepare, inside <platform name="android">, and in the global config scope, but still nothings seems to be working, same error.

image

image

I tested it out locally and it does work

@chadmilden
Copy link

Just found this:
https://forums.adobe.com/thread/2274965

Looks like PGB does not support custom hooks. So guess I'm waiting until 7.2.0. Thanks for the help.

@gasotelo
Copy link

This problem is caused by a bug on GoogleServicesPlugin class.

Gradle allows to use dynamic version dependencies like "+" or "9.+", meaning that it will use the latest version available matching the given expression.

Looking at GoogleServicesPlugin class, there is some point where it reads all firebase dependencies versions and sorts them in order to do an internal check. To sort, it uses a SortedSet using this comparator:

adsads

This method doesn't support + wildcards, it throws a java.lang.NumberFormatException: For input String '+' on this line:
int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));

This problem is easy to solve: + character must be the highest 'number' in the version comparison. Maybe using something like this

int diff = vals1[i].equals(“+”)&&vals2[i].equals(“+”)? 0 : vals1[i].equals(“+”) ? 1 : vals2[i].equals(“+”) ? -1 : Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));

Regards

@hvallenilla
Copy link

Hi, I have this in my project.properties

target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-fabric-plugin/evaluados21-build-extras.gradle
cordova.system.library.1=com.android.support:support-v4:+ evaluados21
cordova.gradle.include.2=cordova-plugin-firebase/evaluados21-build.gradle
cordova.system.library.2=com.google.gms:google-services:11.0.1
cordova.system.library.3=com.google.firebase:firebase-core:11.0.1
cordova.system.library.4=com.google.firebase:firebase-messaging:11.0.1
cordova.system.library.5=com.google.firebase:firebase-crash:11.0.1
cordova.system.library.6=com.google.firebase:firebase-config:11.0.1
#cordova.system.library.7=com.google.android.gms:play-services-maps:+
#cordova.system.library.8=com.google.android.gms:play-services-location:+
cordova.system.library.7=com.android.support:support-v13:26.+
cordova.system.library.8=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.9=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.3=phonegap-plugin-push/evaluados21-push.gradle

And have this error

  • Where:
    Build file '/var/www/ionic/evaluados21/platforms/android/build.gradle' line: 97

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

Could not read script '/var/www/ionic/evaluados21/platforms/android/cordova-plugin-firebase/evaluados21-build.gradle' as it does not exist.

Someone have this error?

@degroundshaker
Copy link

@ianlintner-wf Is there any way to Hug you?
Your answer finally saved me after wasting my complete day on this silly bug:

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"

It worked for me!

@christocracy
Copy link

@degroundshaker You don't want to use play-services version 9.8.0 just because it works.

You want to be using the latest available version, which is 15.0.0.

9.8.0 dates back to October 2016

You are exposing yourself to a world of issues when your app runs on different devices running other versions of Android OS than you're testing upon.

@lock
Copy link

lock bot commented Jun 8, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests