All com.android.support libraries must use the exact same version [duplicate]

To elaborate on the accepted answer, proper dependency resolution for the support library case is as follows:

Don’t just add transitive dependencies as direct dependencies to force their versions; this is semantically the wrong thing to do (if you ever remove the dependency that brought in the transitive dependency, you now have a leftover dependency you’re not actually using).

Do the following:

In your root build.gradle, you should already have

ext {
    supportlib_version = '27.1.1'
    ...
}

and be using this property in your e.g. app/build.gradle like

dependencies {
    implementation "com.android.support:appcompat-v7:$supportlib_version"
    implementation "com.android.support:recyclerview-v7:$supportlib_version"
    ...
}

Now, in your root build.gradle, have

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "$supportlib_version"
            }
        }
    }
}

that is, in every module and every configuration, when resolving dependencies, if it’s a support lib (but not the multidex ones (there may be more exceptions)), force the version to your standardized support lib version.


Now in the age of jetpack and jetifier, it appears prudent to employ a variation (assuming you have migrated to the androidx versions):

Your e.g. app/build.gradle will now contain androidx dependencies, but libraries you use may still transitively pull in supportlib dependencies, which you still want on the same version (namely, 28.0.0) so that they can get properly jetified at build time.

So keep the root build.gradle parts as is, using 28.0.0 for the supportlib_version.

Leave a Comment