Using Contrib and Web Espresso imports causes duplicateFileException

Issue

I am using Android Espresso. I need to use Contrib and Web so the solution here will not work for me. Link

I get this error.

Error:Execution failed for task ':transformResourcesWithMergeJavaResForQaDebugAndroidTest'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.google.guava/guava/pom.xml File1: C:\Users\jwhit\ASProjects\v2.0\build\intermediates\exploded-aar\com.android.support.test.espresso\espresso-web\2.2.1\jars\classes.jar File2: C:\Users\jwhit\ASProjects\v2.0\build\intermediates\exploded-aar\com.android.support.test.espresso\espresso-core\2.2.1\jars\classes.jar

These are added in my gradle as shown below.

dependencies {
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
    androidTestCompile 'com.android.support:support-annotations:23.2.0'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.1')
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1'){
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
}

Solution

I found the solution to this. Add this to the android section of your gradle build

android{
    packagingOptions {

        pickFirst('META-INF/maven/com.google.guava/guava/pom.xml')
        pickFirst('META-INF/maven/com.google.guava/guava/pom.properties')
    }
}

I hope someone finds this useful.

Answered By – J Whitfield

Leave a Comment