使用Gradle构建我的Android应用时出现以下异常:
Execution failed for task ':transformClassesWithJarMergingForGoogleGermanDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/hamcrest/BaseDesc
问题似乎是在我的build.gradle文件中我声明了:
testCompile 'org.hamcrest:hamcrest-all:1.3'
androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
但是,我需要两个依赖项进行单元测试和集成测试。怎么解决这个问题?
答案 0 :(得分:1)
问题是另一个jar(Mockito)包含hamcrest-core
作为传递依赖。此模块包含包名org.hamcrest.*
下的所有类。因此冲突。解决方案是:
configurations {
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
如下所述:https://docs.gradle.org/current/userguide/dependency_management.html第23.4.7节
答案 1 :(得分:0)
尝试为重复输入添加exclude
参数。
androidTestCompile 'org.hamcrest:hamcrest-all:1.3' {
exclude module: 'BaseDesc'
}
答案 2 :(得分:-3)
buildTypes {
release {
multiDexEnabled true;
}
}
试试这个应该有效