gpt4 book ai didi

android - 在build.gradle中同时加载espresso网站和核心时,如何解决重复错误?

转载 作者:行者123 更新时间:2023-12-03 06:04:38 25 4
gpt4 key购买 nike

我正在尝试使用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 View ,则无需同时声明两者。
检查此配置:

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


如果两者都需要,请打开build.gradle文件并添加:
packagingOptions {
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
它应该工作

关于android - 在build.gradle中同时加载espresso网站和核心时,如何解决重复错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39512507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com