Android Espresso Framework Resolved versions for app (25.3.1) and test app (23.1.1) 错误

Android Espresso Framework Resolved versions for app (25.3.1) and test app (23.1.1) Error

当我尝试通过 gradle 添加 espresso 库时收到此错误消息。我该如何解决?

问题是 espresso 使用的支持库版本比你的要旧。由于您的项目中已经有 then,因此请将它们从 espresso 中排除。 因此,在您的 build.gradle 文件中,您应该替换:

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

与:

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

如果您有更多冲突,请尝试排除更多支持模块(如 appcompat、设计等)。

使用此代码测试像 recyclerview 这样的操作

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2', {

    exclude group: 'com.android.support', module: 'appcompact'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude module: 'recyclerview-v7'
})

否则使用

compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'appcompact'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
    })