From b6df36fc392735d318c2cda04fcb994330ea56ea Mon Sep 17 00:00:00 2001 From: Deve Date: Sun, 6 Aug 2017 23:15:08 +0200 Subject: [PATCH] Don't hardcode build-tools version --- android/README.ANDROID | 12 ++++++------ android/build.gradle | 4 ++-- android/make.sh | 26 ++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/android/README.ANDROID b/android/README.ANDROID index d0d0bc48f..bd8793919 100644 --- a/android/README.ANDROID +++ b/android/README.ANDROID @@ -48,9 +48,8 @@ Android NDK r12b. You need to create proper "android-sdk" and "android-ndk" symlinks in the directory with Android project, so that the compilation script will have access -to the SDK and NDK. - -These paths can be also set in SDK_PATH and NDK_PATH environmental variables. +to the SDK and NDK. These paths can be also set in SDK_PATH and NDK_PATH +environmental variables. Before running the compilation, run the generate_assets script, so that selected assets will be copied to "assets" directory, and then included in the @@ -78,9 +77,10 @@ you have to manually sign the apk with your key and run zipalign. Additionally you can choose the build tool by setting BUILD_TOOL environment variable to "gradle" or "ant". Note that ant has been already removed from Android SDK, so you have to use SDK <= 25.2.5 for building with ant. By default -the BUILD_TOOL is set to "gradle". It has hardcoded version of SDK build-tools -that are set to "25.0.3", so you have to use this particular version (or you can -edit build.gradle file). +the BUILD_TOOL is set to "gradle". + +You can override the SDK build-tools version by setting the BUILD_TOOLS_VER +environment variable. Basically if all dependencies are installed in the system, it should be enough to just run: diff --git a/android/build.gradle b/android/build.gradle index c1b35396d..4fae7a216 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -15,8 +15,8 @@ apply plugin: 'com.android.application' android { - compileSdkVersion sdkVersion.toInteger() - buildToolsVersion "25.0.3" + compileSdkVersion sdk_version.toInteger() + buildToolsVersion build_tools_ver sourceSets { diff --git a/android/make.sh b/android/make.sh index cd394e892..401c3aefc 100755 --- a/android/make.sh +++ b/android/make.sh @@ -155,6 +155,24 @@ if [ ! -d "$SDK_PATH" ]; then exit fi +# Find newest build-tools version +if [ -z "$BUILD_TOOLS_VER" ]; then + BUILD_TOOLS_DIRS=`ls -1 "$SDK_PATH/build-tools" | sort -V -r` + + for DIR in $BUILD_TOOLS_DIRS; do + if [ "$DIR" = `echo $DIR | sed 's/[^0-9,.]//g'` ]; then + BUILD_TOOLS_VER="$DIR" + break + fi + done +fi + +if [ -z "$BUILD_TOOLS_VER" ] || [ ! -d "$SDK_PATH/build-tools/$BUILD_TOOLS_VER" ]; then + echo "Error: Couldn't detect build-tools version." + exit +fi + + # Standalone toolchain if [ ! -f "$DIRNAME/obj/make_standalone_toolchain.stamp" ]; then echo "Creating standalone toolchain" @@ -326,9 +344,13 @@ echo "Building APK" if [ "$BUILD_TOOL" = "gradle" ]; then export ANDROID_HOME="$SDK_PATH" - gradle -PsdkVersion=$SDK_VERSION $GRADLE_BUILD_TYPE + gradle -Psdk_version=$SDK_VERSION \ + -Pbuild_tools_ver="$BUILD_TOOLS_VER" \ + $GRADLE_BUILD_TYPE elif [ "$BUILD_TOOL" = "ant" ]; then - ant $ANT_BUILD_TYPE -Dsdk.dir="$SDK_PATH" -Dtarget=$NDK_PLATFORM + ant -Dsdk.dir="$SDK_PATH" \ + -Dtarget=$NDK_PLATFORM \ + $ANT_BUILD_TYPE fi check_error