Android espresso-contrib gradle 构建失败 [英] Android espresso-contrib gradle build failing

查看:27
本文介绍了Android espresso-contrib gradle 构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

应用插件:'com.android.application'安卓 {compileSdkVersion 23构建工具版本23.0.3"默认配置{applicationIdmy.com.myapp_android"minSdk 版本 18目标SDK版本23版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}存储库{jcenter()}依赖{编译文件树(目录:'libs',包括:['*.jar'])testCompile 'junit:junit:4.12'//材质设计编译'com.android.support:appcompat-v7:23.3.0'编译'com.android.support:support-v4:23.3.0'//zxing编译'com.journeyapps:zxing-android-embedded:3.2.0@aar'编译'com.google.zxing:core:3.2.1'//测试//可选 -- Mockito 框架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'//可选 -- Hamcrest 库androidTestCompile 'org.hamcrest:hamcrest-library:1.3'//可选——使用 Espresso 进行 UI 测试androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'//可选——使用 UI Automator 进行 UI 测试androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'//市场SDK//编译组:'com.inmarket',名称:'m2msdk',版本:'2.29',ext:'aar'}

错误是这样的:

错误:与依赖项com.android.support:support-v4"冲突.应用程序 (23.3.0) 和测试应用程序 (23.1.1) 的已解决版本不同.有关详细信息,请参阅 http://g.co/androidstudio/app-test-app-conflict.错误:与依赖项com.android.support:appcompat-v7"冲突.应用程序 (23.3.0) 和测试应用程序 (23.1.1) 的已解决版本不同.有关详细信息,请参阅 http://g.co/androidstudio/app-test-app-conflict.

按照此操作:

可以看出,espresso-contrib 2.2.1lib 对
的 23.0.1 版具有传递依赖关系support-v4recyclerview-v7support-annotations 等.

由于我没有为我的项目中的 recyclerview-v7support-annotations 定义依赖项,因此上述设置可以正常工作.

但是当我们在我们的项目中将它们定义为编译依赖项 [如下所示] 时,我们会遇到您的问题中所述的版本冲突问题.

编译'com.android.support:appcompat-v7:23.3.0'编译'com.android.support:support-v4:23.3.0'

为了避免这些冲突,我们在 espresso-contrib 库中添加了以下行:

 androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1')​​{排除模块:'支持注释'排除模块:'support-v4'排除模块:'support-v13'排除模块:'recyclerview-v7'}

这可确保这些依赖项不会作为 espresso-contrib 传递依赖项的一部分下载.
以上设置一切正常.没问题!

第 2 步:使用 Espresso-Contrib 库版本 2.2.2

通过更改之前的 build.gradle 文件,将应用的 build.gradle 更改为使用 'espresso-contrib' lib 版本 2.2.2:

依赖项{编译文件树(目录:'libs',包括:['*.jar'])编译'com.android.support:appcompat-v7:23.3.0'编译'com.android.support:support-v4:23.3.0'testCompile 'junit:junit:4.12'androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){排除模块:'支持注释'排除模块:'support-v4'排除模块:'support-v13'排除模块:'recyclerview-v7'}}

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

错误:

<块引用>

错误:与依赖项com.android.support:appcompat-v7"冲突.应用程序 (23.3.0) 和测试应用程序 (23.1.1) 的已解决版本不同.有关详细信息,请参阅

现在可以看到 espresso-contrib 2.2.2 库现在对 com.android.support:design:23.1.1 具有传递依赖,导致上述冲突.

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

排除模块:'设计'

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

I'm trying to learn android espresso.. I followed some basic tutorials and it was working fine. But now I want to do some tests on the android navigation drawer. For that I need to use gradle dependency androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' but it's causing conflict with other dependencies. My gradle file :

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 is something like this:

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.

followed this : link for espresso install

I also tried to exclude annotation dependency :

 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;DR;

New version of espresso-contrib 2.2.2 library has now dependency on com.android.support:appcompat-v7:23.1.1 resulting into conflict when using different version of appcompat-v7 in our compile time dependency like below:

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

To avoid conflict when we exclude appcompat-v7 dependency from espresso-contrib like below it breaks again due to some value dependencies on 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: 'appcompat-v7'
}

Error:

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

Root cause:

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.

So, the solution to above problem is to exclude 'design-support' lib dependency from espresso-contrib like below:

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

That solves the conflict problem!

LONGER VERSION (in case someone is interested):

To found out the reasons of various conflict issues we face when using `espresso-contrib' library i have created sample app to find out the root cause.

Step 1:Using Espresso-Contrib Lib version 2.2.1

Created App to use 'espresso-contrib' lib version 2.2.1 by adding following lines in app/build.gradle file:

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'

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

}

Note: In this case,I am not importing any other support library components like
appcompat-v7,recyclerview-v7,etc.

The dependency graph for the above setup looks like below:

As can be seen that espresso-contrib 2.2.1lib has transitive dependencies on version 23.0.1 of
support-v4,recyclerview-v7,support-annotations ,etc.

As i am not defining dependencies for recyclerview-v7,support-annotations in my project the above setup would work just fine.

But when we define those as compile dependencies [like below] in our project we get version conflict issues as stated in your question.

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'

To avoid those conflicts we add below line to our espresso-contrib lib:

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

This makes sure those dependencies aren't downloaded as part of espresso-contrib transitive dependencies.
Everything runs fine with above setup.No issues!

Step 2: Using Espresso-Contrib lib version 2.2.2

Changed App's build.gradle to use 'espresso-contrib' lib version 2.2.2 by changing the previous build.gradle file:

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

But when i build project using above setup..build fails with error posted in question..

Error:

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.

So, looking at error i added one more line to above build.gradle:

exclude module: 'appcompat-v7' (inside androidTestCompile block of espresso-contrib)

But that doesn't resolves the conflict issue and i get value dependencies error posted in comments.
So i check for dependency graph of my app again:

As can be seen now that espresso-contrib 2.2.2 lib has now transitive dependency on com.android.support:design:23.1.1 causing the above conflict.

So, we need to add below line inside androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') block:

exclude module: 'design'

This resolves the conflict issue in lib version 2.2.2!

这篇关于Android espresso-contrib gradle 构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