使用以下依赖项
'com.google.firebase:firebase-messaging:10.2.4'
'com.android.support:multidex:1.0.1'
顶级构建文件
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
classpath 'com.google.gms:google-services:3.1.0'
Gradle 4.0版
Android Studio 3.0 Canary4
在运行应用时出现以下错误
Information:Gradle tasks [:app:assembleDebug]
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzg;
Error:com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzg;
Error: at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:608)
Error: at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:563)
Error: at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:545)
Error: at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:194)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.mergeDexes(DexArchiveMergerCallable.java:66)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:54)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:37)
Error: at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzg;
Information:BUILD FAILED in 16s
Information:16 errors
Information:0 warnings
Information:See complete output in console
请帮忙。
答案 0 :(得分:2)
当两个依赖项使用具有不同版本号的相同依赖项时,会发生此错误。在这种情况下,您的某个依赖项会使用具有不同版本的Firebase。
您可以通过运行gradle app:dependencies
来检查您的依赖关系树(或者如果您有一个包装,这通常适用于Android Studio项目,gradlew app:dependencies
)其中app
是模块&#39 ;你要检查的名字。