For example, there is a dependency in build.gradle
:
androidTestCompile 'com.android.support:support-annotations:25.3.1'
Gradle show conflict when sync:
Conflict with dependency 'com.android.support:support-annotations' in project ':demo'. Resolved versions for app (27.0.0) and test app (25.3.1) differ
According to:
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).
To make the build succeed, just make sure both APKs use the same version.
If the error is about an indirect dependency (a library you didn't mention in your build.gradle),
just add a dependency for the newer version to the configuration ("compile" or "androidTestCompile") that needs it.
You can also use Gradle's resolution strategy mechanism.
You can inspect the dependency tree by running ./gradlew :app:dependencies and ./gradlew :app:androidDependencies.
So modify it:
androidTestCompile 'com.android.support:support-annotations:27.0.0'
Meanwhile, Android Studio shows an error message when I try to run a project, it tells me Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (23.1.1) and test app (27.1.1) differ.
.
But as a matter of fact, in build.gradle
, only androidTestImplementation 'com.android.support:support-annotations:23.1.1'
is used.
$ ./gradlew androidDependencies | grep --color -E '^|com.android.support:support-annotations'
:app:androidDependencies
debug
debugCompileClasspath - Dependencies for compilation
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- com.android.support:support-v4:23.1.1@aar
\--- com.android.support:support-annotations:23.1.1@jar
debugRuntimeClasspath - Dependencies for runtime/packaging
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- com.android.support:support-v4:23.1.1@aar
\--- com.android.support:support-annotations:23.1.1@jar
debugAndroidTest
debugAndroidTestCompileClasspath - Dependencies for compilation
+--- com.android.support.test.espresso:espresso-core:3.0.2@aar
+--- com.android.support.test:runner:1.0.2@aar
+--- com.android.support.test.uiautomator:uiautomator-v18:2.1.2@aar
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- com.android.support:support-v4:23.1.1@aar
+--- com.android.support.test:monitor:1.0.2@aar
+--- com.android.support:support-annotations:27.1.1@jar
+--- junit:junit:4.12@jar
+--- com.android.support.test.espresso:espresso-idling-resource:3.0.2@aar
+--- com.squareup:javawriter:2.1.1@jar
+--- javax.inject:javax.inject:1@jar
+--- org.hamcrest:hamcrest-integration:1.3@jar
+--- org.hamcrest:hamcrest-library:1.3@jar
+--- com.google.code.findbugs:jsr305:2.0.1@jar
+--- org.hamcrest:hamcrest-core:1.3@jar
\--- net.sf.kxml:kxml2:2.3.0@jar
debugAndroidTestRuntimeClasspath - Dependencies for runtime/packaging
+--- com.android.support.test.espresso:espresso-core:3.0.2@aar
+--- com.android.support.test:runner:1.0.2@aar
+--- com.android.support.test.uiautomator:uiautomator-v18:2.1.2@aar
+--- com.android.support.test:monitor:1.0.2@aar
+--- com.android.support:support-annotations:27.1.1@jar
+--- junit:junit:4.12@jar
+--- com.android.support.test.espresso:espresso-idling-resource:3.0.2@aar
+--- com.squareup:javawriter:2.1.1@jar
+--- javax.inject:javax.inject:1@jar
+--- org.hamcrest:hamcrest-integration:1.3@jar
+--- org.hamcrest:hamcrest-library:1.3@jar
+--- com.google.code.findbugs:jsr305:2.0.1@jar
+--- org.hamcrest:hamcrest-core:1.3@jar
\--- net.sf.kxml:kxml2:2.3.0@jar
debugUnitTest
debugUnitTestCompileClasspath - Dependencies for compilation
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- junit:junit:4.12@jar
+--- com.android.support:support-v4:23.1.1@aar
+--- org.hamcrest:hamcrest-core:1.3@jar
\--- com.android.support:support-annotations:23.1.1@jar
debugUnitTestRuntimeClasspath - Dependencies for runtime/packaging
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- junit:junit:4.12@jar
+--- com.android.support:support-v4:23.1.1@aar
+--- org.hamcrest:hamcrest-core:1.3@jar
\--- com.android.support:support-annotations:23.1.1@jar
release
releaseCompileClasspath - Dependencies for compilation
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- com.android.support:support-v4:23.1.1@aar
\--- com.android.support:support-annotations:23.1.1@jar
releaseRuntimeClasspath - Dependencies for runtime/packaging
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- com.android.support:support-v4:23.1.1@aar
\--- com.android.support:support-annotations:23.1.1@jar
releaseUnitTest
releaseUnitTestCompileClasspath - Dependencies for compilation
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- junit:junit:4.12@jar
+--- com.android.support:support-v4:23.1.1@aar
+--- org.hamcrest:hamcrest-core:1.3@jar
\--- com.android.support:support-annotations:23.1.1@jar
releaseUnitTestRuntimeClasspath - Dependencies for runtime/packaging
+--- com.android.support:appcompat-v7:23.1.1@aar
+--- junit:junit:4.12@jar
+--- com.android.support:support-v4:23.1.1@aar
+--- org.hamcrest:hamcrest-core:1.3@jar
\--- com.android.support:support-annotations:23.1.1@jar
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 6s
1 actionable task: 1 executed
And indeed there were two version of com.android.support:support-annotations
.
In project directory, External Libraries
, can find two different versions of the lib.
Since I use compileSdkVersion 23
, so delete 27.1.1
.
Right click on Gradle:com.android.support:support-annotations:27.1.1@jar
, click >
to unfold, choose support-annotations-27.1.1.jar
, right click, choose Delete
.
But this method failed.
Even if the 27.1.1
is deleted, when sync project, it will be automatically downloaded again!!!
A possible but maybe not best resolution:
Add the following code snippet:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.1'
}
android {
compileSdkVersion 23
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.syna.jk.youtubeinchrome"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.1'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:23.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestImplementation 'com.android.support:support-annotations:23.1.1'
}