与依赖'com.android.support:support-annotations'冲突。 应用程序(23.1.0)和testing应用程序(23.0.1)的已解决版本不同
build设时,我得到以下错误:
Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ.
这些是我的gradle依赖关系
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:support-v4:23.1.0' compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:design:23.1.0' compile 'com.android.support:cardview-v7:23.1.0' compile 'com.android.support:recyclerview-v7:23.1.0' compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.squareup:otto:1.3.8' compile 'com.snappydb:snappydb-lib:0.5.2' compile 'com.esotericsoftware.kryo:kryo:2.24.0' compile 'com.google.dagger:dagger:2.0.1' apt 'com.google.dagger:dagger-compiler:2.0.1' compile 'javax.annotation:javax.annotation-api:1.2' compile 'io.reactivex:rxandroid:1.0.1' compile 'io.reactivex:rxjava:1.0.14' compile 'com.google.android.gms:play-services-location:8.1.0' compile 'com.google.android.gms:play-services-gcm:8.1.0' compile 'org.apache.commons:commons-lang3:3.4' testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-library:1.3' testCompile 'org.mockito:mockito-core:1.10.19' androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' }
我怎样才能解决这个问题?
您可以使用以下命令在您的testing中强制注记库:
androidTestCompile 'com.android.support:support-annotations:23.1.0'
像这样的东西:
// Force usage of support annotations in the test app, since it is internally used by the runner module. androidTestCompile 'com.android.support:support-annotations:23.1.0' androidTestCompile 'com.android.support.test:runner:0.4.1' androidTestCompile 'com.android.support.test:rules:0.4.1' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'
另一个解决scheme是在顶层文件中使用它:
configurations.all { resolutionStrategy.force 'com.android.support:support-annotations:23.1.0' }
来源: CodePath – 用Espresso进行UItesting
- 最后,我们需要拉入Espresso依赖关系,并在我们的应用程序build.gradle中设置testing运行器:
// build.gradle ... android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { ... 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:runner:0.5') { // Necessary if your app targets Marshmallow (since the test runner // hasn't moved to Marshmallow yet) exclude group: 'com.android.support', module: 'support-annotations' } }
我已经添加到我的gradle文件,警告消失了。
另外,如果你得到了任何其他的依赖列表,如支持注释,请尝试从androidTestCompile依赖关系中排除它。
你可以尝试使用
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' })
代替
androidTestCompile 'com.android.support.test:runner:0.4.1' androidTestCompile 'com.android.support.test:rules:0.4.1' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'