48

I have been using android support v4 23.1.1 and recently tried to update it to 23.3.0 ( the latest one when this was asked) but I got the following error:

Error:Conflict with dependency 'com.android.support:support-annotations'.
Resolved versions for app (23.3.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details.

So far I have found this https://code.google.com/p/android/issues/detail?id=206137

I went to both the links but I could not fix my issue, how do I fix this issue?

Edit:

I have these in my dependencies

compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:design:23.3.0'

Previously all the versions were 23.1.1 and it worked fine the error occurred after updating

Edit:

Gradle Version 2.10
Gradle Plugin Version 2.0.0
buildToolsVersion "23.0.3"
JJD
  • 50,076
  • 60
  • 203
  • 339
Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64

13 Answers13

102

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.

Emanuel Graf
  • 756
  • 17
  • 37
Nongthonbam Tonthoi
  • 12,667
  • 7
  • 37
  • 64
  • 1
    Tried your solution but still facing error: `Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.` Gradle dependency: `androidTestCompile 'com.android.support:support-annotations:23.4.0'` Can you please suggest ? – Jaydev Jun 06 '16 at 08:06
  • 3
    Try adding androidTestCompile 'com.android.support:support-v4:23.4.0' – Nongthonbam Tonthoi Jun 06 '16 at 08:11
  • Still leaves me with `Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.4.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.`. But upon adding `androidTestCompile 'com.android.support:appcompat-v7:23.4.0'` results in errors within values.xml `Error:(72) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'. ...` – Jaydev Jun 06 '16 at 08:26
  • 3
    SO - Stack Overflow – Nongthonbam Tonthoi Jun 06 '16 at 09:01
  • Had to do the same to get my project to build since I upgraded to Android Studio 2.3. Thanks – Jérémy Mar 03 '17 at 15:18
50

For those who still facing the problem, above answer did not help me in android studio 2.2 Preview.

add this to your gradle file.

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

This fixed my issue.

Reference: https://github.com/JakeWharton/u2020/blob/05a57bf43b9b61f16d32cbe8717af77cd608b0fb/build.gradle#L136-L140

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
Ganesh Bhat
  • 687
  • 5
  • 5
20

Just exemplifying Akshayraj's answer

Original Gradle file:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    [...]

    compile 'com.android.support:support-annotations:25.3.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

}

Received error:

Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'.
Resolved versions for app (25.1.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details. "

FIXED when I added:

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

Final File:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    [...]

    compile 'com.android.support:support-annotations:25.3.0'

    androidTestCompile 'com.android.support:support-annotations:25.3.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
Punpuf
  • 2,042
  • 1
  • 19
  • 30
10

My orignal app.gradle had:

dependencies {
    // App dependencies
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0' 

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

which resulted in following error:
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (22.2.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

After reading the link suggested in error, I found theses lines:

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

So I modified my app.gradle dependencies to:

dependencies {
    // App dependencies
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'

    // Testing-only dependencies
    androidTestCompile 'com.android.support:support-annotations:23.3.0'
    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'
}

Even after the above change gradle was not happy :-(:
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.3.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

Change in test apk version was different! So I modified the version string as pasted below which worked for me:

(Nirvana)

dependencies {
    // App dependencies
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0' // main APK

    // Testing-only dependencies
    androidTestCompile 'com.android.support:support-annotations:23.4.0' //test APK
    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'
}
MANN
  • 3,360
  • 1
  • 17
  • 18
  • a decent example on android gradle usage --> https://github.com/JakeWharton/u2020/blob/master/build.gradle – MANN Jun 10 '16 at 21:52
  • Didn't work for me unfortunately, but I see how your answer works. +1 for the explanation. – rgv Oct 06 '16 at 21:59
4

Took me a while to get out of this error. But this is what has worked for me, give it a try:

NOTE: Am using compileSdkVersion 26

I removed both androidTestImplementation 'com.android.support.test:runner:1.0.2' & androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' in the dependencies block in build.gradle(Module: app). So I ended up with this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.date.brian.cradletest"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
   buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    compile 'com.getbase:floatingactionbutton:1.9.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    testImplementation 'junit:junit:4.12'
}

I hope this comes in handy!

Brian
  • 406
  • 1
  • 5
  • 8
3

You have to use the same version for app and androidTest APKs. To do this, specify the same version as your app,

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

where 24.1.1 is the version number of the dependency used in your app

ARK
  • 3,734
  • 3
  • 26
  • 29
2
compile 'com.android.support:design:24.1.1'
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

For me, The build tool version has to align with the dependency versions. So lets say the build tool version is 26.1.0, the Gradle dependency version has to obey it.

The simplest way is to create a version variable & use it. See the example below

ext {
    buildVersion = '26.1.0'
}

dependencies {
    compile "com.android.support:appcompat-v7:${buildVersion}"
}
Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
1

Just exclude 'annotations'. No harm will be done

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

  2. Navigate to Project > Gradle Scripts > build.gradle (Module:app)

  3. Add dependencies {androidTestCompile 'com.android.support:support-annotations:xx.x.x'}

  4. You can replace xx.x.x to version which is showing in an error

  5. Save Gradle script

  6. Build Project

Hope this will work! :)

0

It was solved after adding the last line:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.android.support:support-annotations:27.1.1'}
Akshay
  • 1,019
  • 12
  • 21
0

remove test dependency from build.gradel file for resolving the issues

rakesh rajput
  • 606
  • 4
  • 5
-1
/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
    resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
}
Dev-iL
  • 23,742
  • 7
  • 57
  • 99
  • While this code may answer the question, providing additional [context](https://meta.stackexchange.com/q/114762) regarding _how_ and/or _why_ it solves the problem would improve the answer's long-term value. It also doesn't hurt to mention why this answer is more appropriate than others. – Dev-iL Mar 21 '17 at 09:30