Bug 1204260 - Pin Android package versions to android-22 and build-tools-22.0.1. r?glandium draft
authorNick Alexander <nalexander@mozilla.com>
Sat, 12 Sep 2015 15:04:19 -0400
changeset 292542 dff9020e68ce7a4d9117c802c0985218ed6a9d64
parent 292541 015b7b8435c08db3f5429e2dcea6196fa16d268f
child 292543 755a30aced7048a41e0dfb56a54d54fcd2c4e069
push id5364
push usernalexander@mozilla.com
push dateSat, 12 Sep 2015 19:37:32 +0000
reviewersglandium
bugs1204260
milestone43.0a1
Bug 1204260 - Pin Android package versions to android-22 and build-tools-22.0.1. r?glandium Right now, --with-android-sdk expects a path to a specific Android SDK version, like /path/to/platforms/android-22. That path is exposed as ANDROID_SDK; the Android SDK root is exposed as ANDROID_SDK_ROOT. Right now, the provided platform's version number is extracted into ANDROID_TARGET_SDK. The extracted ANDROID_TARGET_SDK is checked against a minimum version number (supplied as a parameter to MOZ_ANDROID_SDK). After this patch, --with-android-sdk expects what is now ANDROID_SDK_ROOT, and then derives ANDROID_SDK from that path and a pinned SDK platform version number. The exact version number which we search for is now a parameter given to MOZ_ANDROID_SDK. We accept and warn if we recognize an old-style ANDROID_SDK path. The existing MOZ_ANDROID_{MIN,MAX}_SDK_VERSION variables remain as they are. Right now, the Android build tools are searched in a deterministic but non-obvious manner. After this patch, the exact build tools version number is now a parameter given to MOZ_ANDROID_SDK.
build/autoconf/android.m4
configure.in
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -7,17 +7,17 @@ AC_DEFUN([MOZ_ANDROID_NDK],
 
 MOZ_ARG_WITH_STRING(android-ndk,
 [  --with-android-ndk=DIR
                           location where the Android NDK can be found],
     android_ndk=$withval)
 
 MOZ_ARG_WITH_STRING(android-toolchain,
 [  --with-android-toolchain=DIR
-                          location of the android toolchain],
+                          location of the Android toolchain],
     android_toolchain=$withval)
 
 MOZ_ARG_WITH_STRING(android-gnu-compiler-version,
 [  --with-android-gnu-compiler-version=VER
                           gnu compiler version to use],
     android_gnu_compiler_version=$withval)
 
 MOZ_ARG_ENABLE_BOOL(android-libstdcxx,
@@ -303,129 +303,115 @@ if test -n "$MOZ_NATIVE_DEVICES" ; then
     MOZ_ANDROID_AAR(play-services-base, 7.8.0, google, com/google/android/gms)
     MOZ_ANDROID_AAR(play-services-cast, 7.8.0, google, com/google/android/gms)
     MOZ_ANDROID_AAR(appcompat-v7, 22.2.1, android, com/android/support)
     MOZ_ANDROID_AAR(mediarouter-v7, 22.2.1, android, com/android/support)
 fi
 
 ])
 
+AC_DEFUN([ANDROID_INSTALL_MSG], [mach android update sdk --all --no-ui --filter "$1"])
+
+dnl Configure an Android SDK.
+dnl Arg 1: target SDK version, like 22.
+dnl Arg 2: build tools version, like 22.0.1.
 AC_DEFUN([MOZ_ANDROID_SDK],
 [
 
 MOZ_ARG_WITH_STRING(android-sdk,
 [  --with-android-sdk=DIR
-                          location where the Android SDK can be found (base directory, e.g. .../android/platforms/android-6)],
-    android_sdk=$withval)
+                          location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux)],
+    android_sdk_root=$withval)
 
 android_sdk_root=${withval%/platforms/android-*}
 
 case "$target" in
 *-android*|*-linuxandroid*)
-    if test -z "$android_sdk" ; then
+    if test -z "$android_sdk_root" ; then
         AC_MSG_ERROR([You must specify --with-android-sdk=/path/to/sdk when targeting Android.])
