Exception
Exception

Reputation: 2323

UNEXPECTED TOP-LEVEL EXCEPTION in Android Studio with apache libraries

I am working on a project to upload a file to a server because of which I am using some apache libraries. But I am getting the following error when I try to build my project

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\21.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)

As I understood from some of the previous answers, this error occurs when we have the same library/directory included more than once in your build.gradle's dependencies. But I am not able to figure out which of my library is repeating in build.gradle's dependencies given below

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"
    }

}

Someone Please help me in finding my duplicate library. Thanks in advance!

Upvotes: 1

Views: 707

Answers (1)

Deniz
Deniz

Reputation: 12530

It may be because, both your project and any of the library project includes android-support-v4 jar. that is why it showing duplication

Try this. this is the best answer

https://stackoverflow.com/a/21100040/3020568

Upvotes: 2

Related Questions