Search code examples
androidandroid-studiogradleandroid-multidex

Duplicate Entry during Android gradle build in Task :transformClassesWithJarMergingAndroidTest


I'm getting the following exception when building my Android app with Gradle:

Execution failed for task ':transformClassesWithJarMergingForGoogleGermanDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/hamcrest/BaseDesc

The problem seems to be that in my build.gradle file I have declared:

testCompile 'org.hamcrest:hamcrest-all:1.3'
androidTestCompile 'org.hamcrest:hamcrest-all:1.3'

However, I need both dependencies for unit tests and integration tests. How to solve this?


Solution

  • The problem was that another jar (Mockito) included hamcrest-core as a transitive dependency. This module contains all classes under the package name org.hamcrest.*. Hence the conflict. The solution was:

    configurations {
        all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
    }
    

    As described here: https://docs.gradle.org/current/userguide/dependency_management.html Chapter 23.4.7