Gradle Force build version for third-party libraries?

How to make the library use the sdk build tools 19.1.0 or higher without overlaying / manually editing the build.gradle file for the library?

I keep getting this error when using libraries ...

Error:The SDK Build Tools revision (.......) is too low for project ':somelibrary'. Minimum required is 19.1.0 
+12
android android-gradle gradle
source share
2 answers

The hard way to do this is not in my understanding. Tons of people use library projects that they don’t own, must build with Jenkins or have other reasons not to touch them and don’t want to shell them out for personal use.

Anyway, I found a solution here .

Copy it here just in case:

You have 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 of your Android modules.

And in your main build.gradle project, the dependencies on this change:

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

You basically define them once and can use them from anywhere.

Greetings.

+41
source share

If you want to update the values ​​of compileSdkVersion and buildToolsVersion only when the value of buildToolsVersion too small, you can first compare the version number of the subproject and update only if necessary. This way, you make minimal changes to other projects and have fewer projects to check if something goes wrong.

So, let's say that Android Studio tells you that you need the minimum version of the build tools 25.0.0 , then in your root build.gradle , here is how you will check each buildToolsVersion subproject and change it only if it is less than 25.0.0 :

 subprojects { afterEvaluate {project -> if (project.hasProperty("android") && VersionNumber.parse(project.property("android").buildToolsVersion) < VersionNumber.parse("25.0.0")) { android { compileSdkVersion 25 buildToolsVersion '25.0.0' } } } } 
+3
source share

All Articles