+    fi
+
+    # We were given an old-style --with-android-sdk=/path/to/sdk/platforms/android-*.  Accept but warn.
+    if test -e "$withval"/source.properties ; then
+        AC_MSG_WARN([Including platforms/android-* in --with-android-sdk arguments is deprecated.  Any platform specified is being ignored.])
+    fi
+
+    android_target_sdk=$1
+    if ! test "$android_target_sdk" -eq "$android_target_sdk" ; then
+        AC_MSG_ERROR([The given Android SDK platform version isn't a number! (Looked at $android_target_sdk)])
+    fi
+
+    AC_MSG_CHECKING([for Android SDK platform version $android_target_sdk])
+    android_sdk=$android_sdk_root/platforms/android-$android_target_sdk
+    if ! test -e "$android_sdk/source.properties" ; then
+        AC_MSG_ERROR([You must download Android SDK platform version $android_target_sdk.  Try |ANDROID_INSTALL_MSG(android-$android_target_sdk)|.  (Looked for $android_sdk)])
+    fi
+    AC_MSG_RESULT([$android_sdk])
+
+    android_build_tools="$android_sdk_root"/build-tools/$2
+    AC_MSG_CHECKING([for Android build-tools version $2])
+    if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
+        AC_MSG_RESULT([$android_build_tools])
     else
-        if ! test -e "$android_sdk"/source.properties ; then
-            AC_MSG_ERROR([The path in --with-android-sdk isn't valid (source.properties hasn't been found).])
-        fi
-
-        # Get the api level from "$android_sdk"/source.properties.
-        ANDROID_TARGET_SDK=`$AWK -F = changequote(<<, >>)'<<$>>1 == "AndroidVersion.ApiLevel" {print <<$>>2}'changequote([, ]) "$android_sdk"/source.properties`
+        AC_MSG_ERROR([You must install the Android build-tools version $2.  Try |ANDROID_INSTALL_MSG(build-tools-$2)|.  (Looked for $android_build_tools)])
+    fi
 
-        if test -z "$ANDROID_TARGET_SDK" ; then
-            AC_MSG_ERROR([Unexpected error: no AndroidVersion.ApiLevel field has been found in source.properties.])
-        fi
-
-	AC_DEFINE_UNQUOTED(ANDROID_TARGET_SDK,$ANDROID_TARGET_SDK)
-	AC_SUBST(ANDROID_TARGET_SDK)
+    MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$android_build_tools])
+    MOZ_PATH_PROG(DX, dx, :, [$android_build_tools])
+    MOZ_PATH_PROG(AAPT, aapt, :, [$android_build_tools])
+    MOZ_PATH_PROG(AIDL, aidl, :, [$android_build_tools])
+    if test -z "$ZIPALIGN" -o "$ZIPALIGN" = ":"; then
+      AC_MSG_ERROR([The program zipalign was not found.  Try |ANDROID_INSTALL_MSG(build-tools-$2)|.])
+    fi
+    if test -z "$DX" -o "$DX" = ":"; then
+      AC_MSG_ERROR([The program dx was not found.  Try |ANDROID_INSTALL_MSG(build-tools-$2)|.])
+    fi
+    if test -z "$AAPT" -o "$AAPT" = ":"; then
+      AC_MSG_ERROR([The program aapt was not found.  Try |ANDROID_INSTALL_MSG(build-tools-$2)|.])
+    fi
+    if test -z "$AIDL" -o "$AIDL" = ":"; then
+      AC_MSG_ERROR([The program aidl was not found.  Try |ANDROID_INSTALL_MSG(build-tools-$2)|.])
+    fi
 
