警告:与依赖关系的冲突“com.android.support:support-annotations”

前端之家收集整理的这篇文章主要介绍了警告:与依赖关系的冲突“com.android.support:support-annotations”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试了几乎每一个窍门在书中。

> ResolutionStrategy.force
>排除模块

但没有什么似乎工作,下面是我的build.gradle。我使用Gradle版本1.2.3。有人可以抛出我的代码什么可能是错误的。

我唯一没有尝试的是改变版本的Gradle。
这是一个非常基本的Espresso测试用例。谢谢!

apply plugin: 'com.android.application'
android {
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
    }
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.rasika.job"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(dir: 'libs',include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'

    testCompile 'junit:junit:4.12'

    androidTestCompile 'com.android.support.test:runner:0.3'
    androidTestCompile 'com.android.support.test:rules:0.3'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
我分叉 android-topeka google sample和更新的appcompat版本为23.1.0,同样的消息:

Warning:Conflict with dependency
‘com.android.support:support-annotations’. Resolved versions for app
(23.1.0) and test app (23.0.1) differ.

我补充说:

androidTestCompile 'com.android.support:support-annotations:23.1.0'

现在都解决到23.1.0,警告消失了,应用程序和测试仍然工作。

我不确定这是更好的解决方案,所以我正在寻找另一个,但发现了你的问题。

更新:阅读this good explanation by PaulR

Update2:确认,android-testing google sample

// Testing-only dependencies
// 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.0.1'

Update3:Another good response by CommonsWare

使用以下方法检查您的特定版本/冲突/

./gradlew -q yourmodule:dependencies

Appcompat是22.1.1在你的情况,但你强迫22.1.0。

更新4:
依赖冲突解释在The Android Build System (Android Dev Summit 2015)

Resolving conflicts between main and test APK

When instrumentation tests are run,both the main APK and test APK
share the same classpath. Gradle build will fail if the main APK and
the test APK use the same library (e.g. Guava) but in different
versions. If gradle didn’t catch that,your app could behave
differently during tests and during normal run (including crashing in
one of the cases).

To make the build succeed,just make sure both APKs use the same
version. If the error is about an indirect dependency (a library you
didn’t mention in your build.gradle),just add a dependency for the
newer version to the configuration
(“compile” or “androidTestCompile”)
that needs it. You can also use Gradle’s resolution strategy mechanism. You can inspect the dependency tree by running ./gradlew :app:dependencies and ./gradlew :app:androidDependencies.

原文链接:https://www.f2er.com/javaschema/282534.html

猜你在找的设计模式相关文章