0

我在 android studio 终端中执行 Gradle 命令来运行项目测试。

./gradlew connectedCheck --stacktrace

我收到以下错误:

:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:compileDebugAndroidTestJavaWithJavac
:app:compileDebugAndroidTestNdk UP-TO-DATE
:app:compileDebugAndroidTestSources
:app:transformClassesWithJarMergingForDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task   ':loginsdk:transformClassesWithJarMergingForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/mockito/AdditionalAnswers.class

Try:
 Run with --info or --debug option to get more log output.

Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.

 Caused by: com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/mockito/AdditionalAnswers.class
    at com.android.build.gradle.internal.transforms.JarMergingTransform.transform(JarMergingTransform.java:123)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:151)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:148)
    at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
    ... 69 more
Caused by: java.util.zip.ZipException: duplicate entry: org/mockito/AdditionalAnswers.class
    at com.android.build.gradle.internal.transforms.JarMerger.addJar(JarMerger.java:143)
    at com.android.build.gradle.internal.transforms.JarMergingTransform.transform(JarMergingTransform.java:113)
    ... 72 more


  BUILD FAILED
4

1 回答 1

3

今天也遇到了这个问题。我的日志类似。

:app:transformClassesWithJarMergingForDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/hamcrest/MatcherAssert.class

我找到了自己的罪魁祸首。它是

androidTestCompile 'com.android.support.test:testing-support-lib:0.1'

这是过时的并导致重复

androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'

我删除了前者,错误消失了。

于 2015-12-25T10:23:55.253 回答