Android Support Repo 46.0.0 with Android Studio 2.3

What’s the problem

Some libraries depend on version “X or newer” of Android support libraries so Gradle dependency resolution grabs whatever is the newest available ignoring you actually have a precise version specified in your dependencies block.

This is not what you want. You want all support libraries with same version and major version has to match compile SDK version.

What’s the solution

Fortunately you can force a specific support library version.

Put this at the end of your app module build.gradle:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            // Skip multidex because it follows a different versioning pattern.
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}

Of course replace the version with whatever it is you’re using.

Version values for support libraries in dependecies block are now irrelevant.

If you have doubts

This is a well documented method and it’s working.

What can you do to help

Find the libraries which depend on a range of support library versions

gradlew dependencies --configuration compile -p <module name> | grep ,

and let the authors of said libraries know they should transitively depend on the oldest support libs their library can do with.

This aims to avoid the issue altogether.

Leave a Comment