I encounter the following runtime errors when doing the instrumentation test.
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description;
Unknown source file : at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file : at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file : at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file : at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file : at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file : at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file : at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file : at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file : at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file : at com.android.dx.command.Main.main(Main.java:106)
I think there are many similar questions with this issue.
However, most of them suggest to exclude the hamcrest librarty from other dependencies, but it did not solve my problem :(
Here is the dependencies part of my build.gradle
dependencies {
androidTestCompile files('libs/java-hamcrest-2.0.0.0.jar')
androidTestCompile files('libs/hamcrest-json-0.2.jar')
androidTestCompile files('libs/jsonassert-1.2.3.jar')
androidTestCompile ('org.powermock:powermock-module-junit4:1.6.3')
{
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
}
androidTestCompile ('org.powermock:powermock-api-mockito:1.6.3') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
}
androidTestCompile ('com.android.support.test:runner:0.4.1') {
exclude module: 'hamcrest-core'
}
androidTestCompile ('com.android.support.test:rules:0.4.1') {
exclude module: 'hamcrest-core'
}
}
I use gradle dependencies
and there is no hamcrest-core
in androidTestCompile
, but still fails at the instrumentation time.
Something important I miss?
Thank you!