Android版本24.0.0和Espresso 2.0 gradle异常 [英] Android version 24.0.0 and Espresso 2.0 gradle exception

查看:127
本文介绍了Android版本24.0.0和Espresso 2.0 gradle异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用中使用Espresso 2.0,以测试UI元素。然而,Gradle不会这么做。它给了我这个信息

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

这是我的 gradle文件

  apply plugin:'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion24.0.0

defaultConfig {
applicationIdtheo.testing.espressotutorial
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName1.0

$ b}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules .pro'
}
}

packagingOptions {
exclude'LICENSE.txt'
}
}

依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
testCompile'junit:junit:4.12'
compile'c​​om.android.support: appcompat-v7:24.0.0'

androidTestCompile'c​​om.android.support.test.espresso:espresso-core:2.0'

// Android JUnit Runner
androidTestCompile'c​​om.android.support.test:runner:0.5'
// JUnit4 Rules
androidTestCompile'c​​om.android.support.test:rules:0.5'
}

我应该更新测试跑步者吗?这让我很头疼。

谢谢,

Theo。

解决方案

Espresso具有导致这些问题的传递依赖关系。您可以从 androidTest 依赖关系中将所有依赖关系排除到组 com.android.support 之外:

  //将Espresso的传递依赖关系排除在组com.android.support中的所有包上
configurations.androidTestCompile.dependencies.each {androidTestCompileDependency - > ;
androidTestCompileDependency.exclude group:'com.android.support'
}

你应该使用Espresso 2.2.2 !一个完整的例子:

 依赖项{

def espressoVersion ='2.2.2'
def testRunnerVersion ='0.5'

androidTestCompilecom.android.support.test:runner:$ {testRunnerVersion}
androidTestCompilecom.android.support.test:rules:$ {testRunnerVersion }
androidTestCompilecom.android.support.test.espresso:espresso-core:$ {espressoVersion}
androidTestCompilecom.android.support.test.espresso:espresso-contrib:$ {espressoVersion }
androidTestCompilecom.android.support.test.espresso:espresso-intents:$ {espressoVersion}

configurations.androidTestCompile.dependencies.each {androidTestCompileDependency - >
androidTestCompileDependency.exclude group:'com.android.support'
}
}


I am trying to use Espresso 2.0 in my app,in order to test the UI elements. However the gradle doesn't let do it. It gives me this message

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

This is my gradle file

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "theo.testing.espressotutorial"
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"


}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions{
    exclude 'LICENSE.txt'
  }
}

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

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'

// Android JUnit Runner
androidTestCompile 'com.android.support.test:runner:0.5'
// JUnit4 Rules
androidTestCompile 'com.android.support.test:rules:0.5'
}

Should I updater the test runners? This is giving me a headache.

Thanks,

Theo.

解决方案

Espresso has transitive dependencies that cause those problems. You can just exclude all dependencies to the group com.android.support from your androidTest dependencies:

// Exclude Espresso's transitive dependencies to all packages in group com.android.support
configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
    androidTestCompileDependency.exclude group: 'com.android.support'
}

You should use Espresso 2.2.2! A complete example:

dependencies {

    def espressoVersion = '2.2.2'
    def testRunnerVersion = '0.5'

    androidTestCompile "com.android.support.test:runner:${testRunnerVersion}"
    androidTestCompile "com.android.support.test:rules:${testRunnerVersion}"
    androidTestCompile "com.android.support.test.espresso:espresso-core:${espressoVersion}"
    androidTestCompile "com.android.support.test.espresso:espresso-contrib:${espressoVersion}"
    androidTestCompile "com.android.support.test.espresso:espresso-intents:${espressoVersion}"

    configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
        androidTestCompileDependency.exclude group: 'com.android.support'
    }
}

这篇关于Android版本24.0.0和Espresso 2.0 gradle异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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