0

I'm trying to use Android Espresso Web for my automation test.

After adding it to the build.gradle file like shown below, I get a "DuplicateFileException" exception.

According to the API, both of the dependancies should be present in the build.gradle file so I don't understand why I get a duplication exception and how to solve it.

Error:Execution failed for task ':CompanyAAA:transformResourcesWithMergeJavaResForStagingDebugAndroidTest'.
> 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/mayabechler-speicher/CompanyAAA-Android/CompanyAAA/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-web/2.2.2/jars/classes.jar
     File2: /Users/mayabechler-speicher/CompanyAAA-Android/CompanyAAA/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2.2/jars/classes.jar

[4:24]  
// Espresso core
   androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

   // Espresso web
   androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'

Any idea how to solve this error?

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
Itai Ganot
  • 5,873
  • 18
  • 56
  • 99
  • 1
    Possible duplicate of [Espresso-web import causes duplicateFileException](http://stackoverflow.com/questions/33800924/espresso-web-import-causes-duplicatefileexception) – R. Zagórski Sep 15 '16 at 13:53

1 Answers1

0

According to Google's Android Testing Support Library Examples, you don't need to declare both, if your existing app depends on webviews.

Check this configuration:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
        applicationId "com.example.android.testing.espresso.web.BasicSample"
        minSdkVersion 10
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        abortOnError false
    }
    productFlavors {
    }
    packagingOptions {
      exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
      exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
    }
}

dependencies {
    // App dependencies
    compile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
    compile 'com.google.guava:guava:18.0'
    // Testing-only dependencies
    // Force usage of support annotations in the test app, since it is internally used by the runner module.
    androidTestCompile 'com.android.support:support-annotations:' + rootProject.supportLibVersion;
    androidTestCompile 'com.android.support.test:runner:' + rootProject.runnerVersion;
    androidTestCompile 'com.android.support.test:rules:' + rootProject.rulesVersion;
    androidTestCompile 'com.android.support.test.espresso:espresso-web:' + rootProject.espressoVersion;
}

From: https://github.com/googlesamples/android-testing/blob/master/ui/espresso/WebBasicSample/app/build.gradle

If you need both, open your build.gradle file and add:

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

It should work

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94