androidgradleanko

How to solve "All com.android.support libraries must use the exact same version specification" issue?


Specifically, how to solve the issue if the plugin that has the problem is already the latest?

I'm new to Android programming, and definitely new to Gradle concept. This issue arises after I followed some tutorial on the internet that instructs to add new dependencies into the main app.

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.1.1. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:support-media-compat:27.1.1

But I don't have stated dependency that says "support-media-compat:27.1.1". So I figured this must be one of the plugin I use. The problem is, how am I supposed to know which plugin causes this?

After a lengthy googling and getting tons of red herrings, I found out that you can straight up expands the dependency tree using gradle command in the console:

./gradlew app:dependencies

Which then led me found this:

+--- org.jetbrains.anko:anko:0.10.8
....
|    +--- org.jetbrains.anko:anko-appcompat-v7:0.10.8
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.21 (*)
|    |    +--- com.android.support:appcompat-v7:27.1.1 -> 28.0.0 (*)
|    |    +--- org.jetbrains.anko:anko-support-v4:0.10.8
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.21 (*)
|    |    |    +--- com.android.support:support-v4:27.1.1
|    |    |    |    +--- com.android.support:support-compat:27.1.1 -> 28.0.0 (*)
|    |    |    |    +--- com.android.support:support-media-compat:27.1.1    <-----
|    |    |    |    |    +--- com.android.support:support-annotations:27.1.1 -> 28.0.0
|    |    |    |    |    \--- com.android.support:support-compat:27.1.1 -> 28.0.0 (*)
|    |    |    |    +--- com.android.support:support-core-utils:27.1.1 -> 28.0.0 (*)
|    |    |    |    +--- com.android.support:support-core-ui:27.1.1 -> 28.0.0 (*)
|    |    |    |    \--- com.android.support:support-fragment:27.1.1 -> 28.0.0 (*)
....

Now I know that it's because anko:0.10.8. I did remember that this issue started to arise after I added the anko plugin. From answers I read earlier, usually the solution is to use the latest version of the plugin. But when I see the plugin version, the latest is already 0.10.8. So I'm confused about what to do next.

This is my dependencies by the way:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    implementation 'com.github.StevenDXC:DxLoadingButton:2.2'

    implementation 'com.thoughtbot:expandablerecyclerview:1.3'

    implementation "com.squareup.retrofit2:retrofit:2.3.0"
    implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
    implementation "com.squareup.retrofit2:converter-gson:2.3.0"

    implementation "io.reactivex.rxjava2:rxandroid:2.0.1"

    implementation "org.jetbrains.anko:anko:$anko_version"

    implementation 'com.google.firebase:firebase-core:16.0.9'
}

apply plugin: 'com.google.gms.google-services'

I have also tried the solution to downgrade the appcompat to 27.1.1 instead, and that requires me to also downgrade the android compileSdkVersion to 27. But even after change all that, that leads to even more version incompatibility with other plugins.

How can I resolve this, and still using anko plugins?


Solution

  • You need to add the conflicting dependencies with the latest version in your app/build.gradle.

    So, if it tell you that some library is using com.android.support:support-media-compat:27.1.1, then you need to add that dependency in your app/build.gradle with the latest version that you're using, i.e. in your case, com.android.support:support-media-compat:28.0.0

    Keep doing this, until all the dependencies in your app are using the latest version.