Android Gradle DexException: Multiple dex files define Lorg/hamcrest/Description

后端 未结 4 1185
灰色年华
灰色年华 2020-12-01 10:53

com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description

occurring while trying to do a debug build/test either via Android

4条回答
  •  广开言路
    2020-12-01 11:19

    I solved the error by looking in Android Studio for the exact class called 'Description'. It turned out to be present in 3 jars. One from junit, one from a direct dependency and one from mockito.

    enter image description here

    It turns out that junit, instead of a normal dependency, includes the Hamcrest classes in the junit jar.

    enter image description here

    To be able to solve the problem include junit-dep instead of junit.

    so change

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

    to

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

    Mockito has the same problem/solution: use mockito-core.1.9.5.jar instead of mockito-all.1.9.5.jar

提交回复
热议问题