I would like to specify a range of possible android build tool versions to Gradle.
Is it possible to use + when specifying buildToolsVersion in build.gradle?
Something like buildToolsVersion 23+
?
Or a range like it's possible with compile dependencies:
compile group: 'log4j', name: 'log4j', version: '[1.2.12,1.2.17]'
buildToolsVersion is the version of the compilers (aapt, dx, renderscript compiler, etc...) that you want to use. For each API level (starting with 18), there is a matching . 0.0 version. At IO 2014, we release API 20 and build-tools 20.0.
For the compileSdkVersion you can goto Tools > Android > SDK Manager . This will pull up a window that will allow you to manage your compileSdkVersion and your buildToolsVersion . You can also select the link at the bottom left (Launch Standalone SDK Manager) this will give you a little bit more information.
Android SDK Build-Tools — 32.0. 0.
Good question.
Yes! It's possible. My answer heavily uses this snippet: https://github.com/aayvazyan-tgm/autodetect_android_sdk_and_buildTools/blob/master/sdktools.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion getBuildVersionFromRange("23.0.2", "25.1.3")
...
}
.......
//
// get the installed SDK and build tools version
// based on: http://www.egeek.me/2013/12/07/gradle-auto-detect-android-sdk-and-build-tools-versions/
// modified by Ari Ayvazyan
import org.codehaus.groovy.runtime.StackTraceUtils
public String androidSDKDir() {
def sdkDir = android.getSdkDirectory().toString()
return sdkDir
}
public String[] buildToolsAvailable() {
println "sdk dir: " + androidSDKDir()
def buildToolsDir = new File(androidSDKDir(), "build-tools")
String[] collection = buildToolsDir.list([accept:{ d, f-> !f.contains("android") }] as FilenameFilter)
for (int i = 0; i < collection.length; i++) {
String s = collection[i]
collection[i]=s.replace("build-tools-","")
}
collection.sort { a, b -> b <=> a }
}
public String getBuildVersionFromRange(String defaultBuildTools, String maxBuildTools) {
def buildToolsVersions = buildToolsAvailable()
List maxBuild = maxBuildTools.tokenize('.')
for (int i = 0; i < buildToolsVersions.length; i++) {
def buildToolsToCheck = buildToolsVersions[i]
List currentBuild = buildToolsToCheck.tokenize('.')
boolean isPassing = true;
for (int j = 0; j < maxBuild.size(); j++) {
if (maxBuild.get(j) < currentBuild.get(j)) {
isPassing = false;
break;
}
}
if (isPassing) {
return buildToolsToCheck;
}
}
return defaultBuildTools;
}
import org.apache.tools.ant.taskdefs.condition.Os
public boolean isWindows() {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return true
}
return false
}
The code of getBuildVersionFromRange
can be improved, of course. For example, now, the first parameter is a fallback value, but it can be rewritten to be the bottom border of the range, for example.
I hope, it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With