Kingsley Mitchell
Kingsley Mitchell

Reputation: 2589

Keep getting error when I try install pushwoosh and compile to android: Cordova

This is what happens when I install push woosh

:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/iid/MessengerCompat$1;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

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

BUILD FAILED

Total time: 1 mins 1.862 secs
Error: Error code 1 for command: /Users/apple/usd/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/apple/usd/platforms/android/build.gradle,-PcdvBuildArch=arm,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true

Build Gradle dependencies as requested

 dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }

When I uninstall pushwoosh plugin the app works perfectly

Upvotes: 0

Views: 332

Answers (4)

shader
shader

Reputation: 2121

This error means you have two classes with the same names during the linking (dexer) phase.

Multiple dex files define Lcom/google/android/gms/iid/MessengerCompat$1;

It looks like other plugin is referencing google play services library directly.

The correct way of referencing it on Cordova is through gradle (as Pushwoosh plugin is doing):
https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/blob/master/plugin.xml#L102

Find the other plugin who is referencing google-play-services.jar or similar and remove (just delete) this library from there.

Similar issue:
https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/179#issuecomment-222638452

Upvotes: 0

Kingsley Mitchell
Kingsley Mitchell

Reputation: 2589

Multidex

If you have an issue compiling the app and you're getting an error similar to this (com.android.dex.DexException: Multiple dex files define):

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334) at com.android.dx.command.dexer.Main.run(Main.java:277) at com.android.dx.command.dexer.Main.main(Main.java:245) at com.android.dx.command.Main.main(Main.java:106) Then at least one other plugin you have installed is using an outdated way to declare dependencies such as android-support or play-services-gcm. This causes gradle to fail, and you'll need to identify which plugin is causing it and request an update to the plugin author, so that it uses the proper way to declare dependencies for cordova. See this for the reference on the cordova plugin specification, it'll be usefull to mention it when creating an issue or requesting that plugin to be updated.

Common plugins to suffer from this outdated dependency management are plugins related to facebook, google+, notifications, crosswalk and google maps.

Upvotes: 0

liminal
liminal

Reputation: 1164

You may or may not hit the dex method count limit. Check out this thread that lists a couple of options to troubleshoot this: Java finished with non-zero exit value 2 - Android Gradle

Upvotes: 0

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20930

If you use custom Application class in your project you should inherit it from android.support.multidex.MultiDexApplication to make multidex work.

Upvotes: 1

Related Questions