简体   繁体   English

意外的顶级异常:com.android.dex.DexException:多个dex文件定义

[英]UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define

I have a trouble trying use a Google Play Services on my Android App using Android Studio. 我在使用Android Studio在Android应用上尝试使用Google Play服务时遇到了麻烦。

I've tried everything and still doesn't work. 我已经尝试了一切,仍然无法正常工作。

This is the error. 这是错误。

Execution failed for task ':app:dexDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Users/jghg/Desktop/My App/Android/SDK/android-sdk-mac_86/build-tools/19.0.1/dx --dex --output /Users/jghg/Desktop/My App/Eureka/UDA/app/build/libs/app-debug.dex /Users/jghg/Desktop/My App/Eureka/UDA/app/build/classes/debug /Users/jghg/Desktop/My App/Eureka/UDA/app/build/dependency-cache/debug /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/classes-08979151dd1373bd3f799299d93376d22d4afa46.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/classes-167b9d3c5d689abe004c3fa5b0bcb945d3f0fc8e.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/google-play-services-ec20f8af7bb457c5095cae1afa0cee722582f198.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/support-v4-13.0.0-473d85b8d55c88bfed3404072e6c132f96543429.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/support-v4-19.0.1-861cc05365a0e9262c764da37d61e3f93dc16de6.jar /Users/jgh com.android.ide.common.internal.LoggedErrorException:无法运行命令:/ Users / jghg / Desktop / My App / Android / SDK / android-sdk-mac_86 / build-tools / 19.0.1 / dx --dex - -output / Users / jghg / Desktop / My App / Eureka / UDA / app / build / libs / app-debug.dex / Users / jghg / Desktop / My App / Eureka / UDA / app / build / classes / debug / Users / jghg / Desktop / My App / Eureka / UDA / app / build / dependency-cache / debug / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / classes-08979151dd1373bd3f799299d93376d22d4afa46.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / classes-167b9d3c5d689abe004c3fa5b0bcb945d3f0fc8e.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed /debug/google-play-services-ec20f8af7bb457c5095cae1afa0cee722582f198.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / support-v4-13.0.0-473d85b8d55c88bfed3404072e6c132f96543429.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / support-v4-19.0.1-861cc05365a0e9262c764da37d61e3f93dc16de6.jar / Users / jgh g/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/support-v4-19.0.1-dcc11377c764caea791f711123b8b678f876c3b6.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-async-3.0.5-0904cb320186fb23a9a9bf25a048c5bc4ec07bc2.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-core-3.0.5-41d2d5805e2d90cf77813a126306c4cbe22583ae.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-examples-3.0.5-adc1ee9b037c8061429560e6a5fe89ce8e502db6.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-media-support-3.0.5-37d138cdc631738d13ddb6f4d34c560a9cd8e048.jar /Users/jghg/Desktop/My App/Eureka/UDA/app/build/pre-dexed/debug/twitter4j-stream-3.0.5-c96c138ea216b25631a1a8b47520ecaf33f288d8.jar Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode; g / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / support-v4-19.0.1-dcc11377c764caea791f711123b8b678f876c3b6.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / twitter4j-async-3.0.5-0904cb320186fb23a9a9bf25a048c5bc4ec07bc2.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / twitter4j-core-3.0.5-41d2d5805e2d90cf77813a126306c4cbe22583ae .jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / twitter4j-examples-3.0.5-adc1ee9b037c8061429560e6a5fe89ce8e502db6.jar / Users / jghg / Desktop / My App / Eureka / UDA /app/build/pre-dexed/debug/twitter4j-media-support-3.0.5-37d138cdc631738d13ddb6f4d34c560a9cd8e048.jar / Users / jghg / Desktop / My App / Eureka / UDA / app / build / pre-dexed / debug / twitter4j- stream-3.0.5-c96c138ea216b25631a1a8b47520ecaf33f288d8.jar错误代码:2输出:UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException:多个dex文件定义Lcom / google / ads / AdRequest $ ErrorCode; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) 在com.android.dx.merge.DexMerger.mergeClassDefs的com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)的com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) (dexMerger.java:533)位于com.android的com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)com.android.dx.merge.DexMerger.merge(DexMerger.java:188)。 dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)位于com.android.dx.com上的com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)。在com.android.dx.command.Main.main(Main.java:103)的com.android.dx.command.dexer.Main.main(Main.java:199)运行(Main.java:230)

Thanks. 谢谢。 Best Regards. 最好的祝福。

The error occurs when you have the same library/directory included more than once in your build.gradle's dependencies. 如果在build.gradle的依赖项中包含多个相同的库/目录,则会发生此错误。 Ok, let's say you have an App structure that looks like this: 好的,假设你有一个看起来像这样的App结构:

在此输入图像描述

So you have the main “app” and then you have a bunch of sub-apps/modules/libraries. 所以你有主“应用程序”,然后你有一堆子应用程序/模块/库。 The libraries are: 1) gene_test_library , 2) genes_nine_old_androids_library , & 3) swipe_list_view_library . 这些库是:1) gene_test_library ,2) genes_nine_old_androids_library ,&3) swipe_list_view_library

My name is Gene, so that's why there are all these “gene” libraries. 我叫Gene,这就是为什么有这些“基因”库的原因。

Inside the build.gradle for “app” , I have: “app”build.gradle中,我有:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.0'

    compile project(':libraries:gene_test_library')
    //compile project(':libraries:genes_nine_old_androids_library')
    compile project(':libraries:swipe_list_view_library')
}

Inside the build.gradle for gene_test_library , I have nothing: build.gradlegene_test_library ,我什么都没有:

dependencies {
}

