Android Studio 中带有 apache 库的意外顶级异常
UNEXPECTED TOP-LEVEL EXCEPTION in Android Studio with apache libraries
我正在开发一个将文件上传到服务器的项目,因为我正在使用一些 apache 库。但是当我尝试构建我的项目时出现以下错误
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Documents and Settings\rohitkum\AppData\Local\Android\Sdk\build-tools.1.2\dx.bat --dex --no-optimize --output C:\Documents and Settings\rohitkum\AndroidStudioProjects\NFCDemo\app\build\intermediates\dex\debug --input-list=C:\Documents and Settings\rohitkum\AndroidStudioProjects\NFCDemo\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/http/Consts;
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)
正如我从之前的一些回答中了解到的,当我们在您的 build.gradle 的依赖项中多次包含相同的 library/directory 时,就会发生此错误。但是我无法弄清楚我的哪个库在下面给出的 build.gradle 的依赖项中重复
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.+'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3') {
exclude module: "httpclient"
}
}
有人请帮助我找到我的重复库。提前致谢!
可能是因为,您的项目和任何库项目都包含 android-support-v4 jar。这就是为什么它显示重复
试试这个。这是最佳答案
我正在开发一个将文件上传到服务器的项目,因为我正在使用一些 apache 库。但是当我尝试构建我的项目时出现以下错误
Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Documents and Settings\rohitkum\AppData\Local\Android\Sdk\build-tools.1.2\dx.bat --dex --no-optimize --output C:\Documents and Settings\rohitkum\AndroidStudioProjects\NFCDemo\app\build\intermediates\dex\debug --input-list=C:\Documents and Settings\rohitkum\AndroidStudioProjects\NFCDemo\app\build\intermediates\tmp\dex\debug\inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lorg/apache/http/Consts; 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)
正如我从之前的一些回答中了解到的,当我们在您的 build.gradle 的依赖项中多次包含相同的 library/directory 时,就会发生此错误。但是我无法弄清楚我的哪个库在下面给出的 build.gradle 的依赖项中重复
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.+'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3') {
exclude module: "httpclient"
}
}
有人请帮助我找到我的重复库。提前致谢!
可能是因为,您的项目和任何库项目都包含 android-support-v4 jar。这就是为什么它显示重复
试试这个。这是最佳答案