Conflict with Dependency 'Com.Android.Support:Support-Annotations'. Resolved Versions for App (23.1.0) and Test App (23.0.1) Differ

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

You can force the annotation library in your test using:

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

Something like this:

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

Another solution is to use this in the top level file:

configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}

Resolved versions for app (22.0.0) and test app (21.0.3) differ

Step #1 when dealing with this sort of thing is to get comfortable with command-line Gradle.

Step #2 is to run the Gradle dependencies report (e.g., gradle -q app:dependencies from the project root). This will provide the ASCII tree as shown in the update to the question, and it should help you identify what is asking for the conflicting artifact versions.

Step #3 is to decide what needs replacing. You elected to replace just the conflict (support-annotations). Personally, I would have gone with the root of the wrong-version tree (recyclerview-v7), though for all I know that might not be the best course of action in this case.

Step #4 is to add the exclude directive to block what you chose in Step #3:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude module: 'support-annotations'
}

Step #5 is to test the heck out of this change. What you are doing is saying that espresso-contrib has to deal with the 22.0.0 edition of support-annotations. That may work. That may not. It depends on the backwards compatibility of the conflict. In this case, support-annotations should be pretty good about it.

Step #6 is to consume the beverage of your choice, one appropriate for your locale and time of day.

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

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'

refer to older version of supportAnnotations:

com.android.support:support-annotations:23.1.1

You have a few choices:

  1. Specifically declare suportAnnotations version for test compilation (to override any transitive dependencies):

    androidTestCompile 'com.android.support:support-annotations:25.0.1'
  2. Exlude it from those dependencies:

    androidTestCompile ('com.android.support.test:runner:0.5') {
    exclude module: 'support-annotations'
    }
    androidTestCompile ('com.android.support.test:rules:0.5') {
    exclude module: 'support-annotations'
    }

Error:Conflict with dependency 'com.android.support:support-v4' in project ':app'. Resolved versions for app (25.3.1) and test app (23.1.1) differ

This would solve your problem:

androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.google.code.findbugs'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'design'
exclude module: 'recyclerview-v7'
}

You need to just exclude every library you have already provided in build.gradle

Android support library error after updating to 23.3.0

For those people who are still facing this problem just add this line to your dependencies.

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

It solved my problem.

UPDATE:

If you have this error nowadays, you can just insert the new versioncode (23.3.0 in this case, or 27.1.1 in May '18) as it is described in the error into the above described solution.



Related Topics



Leave a reply



Submit