Espresso-web导入会导致duplicateFileException

时间:2015-11-19 10:14:21

标签: android gradle android-espresso

我正在使用Android Espresso。我需要espresso-web才能使用webview。我根据谷歌网站设置了浓缩咖啡。

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

我的依赖关系看起来像这样:

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

当我评论espresso-web导入/方法并排除此lib时,测试运行。但有了它,我得到了:

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

似乎是番石榴的一些问题。 Espress-web lib生成两个文件夹:espresso-web,espresso-core。 Espresso-core lib也生成espresso-core,它们似乎重叠 - 但这就是设置应该如何。排除Espresso核心库并没有帮助。知道怎么解决吗?

编辑:

现在在packagingOptions中的解决方法:

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

2 个答案:

答案 0 :(得分:5)

添加

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

build.gradle 文件为我工作。

答案 1 :(得分:2)

尝试相反的方式。不要使用espresso-core,而只需使用espresso-web。示例:

Espresso Official Test Kit Blog Example