gradle force build tools version on third party libraries?

The lack easy way to do it is beyond my understanding. Tons of people use library projects that they don’t own, have to build with Jenkins or have other reasons not to touch them and don’t want to fork them for personal use.

Anyway, I found a solution here.

Will copy it here just in case:

In you root build.gradle add

ext {
    compileSdkVersion = 20
    buildToolsVersion = "20.0.0"
}
subprojects { subproject ->
    afterEvaluate{
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

This will apply compileSdkVersion and buildToolsVersion to any android modules you have.

And in your main project’s build.gradle change dependencies to this:

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

Basically you are defining them once and could use from anywhere.

Cheers.

Leave a Comment