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

What I did to solve it was add the below line in to my build.gradle script

androidTestCompile 'com.android.support:support-annotations:xx.x.x'

Replace xx.x.x with whatever version of support-annotations your app is using - this will be shown in your dependencies, or the Gradle sync message as: Resolved version for app (xx.x.x) should there be a problem syncing.


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.


Actually it's a bug of new update version of Espresso Contrib, you can refer this workaround : android-testing/build.gradle

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