14

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'
F1sher
  • 7,140
  • 11
  • 48
  • 85
  • I'm seeing the exact same issue. It only occurred after upgrading the Android Plugin for Gradle from v1.3.1 to v1.5.0 and also (independently) when upgrading the SDK Manager Plugin from v0.12.0 to d0c113b. Oh and your workaround seems to work fine! – Stephen Niedzielski Nov 20 '15 at 20:12
  • While the accepted answer does solve the problem, it does not explain why and it's a link only answer. This answer on another question: http://stackoverflow.com/a/35774745/267540 helps you figure out why. (comment for the benefit of future viewers of this post) – e4c5 Jun 17 '16 at 12:56

2 Answers2

5

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.

Saqib R.
  • 2,919
  • 2
  • 26
  • 21
2

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

Espresso Official Test Kit Blog Example

Testing Singh
  • 1,347
  • 1
  • 15
  • 26
  • When I used espresso-web and not espresso-core, it strangely got the same error. It wouldn't compile until I used espresso-core and *not* espresso-web. – Rock Lee Feb 04 '16 at 03:47
  • same for me, using only espresso-web still gives the error, it worked with packagingOptions workaround – lelloman May 24 '16 at 13:29