Reputation: 12963
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"
Upvotes: 48
Views: 75334
Reputation: 11
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'
})
Upvotes: 1
Reputation: 626
remove test dependency from build.gradel file for resolving the issues
Upvotes: 0
Reputation: 1055
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'}
Upvotes: 0
Reputation: 416
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!
Upvotes: 4
Reputation: 1
Open Android Studio
Navigate to Project > Gradle Scripts > build.gradle (Module:app)
Add dependencies {androidTestCompile 'com.android.support:support-annotations:xx.x.x'}
You can replace xx.x.x to version which is showing in an error
Save Gradle script
Build Project
Hope this will work! :)
Upvotes: 0
Reputation: 12963
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.
Upvotes: 102
Reputation: 10462
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}"
}
Upvotes: 1
Reputation: 2144
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'
}
Upvotes: 20
Reputation: 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"
}
Upvotes: -1
Reputation: 4084
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
Upvotes: 3
Reputation: 687
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.
Upvotes: 50
Reputation: 3520
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'
}
Upvotes: 10