Skip to content

Commit

Permalink
Bug 1411654 - Part 1: Upgrade to Android-Gradle 3.0+ and build-tools;…
Browse files Browse the repository at this point in the history
…26.0.2. r=maliu

New Android-Gradle plugins pin the build-tools version, and we want to
be consistent between Gradle and moz.build.

MozReview-Commit-ID: ApWS4rHzPuH

--HG--
extra : rebase_source : 22008e9333b15c594ce26c2a52f67396d6e3ab84
extra : source : f918500d9cf5112b70bc8e0a120df435b02252b7
  • Loading branch information
ncalexan committed Oct 26, 2017
1 parent e4a0492 commit edf219b
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 125 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ allprojects {
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 = [
Expand Down Expand Up @@ -52,9 +51,8 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// Provided in tree.
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
distributionSha256Sum=ed7e9c8bb41bd10d4c9339c95b2f8b122f5bf13188bd90504a26e0f00b123b0d
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionSha256Sum=5c07b3bac2209fbc98fb1fdf6fd831f72429cdf8c503807404eae03d8c8099e5
93 changes: 41 additions & 52 deletions mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dexcount {

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion

defaultConfig {
targetSdkVersion project.ext.targetSdkVersion
Expand Down Expand Up @@ -74,6 +73,14 @@ android {
if (mozconfig.substs.MOZILLA_OFFICIAL) {
debug configureMinifyClosure
}

def isDebuggable = (!mozconfig.substs.MOZILLA_OFFICIAL) || (mozconfig.substs.NIGHTLY_BUILD && mozconfig.substs.MOZ_DEBUG)
debug {
debuggable isDebuggable
}
release {
debuggable isDebuggable
}
}

// The "audience" flavour dimension distinguishes between _local_ builds (intended for
Expand Down Expand Up @@ -239,30 +246,31 @@ android {
}

dependencies {
compile "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:appcompat-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:cardview-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:recyclerview-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:design:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:customtabs:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:appcompat-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:cardview-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:recyclerview-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:design:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:customtabs:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:palette-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"

if (mozconfig.substs.MOZ_NATIVE_DEVICES) {
compile "com.android.support:mediarouter-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.google.android.gms:play-services-basement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-base:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-cast:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.android.support:mediarouter-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.google.android.gms:play-services-basement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-base:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-cast:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
}

if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
compile "com.google.android.gms:play-services-analytics:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-basement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-analytics:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-basement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
}

if (mozconfig.substs.MOZ_ANDROID_GCM) {
compile "com.google.android.gms:play-services-basement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-base:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-gcm:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
compile "com.google.android.gms:play-services-measurement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-basement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-base:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-gcm:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
implementation "com.google.android.gms:play-services-measurement:${mozconfig.substs.ANDROID_GOOGLE_PLAY_SERVICES_VERSION}"
}

// Include LeakCanary in most gradle based builds. LeakCanary adds about 5k methods, so we disable
Expand All @@ -271,40 +279,22 @@ dependencies {
// of this library.
// It doesn't seem like there is a non-trivial way to be conditional on 'localOld', so instead we explicitly
// define a version of leakcanary for every flavor:
localCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
localOldCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
officialCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
officialCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'

// With a simple "compile", Gradle will always build these libraries in their default configuration
// (i.e. release), so we need to explicitly forward our own build configuration here (bug 1385695).
//
// Official builds compile a hacked up app:Official..Debug, but need the
// release versions of the dependencies, in order to not have debugging
// information. It's not yet possible to specify just officialDebug, so we
// hack around it here.
if (mozconfig.substs.MOZILLA_OFFICIAL) {
debugCompile project(path: ':geckoview', configuration: "release")
} else {
debugCompile project(path: ':geckoview', configuration: "debug")
}
releaseCompile project(path: ':geckoview', configuration: "release")
localImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
localOldImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
officialImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
officialImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'

if (mozconfig.substs.MOZILLA_OFFICIAL) {
debugCompile project(path: ':thirdparty', configuration: "release")
} else {
debugCompile project(path: ':thirdparty', configuration: "debug")
}
releaseCompile project(path: ':thirdparty', configuration: "release")
implementation project(path: ':geckoview')
implementation project(path: ':thirdparty')

testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'org.simpleframework:simple-http:6.0.1'
testCompile 'org.mockito:mockito-core:1.10.19'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.1.2'
testImplementation 'org.simpleframework:simple-http:6.0.1'
testImplementation 'org.mockito:mockito-core:1.10.19'

// Including the Robotium JAR directly can cause issues with dexing.
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.4'
androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.5.4'
}

// TODO: (bug 1261486): This impl is not robust -
Expand Down Expand Up @@ -381,7 +371,7 @@ android.applicationVariants.all { variant ->
}

android.applicationVariants.all { variant ->
configureVariantWithJNIWrappers(variant, "Fennec")
configureApplicationVariantWithJNIWrappers(variant, "Fennec")
}

if (gradle.startParameter.taskNames.any { it.endsWith('UnitTest') }) {
Expand Down Expand Up @@ -418,7 +408,7 @@ android.applicationVariants.all { variant ->

reports {
html.enabled = true // HTML reports for humans.
html.destination = "$project.buildDir/reports/findbugs/findbugs-${variant.name}-output.html"
html.destination = file("$project.buildDir/reports/findbugs/findbugs-${variant.name}-output.html")
xml.enabled = false
}
}
Expand All @@ -442,7 +432,7 @@ android.applicationVariants.all { variant ->

reports {
xml.enabled = true // XML reports for machines.
xml.destination = "$project.buildDir/reports/findbugs/findbugs-${variant.name}-output.xml"
xml.destination = file("$project.buildDir/reports/findbugs/findbugs-${variant.name}-output.xml")
html.enabled = false
}
}
Expand All @@ -468,8 +458,7 @@ android.applicationVariants.all { variant ->

variant.outputs.each { output ->
output.processManifest.doLast {
[output.processManifest.manifestOutputFile,
output.processManifest.instantRunManifestOutputFile,
[file("${manifestOutputDirectory}/AndroidManifest.xml"),
].each({ File manifestOutFile ->
if (manifestOutFile.exists()) {
def contents = manifestOutFile.getText('UTF-8')
Expand Down
4 changes: 2 additions & 2 deletions mobile/android/app/src/photon/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@
</style>

<style name="PopupAnimation">
<item name="@android:windowEnterAnimation">@anim/popup_show</item>
<item name="@android:windowExitAnimation">@anim/popup_hide</item>
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>

<style name="ToastBase">
Expand Down
5 changes: 5 additions & 0 deletions mobile/android/base/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
android:hardwareAccelerated="true"
android:supportsRtl="true"
android:allowBackup="false"
#ifdef MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE
# Android-Gradle 3.0+ doesn't respect android:debuggable from AndroidManifest.xml.
>
#else
# The preprocessor does not yet support arbitrary parentheses, so this cannot
# be parenthesized thus to clarify that the logical AND operator has precedence:
# !defined(MOZILLA_OFFICIAL) || (defined(NIGHTLY_BUILD) && defined(MOZ_DEBUG))
#if !defined(MOZILLA_OFFICIAL) || defined(NIGHTLY_BUILD) && defined(MOZ_DEBUG)
android:debuggable="true">
#else
android:debuggable="false">
#endif
#endif
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true"/>
Expand Down
10 changes: 3 additions & 7 deletions mobile/android/geckoview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ def computeVersionCode() {

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion

defaultConfig {
defaultPublishConfig 'release'
publishNonDefault true

targetSdkVersion project.ext.targetSdkVersion
minSdkVersion project.ext.minSdkVersion
manifestPlaceholders = project.ext.manifestPlaceholders
Expand Down Expand Up @@ -154,8 +150,8 @@ android {
}

dependencies {
compile "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
compile "com.android.support:palette-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
implementation "com.android.support:palette-v7:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
}

apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
Expand Down Expand Up @@ -218,7 +214,7 @@ android.libraryVariants.all { variant ->
}

android.libraryVariants.all { variant ->
configureVariantWithJNIWrappers(variant, "Generated")
configureLibraryVariantWithJNIWrappers(variant, "Generated")
}

apply plugin: 'maven'
Expand Down
16 changes: 6 additions & 10 deletions mobile/android/geckoview_example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion

defaultConfig {
targetSdkVersion project.ext.targetSdkVersion
Expand Down Expand Up @@ -36,20 +35,17 @@ android {
}

dependencies {
testCompile 'junit:junit:4.12'
testImplementation 'junit:junit:4.12'

compile 'com.android.support:support-annotations:23.4.0'
implementation 'com.android.support:support-annotations:23.4.0'

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestImplementation 'com.android.support.test:runner:0.5'
// Not defining this library again results in test-app assuming 23.1.1, and the following errors:
// "Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.1.1) differ."
androidTestCompile 'com.android.support:support-annotations:23.4.0'
androidTestImplementation 'com.android.support:support-annotations:23.4.0'

debugCompile project(path: ':geckoview', configuration: "debug")
releaseCompile project(path: ':geckoview', configuration: "release")
withGeckoBinariesCompile project(path: ':geckoview', configuration: "withGeckoBinaries")
withoutGeckoBinariesCompile project(path: ':geckoview', configuration: "withoutGeckoBinaries")
implementation project(path: ':geckoview')
}

apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
Expand Down
41 changes: 33 additions & 8 deletions mobile/android/gradle.configure
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,39 @@ set_config('GRADLE_ANDROID_APP_TASKS', gradle_android_app_tasks)


@depends(gradle_android_build_config, check_build_environment)
@imports(_from='itertools', _import='imap')
def gradle_android_app_apks(build_config, build_env):
'''Paths to APK files produced by |mach android assemble-app|.'''
flavor = '-'.join(build_config.app.variant.productFlavors)
buildType = build_config.app.variant.buildType
f = '{}/gradle/build/mobile/android/app/outputs/apk/app-{}-{}.apk'
g = '{}/gradle/build/mobile/android/app/outputs/apk/app-{}-{}-androidTest.apk'
return namespace(app_apk=f.format(build_env.topobjdir, flavor, buildType),
app_androidTest_apk=g.format(build_env.topobjdir, flavor, buildType))
def capitalize(s):
# str.capitalize lower cases trailing letters.
if s:
return s[0].upper() + s[1:]
else:
return s

def uncapitalize(s):
if s:
return s[0].lower() + s[1:]
else:
return s

# Like 'officialPhoton'.
productFlavor = uncapitalize(''.join(imap(capitalize, build_config.app.variant.productFlavors)))
# Like 'official-photon'.
product_flavor = '-'.join(build_config.app.variant.productFlavors)

substs = {
'topobjdir': build_env.topobjdir,
'productFlavor': productFlavor,
'product_flavor': product_flavor,
'buildType': build_config.app.variant.buildType,
}

f = '{topobjdir}/gradle/build/mobile/android/app/outputs/apk/{productFlavor}/{buildType}/app-{product_flavor}-{buildType}.apk'
g = '{topobjdir}/gradle/build/mobile/android/app/outputs/apk/androidTest/{productFlavor}/{buildType}/app-{product_flavor}-{buildType}-androidTest.apk'

return namespace(app_apk=f.format(**substs),
app_androidTest_apk=g.format(**substs))

set_config('GRADLE_ANDROID_APP_APK', gradle_android_app_apks.app_apk)
set_config('GRADLE_ANDROID_APP_ANDROIDTEST_APK', gradle_android_app_apks.app_androidTest_apk)
Expand Down Expand Up @@ -146,8 +171,8 @@ def gradle_android_findbugs_tasks(build_config):
set_config('GRADLE_ANDROID_FINDBUGS_TASKS', gradle_android_findbugs_tasks)


@dependable
def gradle_android_archive_geckoview_tasks():
@depends(gradle_android_build_config)
def gradle_android_archive_geckoview_tasks(build_config):
'''Gradle tasks run by |mach android archive-geckoview|.'''
return [
'geckoview:assembleWithGeckoBinaries',
Expand Down
Loading

0 comments on commit edf219b

Please sign in to comment.