gpt4 book ai didi

android-gradle-plugin - Android espresso-contrib gradle 构建失败

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

我正在尝试学习 android espresso .. 我遵循了一些基本教程,并且运行良好。但是现在我想对android抽屉导航做一些测试。为此,我需要使用 gradle 依赖项 androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' 但它会导致与其他依赖项发生冲突。我的gradle文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "my.com.myapp_android"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
//material design
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'

//zxing
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'

//Testing
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
// Optional -- UI testing with UI Automator
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'




//inMarketSDK
//compile group: 'com.inmarket', name: 'm2msdk', version: '2.29', ext: 'aar'

}

错误是这样的:
Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

接着是: link用于浓缩咖啡安装

我还尝试排除注释依赖项:
 androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2')  {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2')
{
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}

最佳答案

TL; 博士;

新版 espresso-contrib 2.2.2 库现在依赖于 com.android.support:appcompat-v7:23.1.1使用不同版本的 appcompat-v7 导致冲突在我们的 compile时间依赖性如下:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'

androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
}

为了避免在排除 appcompat-v7 时发生冲突依赖来自 espresso-contrib如下所示,由于对 design support 的某些值依赖,它再次中断库。
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'appcompat-v7'
}

错误:

Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.



根本原因:

This is because the design support lib has dependency on appcompat-v7.
So,when we exclude 'appcompat-v7' module from espresso-contrib dependencies(like above) , the design support lib downloaded as part of transitive dependency of espresso-contrib lib couldn't find the compatible version of appcompat-v7 lib(23.1.1) it is using internally in its resources files and thus gives out the above error.



因此,上述问题的解决方案是从 espresso-contrib 中排除 'design-support' lib 依赖项。像下面这样:
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'design'
}

这样就解决了冲突问题!

更长的版本 (如果有人感兴趣):

为了找出我们在使用“espresso-contrib”库时遇到的各种冲突问题的原因,我创建了示例应用程序来找出根本原因。
Step 1:Using Espresso-Contrib Lib version 2.2.1

创建要使用的应用程序 'espresso-contrib' lib版本 2.2.1 通过在 app/build.gradle 中添加以下行文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'

}

注意:在这种情况下,我不会导入任何其他支持库组件,例如 appcompat-v7,recyclerview-v7,etc .

上述设置的依赖关系图如下所示:
enter image description here

可以看出 espresso-contrib 2.2.1 lib 对 23.0.1 版本具有传递依赖关系 support-v4 , recyclerview-v7 , support-annotations ,等等。

因为我没有为 recyclerview-v7 定义依赖项, support-annotations在我的项目中,上述设置可以正常工作。

但是,当我们在我们的项目中将它们定义为编译依赖项 [如下所示] 时,我们会遇到您的问题中所述的版本冲突问题。
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'

为了避免这些冲突,我们在 espresso-contrib 库中添加了以下行:
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}

这可确保这些依赖项不会作为 espresso-contrib 的一部分下载。传递依赖。
以上设置一切正常。没问题!
Step 2: Using Espresso-Contrib lib version 2.2.2

将 App 的 build.gradle 更改为使用 'espresso-contrib' lib版本 2.2.2 通过更改之前的 build.gradle 文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
testCompile 'junit:junit:4.12'

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
}

但是当我使用上述设置构建项目时..build 失败并发布有问题的错误..

错误:

Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.



因此,查看错误,我在 build.gradle 上方又添加了一行:
exclude module: 'appcompat-v7' (inside androidTestCompile block of espresso-contrib)

但这并不能解决冲突问题,我在评论中收到了值依赖错误。
所以我再次检查我的应用程序的依赖关系图:
enter image description here

现在可以看出 espresso-contrib 2.2.2 lib 现在具有对 com.android.support:design:23.1.1 的传递依赖造成上述冲突。

因此,我们需要在 androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') 中添加以下行堵塞:
exclude module: 'design'

这解决了 lib 版本 2.2.2 中的冲突问题!

关于android-gradle-plugin - Android espresso-contrib gradle 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37307671/

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