Espresso-web import causes duplicateFileException

2019-02-21 09:29发布

问题:

I am using Android Espresso. I needed espresso-web to work with webviews. I set my espresso according to google website.

https://google.github.io/android-testing-support-library/downloads/index.html

My dependencies looks like that:

dependencies {

    androidTestCompile 'junit:junit:4.12'
    androidTestCompile 'com.squareup.spoon:spoon-client:1.1.10'
    androidTestCompile 'com.jraska:falcon-spoon-compat:0.3.1'
    androidTestCompile 'com.android.support:support-annotations:23.1.1'

    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'

    androidTestCompile "org.mockito:mockito-core:1.10.19"
    androidTestCompile "com.google.dexmaker:dexmaker:1.2"
    androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
}

When I comment espresso-web imports/methods and exclude this lib then tests run. But with it I get:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.google.guava/guava/pom.properties
    File1: /Users/F1sherKK/Dev/MyProject/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-web/2.2.1/jars/classes.jar
    File2: /Users/F1sherKK/Dev/MyProject/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2.1/jars/classes.jar

Seems to be some problem with guava. Espress-web lib generates both folders: espresso-web, espresso-core. Espresso-core lib also generates espresso-core and they seem to overlap - but that's how setup says it should be. Excluding Espresso-core lib doesn't help there. Any idea how to fix it?

Edit:

Workaround for now in packagingOptions:

exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'

回答1:

Try the other way around. Do not use espresso-core but just espresso-web. Example:

Espresso Official Test Kit Blog Example



回答2:

Adding

packagingOptions {
    exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
    exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}

to build.gradle file worked for me.