-        if ! test "$ANDROID_TARGET_SDK" -eq "$ANDROID_TARGET_SDK" ; then
-            AC_MSG_ERROR([Unexpected error: the found android api value isn't a number! (found $ANDROID_TARGET_SDK)])
-        fi
+    android_platform_tools="$android_sdk_root"/platform-tools
+    AC_MSG_CHECKING([for Android platform-tools])
+    if test -d "$android_platform_tools" -a -f "$android_platform_tools/adb"; then
+        AC_MSG_RESULT([$android_platform_tools])
+    else
+        AC_MSG_ERROR([You must install the Android platform-tools.  Try |ANDROID_INSTALL_MSG(platform-tools)|.  (Looked for $android_platform_tools)])
+    fi
 
-        if test $ANDROID_TARGET_SDK -lt $1 ; then
-            AC_MSG_ERROR([The given Android SDK provides API level $ANDROID_TARGET_SDK ($1 or higher required).])
-        fi
+    MOZ_PATH_PROG(ADB, adb, :, [$android_platform_tools])
+    if test -z "$ADB" -o "$ADB" = ":"; then
+      AC_MSG_ERROR([The program adb was not found.  Try |ANDROID_INSTALL_MSG(platform-tools)|.])
     fi
 
     android_tools="$android_sdk_root"/tools
-    android_platform_tools="$android_sdk_root"/platform-tools
-    if test ! -d "$android_platform_tools" ; then
-        android_platform_tools="$android_sdk"/tools # SDK Tools < r8
+    AC_MSG_CHECKING([for Android tools])
+    if test -d "$android_tools" -a -f "$android_tools/emulator"; then
+        AC_MSG_RESULT([$android_tools])
+    else
+        AC_MSG_ERROR([You must install the Android tools.  Try |ANDROID_INSTALL_MSG(tools)|.  (Looked for $android_tools)])
     fi
 
-    dnl The build tools got moved around to different directories in SDK
-    dnl Tools r22. Try to locate them. This is awful, but, from
-    dnl http://stackoverflow.com/a/4495368, the following sorts versions
-    dnl of the form x.y.z.a.b from newest to oldest:
-    dnl sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr
-    dnl We want to favour the newer versions that start with 'android-';
-    dnl that's what the sed is about.
-    dnl We might iterate over directories that aren't build-tools at all;
-    dnl we use the presence of aapt as a marker.
-    AC_MSG_CHECKING([for android build-tools directory])
-    android_build_tools=""
-    for suffix in `ls "$android_sdk_root/build-tools" | sed -e "s,android-,999.," | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr`; do
-        tools_directory=`echo "$android_sdk_root/build-tools/$suffix" | sed -e "s,999.,android-,"`
-        if test -d "$tools_directory" -a -f "$tools_directory/aapt"; then
-            android_build_tools="$tools_directory"
-            break
-        fi
-    done
-    if test -z "$android_build_tools" ; then
-        android_build_tools="$android_platform_tools" # SDK Tools < r22
-    fi
-    all_android_build_tools=""
-    for suffix in `ls "$android_sdk_root/build-tools" | sed -e "s,android-,999.," | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr`; do
-        tools_directory=`echo "$android_sdk_root/build-tools/$suffix" | sed -e "s,999.,android-,"`
-        if test -d "$tools_directory" -a -f "$tools_directory/aapt"; then
-            all_android_build_tools="$all_android_build_tools:$tools_directory"
-        fi
-    done
-
-    if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
-        AC_MSG_RESULT([$android_build_tools])
-    else
-        AC_MSG_ERROR([not found. Please check your SDK for the subdirectory of build-tools. With the current configuration, it should be in $android_sdk_root/build_tools])
+    MOZ_PATH_PROG(EMULATOR, emulator, :, [$android_tools])
+    if test -z "$EMULATOR" -o "$EMULATOR" = ":"; then
+      AC_MSG_ERROR([The program emulator was not found.  Try |ANDROID_INSTALL_MSG(tools)|.])
     fi
 
+    ANDROID_TARGET_SDK="${android_target_sdk}"
     ANDROID_SDK="${android_sdk}"
     ANDROID_SDK_ROOT="${android_sdk_root}"
-
     ANDROID_TOOLS="${android_tools}"
+    AC_DEFINE_UNQUOTED(ANDROID_TARGET_SDK,$ANDROID_TARGET_SDK)
+    AC_SUBST(ANDROID_TARGET_SDK)
     AC_SUBST(ANDROID_SDK_ROOT)
     AC_SUBST(ANDROID_SDK)
     AC_SUBST(ANDROID_TOOLS)
 
-    dnl Google has a history of moving the Android tools around.  We don't
-    dnl care where they are, so let's try to find them anywhere we can.
-    all_android_tools_paths="$ANDROID_TOOLS:$all_android_build_tools:$android_platform_tools"
-    MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$all_android_tools_paths])
-    MOZ_PATH_PROG(DX, dx, :, [$all_android_tools_paths])
-    MOZ_PATH_PROG(AAPT, aapt, :, [$all_android_tools_paths])
-    MOZ_PATH_PROG(AIDL, aidl, :, [$all_android_tools_paths])
-    MOZ_PATH_PROG(ADB, adb, :, [$all_android_tools_paths])
-    MOZ_PATH_PROG(EMULATOR, emulator, :, [$all_android_tools_paths])
-
-    if test -z "$ZIPALIGN" -o "$ZIPALIGN" = ":"; then
-      AC_MSG_ERROR([The program zipalign was not found.  Use --with-android-sdk={android-sdk-dir}.])
-    fi
-    if test -z "$DX" -o "$DX" = ":"; then
-      AC_MSG_ERROR([The program dx was not found.  Use --with-android-sdk={android-sdk-dir}.])
-    fi
-    if test -z "$AAPT" -o "$AAPT" = ":"; then
-      AC_MSG_ERROR([The program aapt was not found.  Use --with-android-sdk={android-sdk-dir}.])
-    fi
-    if test -z "$AIDL" -o "$AIDL" = ":"; then
-      AC_MSG_ERROR([The program aidl was not found.  Use --with-android-sdk={android-sdk-dir}.])
-    fi
-    if test -z "$ADB" -o "$ADB" = ":"; then
-      AC_MSG_ERROR([The program adb was not found.  Use --with-android-sdk={android-sdk-dir}.])
-    fi
-
     MOZ_ANDROID_AAR(support-v4, 22.2.1, android, com/android/support)
     MOZ_ANDROID_AAR(recyclerview-v7, 22.2.1, android, com/android/support)
 
     ANDROID_SUPPORT_ANNOTATIONS_JAR="$ANDROID_SDK_ROOT/extras/android/m2repository/com/android/support/support-annotations/22.2.1/support-annotations-22.2.1.jar"
     AC_MSG_CHECKING([for support-annotations JAR])
     if ! test -e $ANDROID_SUPPORT_ANNOTATIONS_JAR ; then
         AC_MSG_ERROR([You must download the support-annotations lib.  Run the Android SDK tool and install the Android Support Repository under Extras.  See https://developer.android.com/tools/extras/support-library.html for more info. (looked for $ANDROID_SUPPORT_ANNOTATIONS_JAR)])
     fi
--- a/configure.in
+++ b/configure.in
@@ -4062,37 +4062,38 @@ WINNT|Darwin|Android)
   MOZ_FOLD_LIBS=1
   ;;
 *)
   MOZ_FOLD_LIBS=
   ;;
 esac
 
 dnl ========================================================
-dnl Check Android SDK version depending on mobile target.
+dnl Ensure Android SDK and build-tools versions depending on
+dnl mobile target.
 dnl ========================================================
 
 if test -z "$gonkdir" ; then
-    # Minimum Android SDK API Level we require.
     case "$MOZ_BUILD_APP" in
     mobile/android | mobile/android/b2gdroid)
-        android_min_api_level=20
+        android_target_sdk=22
+        android_build_tools_version=22.0.1
         case "$target" in
         *-android*|*-linuxandroid*)
             :
             ;;
         *)
             AC_MSG_ERROR([You must specify --target=arm-linux-androideabi (or some other valid android target) when building with --enable-application=mobile/android or --enable-application=mobile/android/b2gdroid.
              See https://wiki.mozilla.org/Mobile/Fennec/Android#Setup_Fennec_mozconfig for more information about the necessary options])
             ;;
         esac
         ;;
     esac
 
-    MOZ_ANDROID_SDK($android_min_api_level)
+    MOZ_ANDROID_SDK($android_target_sdk, $android_build_tools_version)
 fi
 
 dnl ========================================================
 dnl =
 dnl = Toolkit Options
 dnl =
 dnl ========================================================
 MOZ_ARG_HEADER(Toolkit Options)