DexException:多个dex文件 [英] DexException: Multiple dex files

查看:217
本文介绍了DexException:多个dex文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,目前我正在制作一款Android应用,该应用利用 Google Sheets API 3.0版 适用于Java的Drive API Client Library ,我需要该应用从用户驱动器帐户中读取扩展名并对其进行编辑。继文档之后,我在我的/ lib文件夹(Android Studio 1.1)中包含了以下jar文件。 dependencies {
compile fileTree(include:['* .jar'],dir: 'libs')
compile'c​​om.android.support:appcompat-v7:21.0.3'
compile'c​​om.google.android.gms:play-services:6.5.87'
编译文件('libs / google-api-client-1.19.1.jar')
编译文件('libs / google-api-client-android-1.19.1.jar')
编译文件('libs / google-api-services-drive-v2-rev158-1.19.1.jar')
编译文件('libs / google-http-client-1.19.0.jar')
编译文件('libs / google-http-client-android-1.19.0.jar')
编译文件('libs / google-http-client-gson-1.19.0.jar')
编译文件('libs / google-oauth-client-1.19.0.jar')
编译文件('libs / gson-2.1.jar')
编译文件('libs / jackson-core- 2.1.3.jar')
编译文件('libs / jackson-core-asl-1.9.11.jar')
编译文件('libs / jsr305-1.3.9.jar')
编译文件('libs / protobuf-java-2.4.1.jar')
编译文件('libs / mail.jar')
编译文件('libs / jsr305.jar')
编译文件('libs / guava-11.0.2.jar')
编译文件('libs / gdata-spreadsheet-meta-
编译文件('libs / gdata-spreadsheet-3.0.jar')
编译文件('libs / gdata-docs-meta-3.0.jar')
编译文件('libs / gdata-docs-3.0.jar')
编译文件('libs / gdata-core-1.0.jar')
编译文件('libs / gdata-client-meta-1.0 .jar')
编译文件('libs / gdata-client-1.0.jar')
编译文件('libs / additionnal.jar')
编译文件('libs / activation。 jar')
}


当我输入我的代码时,一切正常,所有的输入都是适当的,但是当我运行我的应用程序时,我得到了这个结果。

Okay so currently i am making an Android app that utilizes the Google Sheets API version 3.0 and Drive API Client Library for Java, i need the app to read a spreadhsheet from a users drive account and edit it. Following the documentation i have included the following jars in my /lib folder(Android Studio 1.1).
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.google.android.gms:play-services:6.5.87' compile files('libs/google-api-client-1.19.1.jar') compile files('libs/google-api-client-android-1.19.1.jar') compile files('libs/google-api-services-drive-v2-rev158-1.19.1.jar') compile files('libs/google-http-client-1.19.0.jar') compile files('libs/google-http-client-android-1.19.0.jar') compile files('libs/google-http-client-gson-1.19.0.jar') compile files('libs/google-oauth-client-1.19.0.jar') compile files('libs/gson-2.1.jar') compile files('libs/jackson-core-2.1.3.jar') compile files('libs/jackson-core-asl-1.9.11.jar') compile files('libs/jsr305-1.3.9.jar') compile files('libs/protobuf-java-2.4.1.jar') compile files('libs/mail.jar') compile files('libs/jsr305.jar') compile files('libs/guava-11.0.2.jar') compile files('libs/gdata-spreadsheet-meta-3.0.jar') compile files('libs/gdata-spreadsheet-3.0.jar') compile files('libs/gdata-docs-meta-3.0.jar') compile files('libs/gdata-docs-3.0.jar') compile files('libs/gdata-core-1.0.jar') compile files('libs/gdata-client-meta-1.0.jar') compile files('libs/gdata-client-1.0.jar') compile files('libs/additionnal.jar') compile files('libs/activation.jar') }

When im typing my code everything works just fine, everything is imported appropiately but when i run my app i get this result.

`What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\Ricardo\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --output C:\Users\Ricardo\Google Drive\Development\Android\Updated\Private\Google_Fiasco\MyApplication\app\build\intermediates\dex\debug --input-list=C:\Users\Ricardo\Google Drive\Development\Android\Updated\Private\Google_Fiasco\MyApplication\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
        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:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
e`<br>

现在有几件事要注意,当我制作两个独立的项目时,一个实现Spreadsheet API和其他Drive API不会发生错误。只有当我在同一个项目中实现两个API时,即将两个库中的罐组合在一起时,才会出现此错误。在对罐子进行修补后,我发现只有当 jsr305.jar &包括 jsr305-1.3.9.jar 。看看这两个jar文件,我发现它们都有 CheckForNull.java 文件,错误消息多个dex文件中引用的文件定义了Ljavax / annotation / CheckForNull

所以我的问题: 我该如何解决这个错误? 我想我必须在依赖中排除它?精确的说明,将不胜感激,也许解释什么解决方案。还有最后一件事它简单地将jar文件放入我的/ lib文件夹并将它添加到build.gradle中的依赖关系之间有什么不同?它似乎不影响任何内容。
删除jsr.jat文件的结果如下:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]:65536
at com.android.dx.merge.DexMerger $ 6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger $ IdMerger.mergeSorted( DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java: 168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)

Now a couple things to note, when i make two separate projects ,one implementing the Spreadsheet API and the other the Drive API no errors occur. The error only occurs when i implement both API's in the same project i.e combining the jars from both libraries. After tinkering with the jars i found that the error only happens when both jsr305.jar & jsr305-1.3.9.jar are included. Looking at these two jars i see that both have CheckForNull.java files, the file referenced in the error message Multiple dex files define Ljavax/annotation/CheckForNull.
So my question: How do i resolve this error? I think i have to exclude it in my dependencies? Precise instructions would be appreciated, and perhaps an explanation on what the solution does. Also one last thing What difference does it make between simply putting jar files in my /lib folder and adding it to my dependencies in build.gradle? It doesn't seem to affect anything. The result of deleting either of the jsr.jat files is the following:
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277) at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at com.android.dx.command.dexer.Main.run(Main.java:246) at com.android.dx.command.dexer.Main.main(Main.java:215) at com.android.dx.command.Main.main(Main.java:106)

推荐答案

这个错误是由于在你的项目中引用了太多的方法引起的。 你可以阅读更多here.\">你可以在这里阅读更多。

This error is caused by having too many method referenced in your project. You can read more here.

一般而言,即使在调试版本中,您也需要删除未使用的库或使用 proguard ,以减少方法的数量引用。您也可以参考文章中提到的multi-dex,但它会让您的项目更加复杂。

Generally it means that you need to remove unused libraries or use proguard even on debug build to reduce the number of method referenced. You may also go with the multi-dex approached mentioned in the article but it makes your project more complicated.

这篇关于DexException:多个dex文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