Reputation: 310
I receive this warning:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 27.1.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:exifinterface:27.1.
I understand this, but why is this warning shown to me even though all the com.android.support versions are the same? (27.1.1)
this is the content of my file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.app.sin.retrolist"
minSdkVersion 18
targetSdkVersion 27
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:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.squareup.picasso:picasso:2.71828' }
Upvotes: 3
Views: 808
Reputation: 1951
To see why a specific dependency is included in your dependency tree, you can (assuming that your main module is named app
and you are on macOS) run a simple:
./gradlew app:dependencies
In the console output, you will see the full dependency tree and how library versions are resolved.
The proper way to deal with dependencies conflicts like this is to explicity define a resolution strategy:
configurations.all {
resolutionStrategy {
force 'com.android.support:exifinterface:27.1.1'
}
}
This must be placed in the root of your build.gradle
file in the app
module.
Overriding the conflicting dependency with:
dependencies {
...
implementation 'com.android.support:exifinterface:27.1.1'
}
is less correct, as your module doesn't directly depends on this library so, if for example future versions of your dependencies won't depend on it anymore, it will still be included in the list of resolved dependencies even if you don't need it.
Even better, you could define:
ext {
supportLibVersion = "27.1.1"
}
in your main build.gradle
file, and then use it wherever you need it:
configurations.all {
resolutionStrategy {
force "com.android.support:exifinterface:$rootProject.supportLibVersion"
}
}
dependencies {
...
implementation "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
implementation "com.android.support:recyclerview-v7:$rootProject.supportLibVersion"
implementation "com.android.support:cardview-v7:$rootProject.supportLibVersion"
...
}
Upvotes: 2