1

I've searched Stackoverflow for this error and found a lot of solutions and tried them all, none worked for me, for example changing junit to "4.8+" or adding these to build.gradle file:

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'LICENSE.txt'
}


androidTestCompile ('com.squareup:fest-android:1.0.+') {
    exclude group: 'com.android.support'
}
androidTestCompile 'com.google.dexmaker:dexmaker:1.+'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.+'
androidTestCompile 'org.powermock:powermock-api-support:1.6.3'
androidTestCompile 'junit:junit:4.11'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile 'org.mockito:mockito-core:1.9.5'

I'm always getting this error :

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define    Lorg/hamcrest/Description;

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException:     com.android.ide.common.process.ProcessException:   org.gradle.process.internal.ExecException: Process 'command 'C:\Program   Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2

When changing junit to "4.8+" it says there's a conflict, and I need to make it 4.11.

What's the solution!

T D Nguyen
  • 7,054
  • 4
  • 51
  • 71
Jaeger
  • 1,646
  • 8
  • 27
  • 59
  • Try changing the hamcrest-library to the one that is likely being included by one of the other packages. In my case I was able to fix the problem by switching to androidTestCompile 'org.hamcrest:hamcrest-library:1.3' you can find out which libraries and versions are being included by opening the terminal and running gradlew app:dependencies. – lodlock Apr 27 '16 at 00:54
  • Possible duplicate of [Android Gradle DexException - Multiple dex files defined](http://stackoverflow.com/questions/22702267/android-gradle-dexexception-multiple-dex-files-defined) – blahdiblah Dec 14 '16 at 00:33

1 Answers1

0

Solved by replacing it by :

androidTestCompile('junit:junit-dep:4.8.+')
Jaeger
  • 1,646
  • 8
  • 27
  • 59