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

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

问题描述

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

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

新版本的 espresso-contrib 2.2.2 库现在具有对com.android.support:appcompat-v7:23.1.1的依赖性,导致在我们的compile时间依赖性中使用不同版本的appcompat-v7时发生冲突,如下所示:

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

为避免发生冲突,当我们从espresso-contrib中排除appcompat-v7依赖项时,如下所示,由于对design support lib的某些值依赖关系,它再次中断.

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

错误:

错误:(69)检索项目的父项时出错:未找到与给定名称'TextAppearance.AppCompat.Display1'匹配的资源.

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

根本原因:

这是因为design支持库依赖于 appcompat-v7.
因此,当我们从中排除"appcompat-v7"模块时 espresso-contrib依赖项(如上),design支持库下载为 找不到espresso-contrib lib的传递依赖的一部分 正在使用的appcompat-v7 lib(23.1.1)的兼容版本 内部在其资源文件中,从而发出上述错误.

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依赖项,如下所示:

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

解决了冲突问题!

长期版本(以防有人感兴趣):

LONGER VERSION (in case someone is interested):

要弄清我们在使用"espresso-contrib"库时遇到的各种冲突问题的原因,我创建了示例应用程序来找出根本原因.

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

通过在app/build.gradle文件中添加以下行来创建使用'espresso-contrib' lib版本 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'

}

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

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:

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

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.

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

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'

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

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

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

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

通过更改先前的build.gradle文件,将应用程序的build.gradle更改为使用'espresso-contrib' lib版本 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'
  }
}

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

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

错误:

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

所以,看着错误,我在build.gradle上面又增加了一行:

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:

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

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.

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

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

exclude module: 'design'

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

This resolves the conflict issue in lib version 2.2.2!

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

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