21

I came across this exception while adding espresso to an android project. I already try the link that comes with this exception

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

also I add the following line according to other thread I found

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

But the problem still persist. I am using the following configurations:

buildToolsVersion "23.0.2"

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

Any ideas, thanks.

axcellinx
  • 296
  • 1
  • 2
  • 5

6 Answers6

39

This solve the problem 'Resolved versions for app (24.0.0-beta1) and test app (23.0.1) differ' for me.

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

And do not forget to add following code, if you want to run the AndroidTest

 defaultConfig {
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
liushan CHEN
  • 801
  • 8
  • 11
15
dependencies {
    //...

    // Solves "versions for app (23.3.0) and test app (23.1.1) differ"
    androidTestCompile 'com.android.support:support-annotations:23.3.0'

    // Android JUnit Runner
    androidTestCompile 'com.android.support.test:runner:0.5'
    // JUnit4 Rules
    androidTestCompile 'com.android.support.test:rules:0.5'
}
Mike Mitterer
  • 6,810
  • 4
  • 41
  • 62
  • probably about another library? add all com.android.support... libraries there for androidTestCompile – Frank Jul 25 '16 at 09:49
  • 1
    Thanks... androidTestCompile 'com.android.support:support-annotations:XX.XX.XX' your app version – Pierry Aug 31 '16 at 13:43
  • Gradle is building fine but it shows error for androidTestCompile 'com.android.support.test:rules:0.5' For Different version of support library versions – Nilay Dani Dec 22 '16 at 11:06
8

Nowadays when you create a new project on Android Studio, it adds this dependency by default:

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

The exclude section is probably to avoid the conflict mentioned in the question. I also faced this issue when trying to add runner:0.5 and rules:0.5 dependencies. My solution was to apply the same piece of code above on them:

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

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

It works for me. Hope it helps.

Mateus Gondim
  • 5,362
  • 6
  • 31
  • 51
4

annotation library is used by all three dependancies rules:0.5', runner:05 and espresso-core:2.2.2, so following worked for me

androidTestCompile 'com.android.support.test:runner:0.5', {
    exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.android.support.test:rules:0.5', {
    exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
}
Anuj Jindal
  • 1,711
  • 15
  • 24
1

Rebuild project solved the issue.

In Android studio in the toolbar.. Build>Rebuild Project.

0
сompile 'com.android.support:support-annotations:23.3.0'
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'
}

It's a solution

Michael Gaev
  • 69
  • 1
  • 3
  • Why would this solve the problem? I don't get it. I tried it, and it doesn't solve anything. – IgorGanapolsky Jun 17 '16 at 21:08
  • My dependencies versions: androidGradleToolsVersion = '2.1.0' androidBuildToolsVersion = '23.0.2' androidSDKVersion = 23 androidSupportLibVersion = '23.3.0' try to change its. Or try to use latest versions. But I think you'll need to use piece of code above nonetheless. – Michael Gaev Jun 20 '16 at 11:40