Bug 1352602 - Part 2: Use build system SDK versions in Gradle configurations. r=maliu
This patch does two things:
- add a Gradle-only ANDROID_COMPILE_SDK_VERSION substitution;
- uses it while uniformizing all of the Gradle Android SDK version
configurations.
The approach is fairly standard (and we were using it already); see,
for example
https://medium.com/@ali.muzaffar/gradle-configure-variables-for-all-android-project-modules-in-one-place-5a6e56cd384e
This will make bumping the Gradle configuration versions forward
easier.
MozReview-Commit-ID: 1j5siCvR5qt
--- a/build.gradle
+++ b/build.gradle
@@ -1,16 +1,37 @@
import java.util.regex.Pattern
+def tryInt = { string ->
+ if (string == null) {
+ return string
+ }
+ if (string.isInteger()) {
+ return string as Integer
+ }
+ return string
+}
+
allprojects {
// Expose the per-object-directory configuration to all projects.
ext {
mozconfig = gradle.mozconfig
topsrcdir = gradle.mozconfig.topsrcdir
topobjdir = gradle.mozconfig.topobjdir
+
+ compileSdkVersion = tryInt(mozconfig.substs.ANDROID_COMPILE_SDK_VERSION)
+ buildToolsVersion = tryInt(mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION)
+ targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
+ minSdkVersion = tryInt(mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION)
+ manifestPlaceholders = [
+ ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
+ ANDROID_TARGET_SDK: mozconfig.substs.ANDROID_TARGET_SDK,
+ MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
+ MOZ_ANDROID_SHARED_ID: "${mozconfig.substs.ANDROID_PACKAGE_NAME}.sharedID",
+ ]
}
repositories {
if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
maven {
url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
}
}
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -225,19 +225,20 @@ AC_DEFUN([MOZ_ANDROID_INSTALL_TRACKING],
if test -n "$MOZ_INSTALL_TRACKING"; then
MOZ_ANDROID_AAR(play-services-ads, $ANDROID_GOOGLE_PLAY_SERVICES_VERSION, google, com/google/android/gms)
MOZ_ANDROID_AAR(play-services-basement, $ANDROID_GOOGLE_PLAY_SERVICES_VERSION, google, com/google/android/gms)
fi
])
dnl Configure an Android SDK.
-dnl Arg 1: target SDK version, like 23.
-dnl Arg 2: list of build-tools versions, like "23.0.3 23.0.1".
-dnl Arg 3: target lint version, like "25.3.1" (note: we fall back to
+dnl Arg 1: compile SDK version, like 23.
+dnl Arg 2: target SDK version, like 23.
+dnl Arg 3: list of build-tools versions, like "23.0.3 23.0.1".
+dnl Arg 4: target lint version, like "25.3.1" (note: we fall back to
dnl unversioned lint if this version is not found).
AC_DEFUN([MOZ_ANDROID_SDK],
[
MOZ_ARG_WITH_STRING(android-sdk,
[ --with-android-sdk=DIR
location where the Android SDK can be found (like ~/.mozbuild/android-sdk-linux)],
android_sdk_root=$withval)
@@ -252,37 +253,37 @@ case "$target" in
# We were given an old-style
# --with-android-sdk=/path/to/sdk/platforms/android-*. We could warn, but
# we'll get compliance by forcing the issue.
if test -e "$withval"/source.properties ; then
AC_MSG_ERROR([Including platforms/android-* in --with-android-sdk arguments is deprecated. Use --with-android-sdk=$android_sdk_root.])
fi
- android_target_sdk=$1
+ android_target_sdk=$2
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 |mach bootstrap|. (Looked for $android_sdk)])
fi
AC_MSG_RESULT([$android_sdk])
AC_MSG_CHECKING([for Android build-tools])
android_build_tools_base="$android_sdk_root"/build-tools
android_build_tools_version=""
- for version in $2; do
+ for version in $3; do
android_build_tools="$android_build_tools_base"/$version
if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
android_build_tools_version=$version
AC_MSG_RESULT([$android_build_tools])
break
fi
done
if test "$android_build_tools_version" = ""; then
- version=$(echo $2 | cut -d" " -f1)
+ version=$(echo $3 | cut -d" " -f1)
AC_MSG_ERROR([You must install the Android build-tools version $version. Try |mach bootstrap|. (Looked for "$android_build_tools_base"/$version)])
fi
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
@@ -319,21 +320,25 @@ case "$target" in
AC_MSG_ERROR([You must install the Android tools. Try |mach bootstrap|. (Looked for $android_tools)])
fi
MOZ_PATH_PROG(EMULATOR, emulator, :, [$android_tools])
if test -z "$EMULATOR" -o "$EMULATOR" = ":"; then
AC_MSG_ERROR([The program emulator was not found. Try |mach bootstrap|.])
fi
+ # `compileSdkVersion ANDROID_COMPILE_SDK_VERSION` is Gradle-only,
+ # so there's no associated configure check.
+ ANDROID_COMPILE_SDK_VERSION=$1
ANDROID_TARGET_SDK="${android_target_sdk}"
ANDROID_SDK="${android_sdk}"
ANDROID_SDK_ROOT="${android_sdk_root}"
ANDROID_TOOLS="${android_tools}"
ANDROID_BUILD_TOOLS_VERSION="$android_build_tools_version"
+ AC_SUBST(ANDROID_COMPILE_SDK_VERSION)
AC_SUBST(ANDROID_TARGET_SDK)
AC_SUBST(ANDROID_SDK_ROOT)
AC_SUBST(ANDROID_SDK)
AC_SUBST(ANDROID_TOOLS)
AC_SUBST(ANDROID_BUILD_TOOLS_VERSION)
MOZ_ANDROID_AAR(customtabs, $ANDROID_SUPPORT_LIBRARY_VERSION, android, com/android/support)
MOZ_ANDROID_AAR(appcompat-v7, $ANDROID_SUPPORT_LIBRARY_VERSION, android, com/android/support)
@@ -352,17 +357,17 @@ case "$target" in
fi
AC_MSG_RESULT([$ANDROID_SUPPORT_ANNOTATIONS_JAR])
AC_SUBST(ANDROID_SUPPORT_ANNOTATIONS_JAR)
ANDROID_SUPPORT_ANNOTATIONS_JAR_LIB=$ANDROID_SUPPORT_ANNOTATIONS_JAR
AC_SUBST(ANDROID_SUPPORT_ANNOTATIONS_JAR_LIB)
;;
esac
-android_lint_target=$3
+android_lint_target=$4
ANDROID_LINT_CLASSPATH=""
android_lint_versioned_jar="$ANDROID_SDK_ROOT/tools/lib/lint-$android_lint_target.jar"
android_lint_unversioned_jar="$ANDROID_SDK_ROOT/tools/lib/lint.jar"
if test -e "$android_lint_versioned_jar" ; then
ANDROID_LINT_CLASSPATH="$ANDROID_LINT_CLASSPATH $android_lint_versioned_jar"
ANDROID_LINT_CLASSPATH="$ANDROID_LINT_CLASSPATH $ANDROID_SDK_ROOT/tools/lib/lint-checks-$android_lint_target.jar"
ANDROID_LINT_CLASSPATH="$ANDROID_LINT_CLASSPATH $ANDROID_SDK_ROOT/tools/lib/sdklib-$android_lint_target.jar"
ANDROID_LINT_CLASSPATH="$ANDROID_LINT_CLASSPATH $ANDROID_SDK_ROOT/tools/lib/repository-$android_lint_target.jar"
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -6,30 +6,27 @@ apply plugin: 'checkstyle'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'findbugs'
dexcount {
format = "tree"
}
android {
- compileSdkVersion 23
- buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
+ compileSdkVersion project.ext.compileSdkVersion
+ buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
- targetSdkVersion 23
- minSdkVersion 15
+ targetSdkVersion project.ext.targetSdkVersion
+ minSdkVersion project.ext.minSdkVersion
+ manifestPlaceholders = project.ext.manifestPlaceholders
+
applicationId mozconfig.substs.ANDROID_PACKAGE_NAME
testApplicationId 'org.mozilla.roboexample.test'
testInstrumentationRunner 'org.mozilla.gecko.FennecInstrumentationTestRunner'
- manifestPlaceholders = [
- ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
- MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
- MOZ_ANDROID_SHARED_ID: "${mozconfig.substs.ANDROID_PACKAGE_NAME}.sharedID",
- ]
// Used by Robolectric based tests; see TestRunner.
buildConfigField 'String', 'BUILD_DIR', "\"${project.buildDir}\""
vectorDrawables.useSupportLibrary = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
--- a/mobile/android/app/src/androidTest/AndroidManifest.xml
+++ b/mobile/android/app/src/androidTest/AndroidManifest.xml
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.mozilla.roboexample.test"
android:sharedUserId="${MOZ_ANDROID_SHARED_ID}"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="${MOZ_ANDROID_MIN_SDK_VERSION}"
- android:targetSdkVersion="23"/>
+ android:targetSdkVersion="${ANDROID_TARGET_SDK}"/>
<!-- TODO: re-instate maxSdkVersion. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<instrumentation
--- a/mobile/android/bouncer/build.gradle
+++ b/mobile/android/bouncer/build.gradle
@@ -1,19 +1,21 @@
buildDir "${topobjdir}/gradle/build/mobile/android/bouncer"
apply plugin: 'com.android.application'
android {
- compileSdkVersion 23
- buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
+ compileSdkVersion project.ext.compileSdkVersion
+ buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
- targetSdkVersion 23
- minSdkVersion 15
+ targetSdkVersion project.ext.targetSdkVersion
+ minSdkVersion project.ext.minSdkVersion
+ manifestPlaceholders = project.ext.manifestPlaceholders
+
applicationId mozconfig.substs.ANDROID_PACKAGE_NAME
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -1,27 +1,29 @@
buildDir "${topobjdir}/gradle/build/mobile/android/geckoview"
apply plugin: 'android-sdk-manager' // Must come before 'com.android.*'.
apply plugin: 'com.android.library'
def VERSION_NAME = '0.0.1'
android {
- compileSdkVersion 23
- buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
+ compileSdkVersion project.ext.compileSdkVersion
+ buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
+ targetSdkVersion project.ext.targetSdkVersion
+ minSdkVersion project.ext.minSdkVersion
+ manifestPlaceholders = project.ext.manifestPlaceholders
+
// TODO: version GeckoView explicitly. We'd like to avoid
// mozconfig.substs.ANDROID_VERSION_CODE, which won't be intuitive to
// consumer (and advances very quickly on pre-release channels).
versionCode 1
versionName VERSION_NAME
- targetSdkVersion 23
- minSdkVersion 15
consumerProguardFiles 'proguard-rules.txt'
// TODO: ensure these fields always agree with mobile/android/geckoview/BuildConfig.java.in,
// either by diffing the processed files or by generating the output from a single source.
buildConfigField 'String', "GRE_MILESTONE", "\"${mozconfig.substs.GRE_MILESTONE}\""
buildConfigField 'String', "MOZ_APP_ABI", "\"${mozconfig.substs.MOZ_APP_ABI}\"";
buildConfigField 'String', "MOZ_APP_BASENAME", "\"${mozconfig.substs.MOZ_APP_BASENAME}\"";
--- a/mobile/android/geckoview_example/build.gradle
+++ b/mobile/android/geckoview_example/build.gradle
@@ -1,20 +1,22 @@
buildDir "${topobjdir}/gradle/build/mobile/android/geckoview_example"
apply plugin: 'com.android.application'
android {
- compileSdkVersion 23
- buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
+ compileSdkVersion project.ext.compileSdkVersion
+ buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
+ targetSdkVersion project.ext.targetSdkVersion
+ minSdkVersion project.ext.minSdkVersion
+ manifestPlaceholders = project.ext.manifestPlaceholders
+
applicationId "org.mozilla.geckoview_example"
- minSdkVersion 15
- targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
// This is extremely frustrating, but the only way to do it automation for
// now. Without this, we only get a "debugAndroidTest" configuration; we
// have no "withoutGeckoBinariesAndroidTest" configuration.
--- a/mobile/android/thirdparty/build.gradle
+++ b/mobile/android/thirdparty/build.gradle
@@ -1,19 +1,20 @@
buildDir "${topobjdir}/gradle/build/mobile/android/thirdparty"
apply plugin: 'com.android.library'
android {
- compileSdkVersion 23
- buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
+ compileSdkVersion project.ext.compileSdkVersion
+ buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
- targetSdkVersion 23
- minSdkVersion 15
+ targetSdkVersion project.ext.targetSdkVersion
+ minSdkVersion project.ext.minSdkVersion
+ manifestPlaceholders = project.ext.manifestPlaceholders
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
--- a/old-configure.in
+++ b/old-configure.in
@@ -2297,17 +2297,17 @@ AC_SUBST(MOZ_B2G_VERSION)
dnl ========================================================
dnl Ensure Android SDK and build-tools versions depending on
dnl mobile target.
dnl ========================================================
if test -z "$gonkdir" ; then
case "$MOZ_BUILD_APP" in
mobile/android)
- MOZ_ANDROID_SDK(23, 23.0.3 23.0.1, 25.3.1)
+ MOZ_ANDROID_SDK(23, 23, 23.0.3 23.0.1, 25.3.1)
;;
esac
fi
dnl ========================================================
dnl =
dnl = Toolkit Options
dnl =