Warning:Conflict with dependency 'com.android.support:support-annotations' Warning:Conflict with dependency 'com.android.support:support-annotations' android android

Warning:Conflict with dependency 'com.android.support:support-annotations'


I forked android-topeka google sample and updated appcompat version to 23.1.0, same message:

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

I added:

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

Now both resolve to 23.1.0, the warning is gone, and the app and tests still work.

I'm not sure that it's the better solution, so I'm searching for another but found your question.

Update: Read this good explanation by PaulR.

Update2: Confirmed, android-testing google sample does it.

// 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.

Check your specific versions/conflicts/resolutions using:

./gradlew -q yourmodule:dependencies

enter image description here

Appcompat is 22.1.1 in your case but you are forcing 22.1.0.

Update4:Dependency conflict explained at The Android Build System (Android Dev Summit 2015).

enter image description here

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.


I solved the conflict by adding dependency:

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


I had the same issue, solved by this:

// build.gradle...android {    ...    defaultConfig {        ...        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }}dependencies {    ...    androidTestCompile('com.android.support.test.espresso:espresso-core: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.3') {        // Necessary if your app targets Marshmallow (since the test runner        // hasn't moved to Marshmallow yet)        exclude group: 'com.android.support', module: 'support-annotations'    }}

solution was found here:https://github.com/codepath/android_guides/wiki/UI-Testing-with-Espresso

UPDATE:finally dependencies block in my build.gradle looks like this:

dependencies {    ...            compile 'com.android.support:appcompat-v7:23.2.1'    compile 'com.android.support:support-v4:23.2.1'    compile 'com.android.support:design:23.2.1'    ...         // Necessary if your app targets Marshmallow (since Espresso    // hasn't moved to Marshmallow yet)    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {        exclude group: 'com.android.support'    }    androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2') {        exclude group: 'com.android.support'    }    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'    }    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {        exclude group: 'com.android.support'    }    androidTestCompile('com.android.support:support-annotations:23.2.1') {        exclude group: 'com.android.support'    }    androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.2') {        exclude group: 'com.android.support'    }}