Bug 1355625 - Part 2: Tweak the Gradle build to agree more with moz.build. r=sebastian draft
authorNick Alexander <nalexander@mozilla.com>
Tue, 20 Jun 2017 11:19:32 -0700
changeset 597755 9944b4b3f106aab590e914c7ee9a52a246a7fdf6
parent 597754 dab092a188bc735ef819a4be0ad13387e85c87e2
child 634311 6ae3ef5b1766fa5f248f263c73f24f745267f40a
push id65019
push usernalexander@mozilla.com
push dateTue, 20 Jun 2017 22:48:51 +0000
reviewerssebastian
bugs1355625
milestone56.0a1
Bug 1355625 - Part 2: Tweak the Gradle build to agree more with moz.build. r=sebastian MozReview-Commit-ID: DMoxPnla3Ij
mobile/android/app/build.gradle
mobile/android/thirdparty/build.gradle
settings.gradle
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -31,16 +31,20 @@ android {
         vectorDrawables.useSupportLibrary = true
     }
 
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_7
         targetCompatibility JavaVersion.VERSION_1_7
     }
 
+    aaptOptions {
+        cruncherEnabled = false
+    }
+
     dexOptions {
         javaMaxHeapSize "2g"
     }
 
     lintOptions {
         abortOnError true
     }
 
@@ -139,16 +143,22 @@ android {
                 srcDir "${topsrcdir}/mobile/android/base/aidl"
             }
 
             java {
                 srcDir "${topsrcdir}/mobile/android/base/java"
                 srcDir "${topsrcdir}/mobile/android/search/java"
                 srcDir "${topsrcdir}/mobile/android/services/src/main/java"
 
+                // These aren't included in moz.build builds, for reasons unknown.
+                exclude "org/mozilla/gecko/dlc/CleanupAction.java"
+                // This is a marker file for linting.  We can probably find
+                // other ways to achieve this once we're Gradle-only.
+                exclude "org/mozilla/gecko/util/UnusedResourcesUtil.java"
+
                 if (mozconfig.substs.MOZ_ANDROID_MLS_STUMBLER) {
                     srcDir "${topsrcdir}/mobile/android/stumbler/java"
                 }
 
                 if (!mozconfig.substs.MOZ_CRASHREPORTER) {
                     exclude 'org/mozilla/gecko/CrashReporter.java'
                 }
 
@@ -156,16 +166,17 @@ android {
                     exclude 'org/mozilla/gecko/ChromeCastDisplay.java'
                     exclude 'org/mozilla/gecko/ChromeCastPlayer.java'
                     exclude 'org/mozilla/gecko/GeckoMediaPlayer.java'
                     exclude 'org/mozilla/gecko/GeckoPresentationDisplay.java'
                     exclude 'org/mozilla/gecko/MediaPlayerManager.java'
                 }
 
                 if (mozconfig.substs.MOZ_WEBRTC) {
+                    srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/base/java/src"
                     srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/audio_device/android/java/src"
                     srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src"
                     srcDir "${topsrcdir}/media/webrtc/trunk/webrtc/modules/video_render/android/java/src"
                 }
 
                 if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
                     exclude 'org/mozilla/gecko/adjust/StubAdjustHelper.java'
                 } else {
@@ -546,8 +557,22 @@ android.applicationVariants.all { varian
                         .each { it.replaceNode {} }
 
                     manifestOutFile.write(XmlUtil.serialize(xml), 'UTF-8')
                 }
             })
         }
     }
 }
+
+// Bug 1355625: strip extra .class files from Gradle builds; modified from
+// http://stackoverflow.com/a/40705699.
+android.applicationVariants.all { variant ->
+    variant.javaCompile.doLast {
+        // BuildConfig is not part of release builds, but it is required by the
+        // local unit tests of the android-test job.  Since the debug buildType
+        // is overloaded as the release type (see comments above), we have to
+        // keep the BuildConfig for testing.
+        // delete fileTree(dir: "${project.buildDir}", include: '**/org/mozilla/gecko/BuildConfig.class')
+        delete fileTree(dir: "${project.buildDir}", include: '**/org/mozilla/gecko/Manifest.class')
+        delete fileTree(dir: "${project.buildDir}", include: '**/org/mozilla/gecko/Manifest$permission.class')
+    }
+}
--- a/mobile/android/thirdparty/build.gradle
+++ b/mobile/android/thirdparty/build.gradle
@@ -64,8 +64,16 @@ idea {
             excludeDirs += file('com/leanplum')
         }
     }
 }
 
 // Bug 1353055 - Strip 'vars' debugging information to agree with moz.build.
 apply from: "${topsrcdir}/mobile/android/gradle/debug_level.gradle"
 android.libraryVariants.all configureVariantDebugLevel
+
+// Bug 1355625: strip extra .class files from Gradle builds; modified from
+// http://stackoverflow.com/a/40705699.
+android.libraryVariants.all { variant ->
+    variant.javaCompile.doLast {
+        delete fileTree(dir: "${project.buildDir}", include: "**/org/mozilla/gecko/thirdparty_unused/BuildConfig.class")
+    }
+}
--- a/settings.gradle
+++ b/settings.gradle
@@ -48,8 +48,14 @@ if (json.substs.MOZ_ANDROID_PACKAGE_INST
 // The Gradle instance is shared between settings.gradle and all the
 // other build.gradle files (see
 // http://forums.gradle.org/gradle/topics/define_extension_properties_from_settings_xml).
 // We use this ext property to pass the per-object-directory mozconfig
 // between scripts.  This lets us execute set-up code before we gradle
 // tries to configure the project even once, and as a side benefit
 // saves invoking |mach environment| multiple times.
 gradle.ext.mozconfig = json
+
+if (!gradle.ext.mozconfig.substs.COMPILE_ENVIRONMENT) {
+    // These should really come from the included binaries, but that's not easy.
+    gradle.ext.mozconfig.substs.TARGET_XPCOM_ABI = 'arm-eabi-gcc3'
+}
+gradle.ext.mozconfig.substs.MOZ_APP_ABI = gradle.ext.mozconfig.substs.TARGET_XPCOM_ABI