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

--HG--
extra : rebase_source : 07afb00de0e4a72af4026eb19ff4f2530c119336
This commit is contained in:
Nick Alexander 2017-06-21 10:52:30 -07:00
parent 23b90d5c28
commit bd230aea82
9 changed files with 64 additions and 34 deletions

View File

@ -1,11 +1,32 @@
import java.util.regex.Pattern import java.util.regex.Pattern
def tryInt = { string ->
if (string == null) {
return string
}
if (string.isInteger()) {
return string as Integer
}
return string
}
allprojects { allprojects {
// Expose the per-object-directory configuration to all projects. // Expose the per-object-directory configuration to all projects.
ext { ext {
mozconfig = gradle.mozconfig mozconfig = gradle.mozconfig
topsrcdir = gradle.mozconfig.topsrcdir topsrcdir = gradle.mozconfig.topsrcdir
topobjdir = gradle.mozconfig.topobjdir 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 { repositories {

View File

@ -230,9 +230,10 @@ fi
]) ])
dnl Configure an Android SDK. dnl Configure an Android SDK.
dnl Arg 1: target SDK version, like 23. dnl Arg 1: compile SDK version, like 23.
dnl Arg 2: list of build-tools versions, like "23.0.3 23.0.1". dnl Arg 2: target SDK version, like 23.
dnl Arg 3: target lint version, like "25.3.1" (note: we fall back to 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). dnl unversioned lint if this version is not found).
AC_DEFUN([MOZ_ANDROID_SDK], AC_DEFUN([MOZ_ANDROID_SDK],
[ [
@ -257,7 +258,7 @@ case "$target" in
AC_MSG_ERROR([Including platforms/android-* in --with-android-sdk arguments is deprecated. Use --with-android-sdk=$android_sdk_root.]) AC_MSG_ERROR([Including platforms/android-* in --with-android-sdk arguments is deprecated. Use --with-android-sdk=$android_sdk_root.])
fi fi
android_target_sdk=$1 android_target_sdk=$2
AC_MSG_CHECKING([for Android SDK platform version $android_target_sdk]) AC_MSG_CHECKING([for Android SDK platform version $android_target_sdk])
android_sdk=$android_sdk_root/platforms/android-$android_target_sdk android_sdk=$android_sdk_root/platforms/android-$android_target_sdk
if ! test -e "$android_sdk/source.properties" ; then if ! test -e "$android_sdk/source.properties" ; then
@ -268,7 +269,7 @@ case "$target" in
AC_MSG_CHECKING([for Android build-tools]) AC_MSG_CHECKING([for Android build-tools])
android_build_tools_base="$android_sdk_root"/build-tools android_build_tools_base="$android_sdk_root"/build-tools
android_build_tools_version="" android_build_tools_version=""
for version in $2; do for version in $3; do
android_build_tools="$android_build_tools_base"/$version android_build_tools="$android_build_tools_base"/$version
if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
android_build_tools_version=$version android_build_tools_version=$version
@ -277,7 +278,7 @@ case "$target" in
fi fi
done done
if test "$android_build_tools_version" = ""; then 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)]) AC_MSG_ERROR([You must install the Android build-tools version $version. Try |mach bootstrap|. (Looked for "$android_build_tools_base"/$version)])
fi fi
@ -324,11 +325,15 @@ case "$target" in
AC_MSG_ERROR([The program emulator was not found. Try |mach bootstrap|.]) AC_MSG_ERROR([The program emulator was not found. Try |mach bootstrap|.])
fi 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_TARGET_SDK="${android_target_sdk}"
ANDROID_SDK="${android_sdk}" ANDROID_SDK="${android_sdk}"
ANDROID_SDK_ROOT="${android_sdk_root}" ANDROID_SDK_ROOT="${android_sdk_root}"
ANDROID_TOOLS="${android_tools}" ANDROID_TOOLS="${android_tools}"
ANDROID_BUILD_TOOLS_VERSION="$android_build_tools_version" ANDROID_BUILD_TOOLS_VERSION="$android_build_tools_version"
AC_SUBST(ANDROID_COMPILE_SDK_VERSION)
AC_SUBST(ANDROID_TARGET_SDK) AC_SUBST(ANDROID_TARGET_SDK)
AC_SUBST(ANDROID_SDK_ROOT) AC_SUBST(ANDROID_SDK_ROOT)
AC_SUBST(ANDROID_SDK) AC_SUBST(ANDROID_SDK)
@ -357,7 +362,7 @@ case "$target" in
;; ;;
esac esac
android_lint_target=$3 android_lint_target=$4
ANDROID_LINT_CLASSPATH="" ANDROID_LINT_CLASSPATH=""
android_lint_versioned_jar="$ANDROID_SDK_ROOT/tools/lib/lint-$android_lint_target.jar" 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" android_lint_unversioned_jar="$ANDROID_SDK_ROOT/tools/lib/lint.jar"

View File

@ -11,20 +11,17 @@ dexcount {
} }
android { android {
compileSdkVersion 23 compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION buildToolsVersion project.ext.buildToolsVersion
defaultConfig { defaultConfig {
targetSdkVersion 23 targetSdkVersion project.ext.targetSdkVersion
minSdkVersion 15 minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders
applicationId mozconfig.substs.ANDROID_PACKAGE_NAME applicationId mozconfig.substs.ANDROID_PACKAGE_NAME
testApplicationId 'org.mozilla.roboexample.test' testApplicationId 'org.mozilla.roboexample.test'
testInstrumentationRunner 'org.mozilla.gecko.FennecInstrumentationTestRunner' 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. // Used by Robolectric based tests; see TestRunner.
buildConfigField 'String', 'BUILD_DIR', "\"${project.buildDir}\"" buildConfigField 'String', 'BUILD_DIR', "\"${project.buildDir}\""

View File

@ -6,7 +6,7 @@
android:versionName="1.0" > android:versionName="1.0" >
<uses-sdk android:minSdkVersion="${MOZ_ANDROID_MIN_SDK_VERSION}" <uses-sdk android:minSdkVersion="${MOZ_ANDROID_MIN_SDK_VERSION}"
android:targetSdkVersion="23"/> android:targetSdkVersion="${ANDROID_TARGET_SDK}"/>
<!-- TODO: re-instate maxSdkVersion. --> <!-- TODO: re-instate maxSdkVersion. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

View File

@ -3,12 +3,14 @@ buildDir "${topobjdir}/gradle/build/mobile/android/bouncer"
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 23 compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION buildToolsVersion project.ext.buildToolsVersion
defaultConfig { defaultConfig {
targetSdkVersion 23 targetSdkVersion project.ext.targetSdkVersion
minSdkVersion 15 minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders
applicationId mozconfig.substs.ANDROID_PACKAGE_NAME applicationId mozconfig.substs.ANDROID_PACKAGE_NAME
} }

View File

@ -6,17 +6,19 @@ apply plugin: 'com.android.library'
def VERSION_NAME = '0.0.1' def VERSION_NAME = '0.0.1'
android { android {
compileSdkVersion 23 compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION buildToolsVersion project.ext.buildToolsVersion
defaultConfig { defaultConfig {
targetSdkVersion project.ext.targetSdkVersion
minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders
// TODO: version GeckoView explicitly. We'd like to avoid // TODO: version GeckoView explicitly. We'd like to avoid
// mozconfig.substs.ANDROID_VERSION_CODE, which won't be intuitive to // mozconfig.substs.ANDROID_VERSION_CODE, which won't be intuitive to
// consumer (and advances very quickly on pre-release channels). // consumer (and advances very quickly on pre-release channels).
versionCode 1 versionCode 1
versionName VERSION_NAME versionName VERSION_NAME
targetSdkVersion 23
minSdkVersion 15
consumerProguardFiles 'proguard-rules.txt' consumerProguardFiles 'proguard-rules.txt'
// TODO: ensure these fields always agree with mobile/android/geckoview/BuildConfig.java.in, // TODO: ensure these fields always agree with mobile/android/geckoview/BuildConfig.java.in,

View File

@ -3,13 +3,15 @@ buildDir "${topobjdir}/gradle/build/mobile/android/geckoview_example"
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 23 compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION buildToolsVersion project.ext.buildToolsVersion
defaultConfig { defaultConfig {
targetSdkVersion project.ext.targetSdkVersion
minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders
applicationId "org.mozilla.geckoview_example" applicationId "org.mozilla.geckoview_example"
minSdkVersion 15
targetSdkVersion 23
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

View File

@ -3,12 +3,13 @@ buildDir "${topobjdir}/gradle/build/mobile/android/thirdparty"
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
android { android {
compileSdkVersion 23 compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION buildToolsVersion project.ext.buildToolsVersion
defaultConfig { defaultConfig {
targetSdkVersion 23 targetSdkVersion project.ext.targetSdkVersion
minSdkVersion 15 minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders
} }
compileOptions { compileOptions {

View File

@ -2302,7 +2302,7 @@ dnl ========================================================
if test -z "$gonkdir" ; then if test -z "$gonkdir" ; then
case "$MOZ_BUILD_APP" in case "$MOZ_BUILD_APP" in
mobile/android) 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 esac
fi fi