multidex app获取ZipException:junit的重复条目,尝试运行检测测试

时间:2016-06-16 16:57:27

标签: java android android-studio gradle junit

尝试运行检测测试,我收到此错误:

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会显示:

  1. C:\Users\me\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa\junit-4.12-sources.jar!\org\junit\ClassRule.java
  2. 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)
  3. 搜索ActiveTestSuite会得到3个结果,全部都在C:\Users\me\.gradle\caches\modules-2\files-2.1\junit\

    有没有办法查看依赖关系图?我评论了与junit的依赖关系部分相关的所有app/build.gradle

    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'
    }
    

1 个答案:

答案 0 :(得分:0)

您需要做的就是在我们的依赖列表中添加以下行:

 testCompile "junit:junit:4.12'

然后,通过在我们的app/build.gradle中添加以下块来强制此版本的Junit依赖于整个项目:

configurations.all{
    resolutionStrategy.force 'junit:junit:4.12'
}

这将解决所有依赖冲突。

了解更多信息: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html