AndroidAndroid Studio

com.android.dex.DexException: Multiple dex files define, Android Studio

After moving an Eclipse project to Android Studio work space, and build project (Make Project), I see Build successful but when I run the project… I get the following exception, com.android.dex.DexException: Multiple dex files define

Multiple dex files

Error:Execution failed for task ':<projectname>:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
<home>AppDataLocalAndroidsdkbuild-tools21.1.2dx.bat --dex --no-optimize --output <home>AndroidStudioProjects<projectpath>buildintermediatesdexdebug --input-list=<home>AndroidStudioProjects<projectpath>buildintermediatestmpdexdebuginputList.txt
Error Code:2
Output: UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompatIcs;
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)

after so much of struggle I found the issue is with dependencies of project gradle build file

dependencies {
compile project(':simplecropimagelib')
compile project(':library')
compile 'com.google.android.gms:play-services:+'
compile files('libs/acra-4.5.0.jar')
compile files('libs/android-support-v13.jar')
compile files('libs/core.jar')
compile files('libs/httpmime-4.2.3.jar')
compile files('libs/opencsv-2.3.jar')
compile files('libs/xstream-for-android-1.0.0.jar')
compile files('libs/zxingjar.jar')
compile 'com.android.support:appcompat-v7:21.0.2'
}

I find, this error occurs when you have the same library/directory included more than once in your build.gradle’s dependencies.
and in the above code, the issue is due to this line

compile files('libs/android-support-v13.jar')

which is included by other library project.

So, I just commented that line and run the Project, fixed the issue.

Phew….
Hope it helps somebody… cheers.. 🙂

note: If the dependency is declared as a dynamic version (like 1.+), Gradle will resolve this to the newest available static version (like 1.2) in the repository.

2 thoughts on “com.android.dex.DexException: Multiple dex files define, Android Studio

Leave a Reply

Your email address will not be published. Required fields are marked *