![](/img/trans.png)
[英]How to solve the error of different version of libraries in build.gradle?
[英]How to solve duplication error when loading both espresso web and core in build.gradle?
我正在嘗試使用Android Espresso Web進行自動化測試。
將其添加到如下所示的build.gradle文件后,出現“ DuplicateFileException”異常。
根據API ,兩個依賴關系都應該存在於build.gradle文件中,所以我不明白為什么會得到重復異常以及如何解決它。
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'
任何想法如何解決此錯誤?
根據Google的Android測試支持庫示例,如果您現有的應用程序依賴於Web視圖,則無需同時聲明兩者。
檢查此配置:
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; }
來自: https : //github.com/googlesamples/android-testing/blob/master/ui/espresso/WebBasicSample/app/build.gradle
如果兩者都需要,請打開build.gradle文件並添加:
packagingOptions {
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
它應該工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.