微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android-gradle – Android espresso-contrib gradle build失败

我正在尝试学习 android espresso ..我遵循了一些基本的教程,它工作正常.但现在我想在android导航抽屉上做一些测试.为此,我需要使用gradle依赖androidTestCompile’c​​om.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 for espresso install

我还试图排除注释依赖:

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,在我们的编译时依赖项中使用不同版本的appcompat-v7会产生冲突,如下所示:

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依赖关系时,由于设计支持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:(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中排除“设计支持”的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

创建App以通过在app / build.gradle文件添加以下行来使用’espresso-contrib’lib 2.2.1版:

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

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

}

注意:在这种情况下,我没有导入任何其他支持库组件,如
程序兼容性-V7,recyclerview-V7等.

上述设置的依赖关系图如下所示:

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

由于我没有为recyclerview-v7定义依赖项,在我的项目中支持注释,上面的设置可以正常工作.

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

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

为了避免这些冲突,我们将以下行添加到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传递依赖项的一部分下载.
以上设置一切正常.没有问题!

Step 2: Using Espresso-Contrib lib version 2.2.2

通过更改以前的build.gradle文件,将App的build.gradle更改为使用’espresso-contrib’lib 2.2.2版:

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构建项目失败并发布了错误错误..

错误

Error:Conflict with dependency ‘com.android.support:appcompat-v7’. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See 07001 for details.

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

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

但这并没有解决冲突问题,我在评论中发布了价值依赖性错误.
所以我再次检查我的应用程序的依赖图:

现在可以看出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版中的冲突问题!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