Auto-detect Android build-tools version

Use <android build-tools-version="" /> to specify a version in project xml.
This commit is contained in:
Justin Espedal
2017-04-05 15:22:39 -07:00
committed by Joshua Granick
parent 4373726efb
commit f31b29fc3c
4 changed files with 67 additions and 1 deletions

View File

@@ -1852,6 +1852,10 @@ class ProjectXMLParser extends HXProject {
case "target-sdk-version":
config.set ("android.target-sdk-version", Std.parseInt (value));
case "build-tools-version":
config.set ("android.build-tools-version", value);
case "install-location":

View File

@@ -71,6 +71,61 @@ class AndroidHelper {
}
public static function getBuildToolsVersion (project:HXProject):String {
var buildToolsPath = project.environment.get ("ANDROID_SDK") + "/build-tools/";
var version = ~/^(\d+)\.(\d+)\.(\d+)$/i;
var current = { major : 0, minor : 0, micro : 0 };
for (buildTool in FileSystem.readDirectory (buildToolsPath)) {
//gradle only likes simple version numbers (x.y.z)
if (!version.match (buildTool)) {
continue;
}
var newVersion = {
major: Std.parseInt (version.matched (1)),
minor: Std.parseInt (version.matched (2)),
micro: Std.parseInt (version.matched (3))
};
if (newVersion.major != current.major) {
if (newVersion.major > current.major) {
current = newVersion;
}
} else if (newVersion.minor != current.minor) {
if (newVersion.minor > current.minor) {
current = newVersion;
}
} else {
if (newVersion.micro > current.micro) {
current = newVersion;
}
}
}
return '${current.major}.${current.minor}.${current.micro}';
}
public static function getDeviceSDKVersion (deviceID:String):Int {

View File

@@ -321,6 +321,7 @@ class AndroidPlatform extends PlatformTarget {
context.ANDROID_INSTALL_LOCATION = project.config.getString ("android.install-location", "auto");
context.ANDROID_MINIMUM_SDK_VERSION = project.config.getInt ("android.minimum-sdk-version", 9);
context.ANDROID_TARGET_SDK_VERSION = project.config.getInt ("android.target-sdk-version", 19);
context.ANDROID_BUILD_TOOLS_VERSION = project.config.getString ("android.build-tools-version");
context.ANDROID_EXTENSIONS = project.config.getArrayString ("android.extension");
context.ANDROID_PERMISSIONS = project.config.getArrayString ("android.permission", [ "android.permission.WAKE_LOCK", "android.permission.INTERNET", "android.permission.VIBRATE", "android.permission.ACCESS_NETWORK_STATE" ]);
context.ANDROID_GRADLE_VERSION = project.config.getString ("android.gradle-version", "2.10");
@@ -344,6 +345,12 @@ class AndroidPlatform extends PlatformTarget {
Sys.exit (1);
}
if (context.ANDROID_BUILD_TOOLS_VERSION == "") {
context.ANDROID_BUILD_TOOLS_VERSION = AndroidHelper.getBuildToolsVersion (project);
}
var escaped = ~/([ #!=\\:])/g;
context.ANDROID_SDK_ESCAPED = escaped.replace(context.ENV_ANDROID_SDK, "\\$1");

View File

@@ -19,7 +19,7 @@ VERSION_CODE=::META_BUILD_NUMBER::
ANDROID_BUILD_TARGET_SDK_VERSION=::ANDROID_TARGET_SDK_VERSION::
ANDROID_BUILD_MIN_SDK_VERSION=::ANDROID_MINIMUM_SDK_VERSION::
ANDROID_BUILD_SDK_VERSION=::ANDROID_TARGET_SDK_VERSION::
ANDROID_BUILD_TOOLS_VERSION=24.0.1
ANDROID_BUILD_TOOLS_VERSION=::ANDROID_BUILD_TOOLS_VERSION::
::if KEY_STORE::
KEY_STORE=::KEY_STORE::