我在向android项目添加espresso时遇到了这个异常。我已经尝试了这个异常附带的链接
**Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.3.0) and test app (23.1.1) differ**
我还根据我发现的的其他线程添加了以下行
**androidTestCompile 'com.android.support:support-annotations:23.1.0'**
但这个问题仍然存在。我使用以下配置:
buildToolsVersion "23.0.2"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
有什么想法,谢谢。
这为我解决了"应用程序(24.0.0-beta1)和测试应用程序(23.0.1)的解决版本不同"的问题。
android{
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.0.1'
}
}
如果你想运行AndroidTest ,不要忘记添加以下代码
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dependencies {
//...
// Solves "versions for app (23.3.0) and test app (23.1.1) differ"
androidTestCompile 'com.android.support:support-annotations:23.3.0'
// Android JUnit Runner
androidTestCompile 'com.android.support.test:runner:0.5'
// JUnit4 Rules
androidTestCompile 'com.android.support.test:rules:0.5'
}
如今,当你在Android Studio上创建一个新项目时,它默认会添加这个依赖项:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
exclude
部分可能是为了避免问题中提到的冲突。在尝试添加runner:0.5
和rules:0.5
依赖关系时,我也遇到了这个问题。我的解决方案是对它们应用上面相同的代码:
androidTestCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile ('com.android.support.test:rules:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
它对我有用。希望它能帮助我。
注释库被所有三个依赖规则使用:0.5',runner:05和espresso core:2.2.2,所以以下对我有效
androidTestCompile 'com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.android.support.test:rules:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
重建项目解决了这个问题。
在Android工作室的工具栏中。。"构建">"重建项目"。
сompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile ("com.android.support.test:runner:0.5"){
exclude group: 'com.android.support'
}
androidTestCompile ('com.android.support.test:rules:0.5'){
exclude group: 'com.android.support'
}
这是一个解决方案