【发布时间】:2016-06-16 16:57:26
【问题描述】:
尝试运行仪器测试,我收到此错误:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.
com.android.build.api.transform.TransformException:
java.util.zip.ZipException:
duplicate entry:
org/junit/ClassRule.class
但有时duplicate entry 是:
duplicate entry:
junit/extensions/ActiveTestSuite$1.class
这显然是正确的:Control-N -> 输入 ClassRule 显示:
C:\Users\me\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa\junit-4.12-sources.jar!\org\junit\ClassRule.java-
C:\Users\me\.gradle\caches\modules-2\files-2.1\junit\junit-dep\4.10\64417b3bafdecd366afa514bd5beeae6c1f85ece\junit-dep-4.10.jar!\org\junit\ClassRule.class(反编译的.class文件,字节码版本:49.0(Java 5.0)
搜索 ActiveTestSuite 得到 3 个结果,全部在 C:\Users\me\.gradle\caches\modules-2\files-2.1\junit\
有没有办法查看依赖关系图?我评论了与app/build.gradle 的依赖部分相关的所有junit:
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.firebase:firebase-core:9.0.2'
compile 'com.google.firebase:firebase-messaging:9.0.2'
/// <Dagger>
provided 'javax.annotation:jsr250-api:1.0'
apt 'com.google.dagger:dagger-compiler:2.0.1'
compile 'com.google.dagger:dagger:2.0.1'
compile 'com.google.dagger:dagger-compiler:2.0.1'
/// </Dagger>
// ------ JSON ... ------
testCompile 'org.glassfish:javax.json:1.0.4'
testCompile 'com.fasterxml.jackson.core:jackson-databind:2.7.4'
// ------ ... JSON end ------
apt 'com.jakewharton:butterknife-compiler:8.0.1'
//testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.robolectric:robolectric:3.0'
//androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'org.robolectric:robolectric:3.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2'){
exclude group: 'javax.inject'
}
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v13:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.jakewharton:butterknife:8.0.1'
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
//<Floating Buttons>
compile 'com.github.clans:fab:1.6.4'
//</Floating Buttons>
compile 'org.apache.commons:commons-lang3:3.4'
}
【问题讨论】:
-
试试这个,加入 gradle.. 配置 { all*.exclude group: 'com.android.support', module: 'support-v4' }
-
@WaqarYounis,我有这个:
configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:23.3.0', 'junit:junit:4.12' }(我刚刚添加了junit)。但问题依然存在:java.util.zip.ZipException: duplicate entry: junit/extensions/ActiveTestSuite$1.class -
试试这个 compile 'com.android.support:support-annotations:23.3.0
-
名为“app”的模块的依赖关系图 - gradlew app:dependencies。此外,如果依赖项之一通过在项目中复制粘贴它(或作为 jar 添加到 libs 文件夹)添加了 junit,而不更改 junit 的包,则此错误很常见。在这种情况下,依赖是不受管理的,因此 gradle 的解析策略不起作用
-
@m.ostroverkhov,没办法查出哪个库是冒犯的?
标签: java android android-studio gradle junit