Inside build.gradle for gene_nine_old_androids_library , I have: build.gradlegene_nine_old_androids_library里面,我有:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.0'
}

Inside build.gradle for swipe_list_view_library , I have: build.gradleswipe_list_view_library里面,我有:

dependencies {
    compile 'com.nineoldandroids:library:2.4.0+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.0'
}

This line of code compile fileTree(dir: 'libs', include: ['*.jar']) just means “hey, look inside the 'libs' folder inside this module for any jar files. 这行代码compile fileTree(dir: 'libs', include: ['*.jar'])只是意味着“嘿,看看这个模块里面的'libs'文件夹中的任何jar文件。 I do not have anything in the libs folder of any of the modules so you can ignore that line of code. 我在任何模块的libs文件夹中都没有任何内容,因此您可以忽略该行代码。

So let's say I uncomment out //compile project(':libraries:genes_nine_old_androids_library') In the build.gradle for the “app” module. 所以,让我说取消注释//compile project(':libraries:genes_nine_old_androids_library')“app”模块的build.gradle中。 Then I would get the “UNEXPECTED TOP-LEVEL EXCEPTION:” error. 然后我会得到“UNEXPECTED TOP-LEVEL EXCEPTION:”错误。 Why is that? 这是为什么?

在此输入图像描述

Well, writing //compile project(':libraries:genes_nine_old_androids_library') inside the build.gradle for “app” , is the same as taking the build dependencies of “genes_nine_old_androids_library” module and putting it there. 好吧,在build.gradle“app”编写//compile project(':libraries:genes_nine_old_androids_library')与获取“genes_nine_old_androids_library”模块的构建依赖关系并将其放在那里相同。 So uncommenting the //compile project(':libraries:genes_nine_old_androids_library') statement, the build.gradle for “app” module becomes: 因此,取消注释//compile project(':libraries:genes_nine_old_androids_library')语句,“app”模块的build.gradle变为:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.0'

    compile project(':libraries:gene_test_library')
    ***compile fileTree(dir: 'libs', include: ['*.jar'])***
    ***compile 'com.android.support:appcompat-v7:21.0.0'***
    compile project(':libraries:swipe_list_view_library')
}

Notice how now compile 'com.android.support:appcompat-v7:21.0.0' shows up 2x. 注意现在如何compile 'com.android.support:appcompat-v7:21.0.0'显示2x。 That's where the error is coming from. 这就是错误的来源。

Your google play services library is being exported from other dependencies of your project and at the compile time the dex compiler gets confused. 您的Google Play服务库正在从项目的其他依赖项中导出,并且在编译时dex编译器会混淆。

If you're using Gradle then including this in your project's build.gradle should exclude the support library from being exported into your main project. 如果您正在使用Gradle,那么在项目的build.gradle中包含它应该排除将支持库导出到您的主项目中。

apply plugin: 'android'
apply plugin: 'crashlytics'

/** Must exclude exported support jars from dependencies, or get dex duplicate class      error.
*  we're
**/
configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
    all*.exclude group: 'com.google.android.gms', module: 'play-services'
}

If you're using the andoid studio build system. 如果您正在使用andoid studio构建系统。 Then you should go to File -> project structure and disable -> modules. 然后你应该去File - > project structure并禁用 - > modules。 Go through each module the and click on the dependency tab, uncheck the export column for for the support library and google play services library. 浏览每个模块并单击依赖选项卡,取消选中支持库和Google Play服务库的导出列。

Post comments if you need more help. 如果您需要更多帮助,请发表评论。

It could also happen if you have differing versions of the same library imported in your build.gradle vs one in one of your libraries. 如果您在build.gradle中导入了相同库的不同版本,而在其中一个库中导入了不同版本,则也可能发生这种情况。 For example, Google Play Store services requires you have them all refer to the same version I had: 例如,Google Play商店服务要求您让它们都引用我的相同版本:

app build.gradle app build.gradle

compile 'com.google.android.gms:play-services-base:7.5.0'

whereas: 然而:

module/library build.gradle module / library build.gradle

compile 'com.google.android.gms:play-services-cast:7.8.+'

Upgrading my app's version to 7.8.0 solved the problem 将我的应用程序版本升级到7.8.0解决了这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 意外的顶级异常:com.android.dex.DexException:多个dex文件定义 - UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define 意外的顶级异常:com.android.dex.DexException - UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException 将字节码转换为dex:原因:com.android.dex.DexException:定义了多个dex文件 - converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define com.android.dex.DexException:多个dex文件定义了Lcom / google / android / gms / location / places / PlaceReport; - com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/location/places/PlaceReport; 错误:com.android.dex.DexException:多个dex文件定义了Ledu / umd / cs / findbugs / annotations / NonNull; - Error:com.android.dex.DexException: Multiple dex files define Ledu/umd/cs/findbugs/annotations/NonNull; com.android.dex.DexException:多个dex文件定义了Lcom / facebook / internal / Utility $ GraphMeRequestWithCacheCallback; - com.android.dex.DexException: Multiple dex files define Lcom/facebook/internal/Utility$GraphMeRequestWithCacheCallback; com.android.dex.DexException:多个dex文件定义Lorg / hamcrest / Description; - com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description; 将字节码转换为dex时出错:原因:com.android.dex.DexException:多个dex文件定义了Lcom / RNFetchBlob / RNFetchBlobConst; - Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/RNFetchBlob/RNFetchBlobConst; 未知源文件:com.android.dex.DexException:多个dex文件定义了Lcom / google / android / gms / internal / zzpq; - Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzpq; 错误:将字节码转换为dex时出错:原因:com.android.dex.DexException:多个dex文件定义了Lcom / google / android / gms / common / api / zza; - Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM