Android Studio中意外顶级EXCEPTION [英] UNEXPECTED TOP-LEVEL EXCEPTION in Android Studio
问题描述
在我的一个项目我得到这个例外,同时建立文件的gradle
错误:执行失败的任务。':emBazaarV4:dexDebug
com.android.ide.common.internal.LoggedErrorException:无法运行命令:F:\\ AndroidSDK \\构建工具\\ 21.1.2 \\ dx.bat --dex
--no-优化--output F:\\ AndroidStudioWorkspace \\ EmBazaarV4 \\ emBazaarV4 \\建立\\中间体\\ DEX \\调试
--input-列表= F:\\ AndroidStudioWorkspace \\ EmBazaarV4 \\ emBazaarV4 \\建立\\中间体\\ tmp目录\\ DEX \\调试\\ inputList.txt
错误code:2输出:意外的顶级例外:
com.android.dex.DexException:多DEX文件定义
LCOM /谷歌/ GSON / JsonSerializer;在
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:454)
在com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)在
com.android.dx.command.dexer.Main.run(Main.java:246)在
com.android.dx.command.dexer.Main.main(Main.java:215)在
com.android.dx.command.Main.main(Main.java:106)
块引用>
块引用>和这里是我的依赖
{相关性
编译com.facebook.android:facebook-android-sdk:3.22.0
编译com.aviary.android.feather.sdk:舍-SDK:3.6.3
编译com.android.support:support-v4:21.0.3
编译com.google.android.gms:播放服务:+'
编译com.squareup.okhttp:okhttp:2.2.0
编译com.squareup.okio:奥基奥:1.1.0
编译com.squareup.okhttp:okhttp-的URLConnection:2.2.0
编译com.squareup.retrofit:改造:1.9.0
编译com.squareup.picasso:毕加索:2.4.0
编译文件(库/公地IO-2.4.jar')
编译文件(库/ crashlytics.jar')
编译文件(库/ httpmime-4.1.3.jar')
编译文件(库/ jumblr-0.0.8-JAR与 - dependencies.jar')
编译文件(库/路标-commonshttp4-1.2.1.2.jar')
编译文件(库/路标核-1.2.1.2.jar')
编译文件(库/ simplesocialsharing.jar')
编译文件(库/ gcm.jar')}我曾尝试一切,但没有得到如何排除这种多DEX文件。我已经找到解决方案V4这样
配置{
所有* .exclude组:com.android.support',模块:支持-V4
}所以有这些错误类型的一般解?
解决方案由于加布里埃尔说,顶层的异常总是由于不同版本的同一个库的冲突发生。
所有我建议:首先,避免使用添加文件相关性,尽可能为你,永远尝试从jcenter库添加依赖。貌似需要的Gradle依赖冲突的照顾。
块引用>所以,现在,有一些方法来避免它:
使用只有一个包含所有必需类的版本。像应用紧凑拥有所有V4支持类,所以你不需要导入V4支持veresion如果要导入appcompact V7。
您可以随时从编译依赖排除包。例如:
//为包:
依赖{
编译(com.android.support:support-v4:21.0.3){
排除组:com.android.support',模块:支持-V4
}
}
In one of my projects i am getting this Exception while building gradle file
Error:Execution failed for task ':emBazaarV4:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command: F:\AndroidSDK\build-tools\21.1.2\dx.bat --dex --no-optimize --output F:\AndroidStudioWorkspace\EmBazaarV4\emBazaarV4\build\intermediates\dex\debug --input- list=F:\AndroidStudioWorkspace\EmBazaarV4\emBazaarV4\build\intermediates\tmp\dex\debug\inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer; 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)
and here is my dependencies
dependencies { compile 'com.facebook.android:facebook-android-sdk:3.22.0' compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.3' compile 'com.android.support:support-v4:21.0.3' compile 'com.google.android.gms:play-services:+' compile 'com.squareup.okhttp:okhttp:2.2.0' compile 'com.squareup.okio:okio:1.1.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.picasso:picasso:2.4.0' compile files('libs/commons-io-2.4.jar') compile files('libs/crashlytics.jar') compile files('libs/httpmime-4.1.3.jar') compile files('libs/jumblr-0.0.8-jar-with-dependencies.jar') compile files('libs/signpost-commonshttp4-1.2.1.2.jar') compile files('libs/signpost-core-1.2.1.2.jar') compile files('libs/simplesocialsharing.jar') compile files('libs/gcm.jar') }
I have tried everything but not getting how to exclude this multiple dex files. I have found solution for v4 like this
configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
so is there any general solution for these kind of errors?
解决方案As Gabriele says, TopLevel Exception always occur due to conflict of different version of same library.
First of all I would suggest, avoid using adding file dependency as much as possible for you, Always try to add dependency from the jcenter repository. Looks like gradle takes care of conflicting dependencies.
So now, There are some ways to avoid it:
Use only one version which contains all your required classes. like app compact has all v4 support classes, SO you dont need to import v4 support veresion if you're importing appcompact v7.
You can always exclude a package from the compiled dependencies. For Example:
//for the package: dependencies { compile("com.android.support:support-v4:21.0.3") { exclude group: 'com.android.support', module: 'support-v4' } }
这篇关于Android Studio中意外顶级EXCEPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!