Gradle To Force Dependencency Library Version

May 18, 2018

You might be using 3rd party library who are using a different version of android support library. Use the following configuration to force all dependency libraries to use the same version.

Edit project’s build.gradle.

buildscript {
    ext {
        android_support_library_version = '27.1.1'
    }

    ...
}

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

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.