Bug 1355625 - Part 2: Tweak the Gradle build to agree more with moz.build. r=nalexander
authorNick Alexander <nalexander@mozilla.com>
Tue, 20 Jun 2017 11:19:32 -0700
changeset 404237 0b7af9b62aff574eec690d4136d19e431abf2708
parent 404236 b44a1a078e6445f84c1a8f92af6b13f0c5f7b6db
child 404238 114095814191ba58c741c045dd1d501993607de7
push id57
push userfmarier@mozilla.com
push dateSat, 24 Jun 2017 00:05:50 +0000
reviewersnalexander
bugs1355625
milestone56.0a1
Bug 1355625 - Part 2: Tweak the Gradle build to agree more with moz.build. r=nalexander 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"
         jumboMode = true
     }
 
     lintOptions {
         abortOnError true
     }
@@ -132,16 +136,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'
                 }
 
@@ -539,8 +549,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