com.android.dex.DexException:多个dex文件定义Lorg / hamcrest / Description;

时间:2016-04-26 23:50:17

标签: java android junit

我已经搜索了Stackoverflow这个错误并找到了很多解决方案并尝试了所有解决方案,但没有一个能为我工作,例如将junit更改为" 4.8 +"或将这些添加到build.gradle文件:

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'

我总是收到此错误:

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

junit更改为" 4.8 +"它说有冲突,我需要做到4.11。

解决方案是什么!

1 个答案:

答案 0 :(得分:0)

通过以下方式解决:

androidTestCompile('junit:junit-dep:4.8.+')