使用 Contrib 和 Web Espresso 导入会导致 duplicateFileException

Using Contrib and Web Espresso imports causes duplicateFileException

我正在使用 Android 浓缩咖啡。我需要使用 Contrib 和 Web,所以这里的解决方案对我不起作用。

我收到这个错误。

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.1\jars\classes.jar File2: C:\Users\jwhit\ASProjects\v2.0\build\intermediates\exploded-aar\com.android.support.test.espresso\espresso-core.2.1\jars\classes.jar

这些是添加到我的 gradle 中的,如下所示。

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

我找到了解决方法。将此添加到 gradle build

的 android 部分
android{
    packagingOptions {

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

我希望有人觉得这有用。