当我尝试安装pushwoosh并编译到android:Cordova

时间:2016-06-03 03:53:00

标签: android pushwoosh

当我安装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

按要求构建Gradle依赖项

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

当我卸载pushwoosh插件时,该应用程序运行正常

4 个答案:

答案 0 :(得分:1)

如果您在项目中使用自定义Application类,则应从android.support.multidex.MultiDexApplication继承它以使多索引用。

答案 1 :(得分:0)

您可能会或可能不会达到dex方法计数限制。查看此主题列出了几个解决此问题的选项:Java finished with non-zero exit value 2 - Android Gradle

答案 2 :(得分:0)

Multidex

如果您在编译应用时出现问题,并且您收到与此类似的错误(com.android.dex.DexException:多个dex文件定义):

意外的顶级例外情况: com.android.dex.DexException:多个dex文件定义Landroid / support / annotation / AnimRes;     在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)     在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)     在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)     在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)     在com.android.dx.merge.DexMerger.merge(DexMerger.java:189)     在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)     在com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)     在com.android.dx.command.dexer.Main.run(Main.java:277)     在com.android.dx.command.dexer.Main.main(Main.java:245)     在com.android.dx.command.Main.main(Main.java:106) 然后,您安装的至少一个其他插件使用过时的方式来声明依赖项,例如android-support或play-services-gcm。这会导致gradle失败,并且您需要确定哪个插件正在导致它并请求对插件作者进行更新,以便它使用正确的方式来声明cordova的依赖关系。有关cordova插件规范的参考信息,请参阅此文章,在创建问题或请求更新插件时,请务必提及它。

受此过时依赖管理影响的常见插件是与facebook,google +,通知,人行横道和谷歌地图相关的插件。

答案 3 :(得分:0)

此错误表示在链接(dexer)阶段您有两个具有相同名称的类。

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

看起来其他插件直接引用了google play服务库。

在Cordova上引用它的正确方法是通过gradle(正如Pushwoosh插件所做的那样):
https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/blob/master/plugin.xml#L102

找到引用google-play-services.jar或类似内容的其他插件,然后从中删除(只删除)此库。

类似的问题:
https://github.com/Pushwoosh/pushwoosh-phonegap-plugin/issues/179#issuecomment-222638452