Bug 1320310 - Post-process Gradle-produced Android manifest. r=sebastian draft
authorNick Alexander <nalexander@mozilla.com>
Tue, 11 Apr 2017 20:49:05 -0700
changeset 561396 c9aff7c414c13843c4e54267c95941fa35bc1001
parent 560546 abf145ebd05fe105efbc78b761858c34f7690154
child 623967 a0ed254e0ac7c69fa53a25e4ce321d5e81376983
push id53722
push usernalexander@mozilla.com
push dateWed, 12 Apr 2017 16:27:32 +0000
reviewerssebastian
bugs1320310
milestone55.0a1
Bug 1320310 - Post-process Gradle-produced Android manifest. r=sebastian Layer on the hacks! This: 1) Reinstates the <activity-alias android:name=".App"> that we have in the moz.build produced Android manifest. I found no way to do this using placeholders or the manifest merger. 2) Culls manifest entries provided by com.google.android.gms.measurement. We know they're not necessary, since they're not present in the existing Fennec Android manifest. These are strictly workarounds to avoid doing the real work of fixing the issues. To fix 1), we'd need to migrate all existing users with homescreen shortcuts to .App. This could be difficult, especially if partners have deployed packages out of our update control. To fix 2), we'll need to upgrade our Google Play Services to at least version 9.0.0 and then use the finer-grained AAR dependencies to not build with the measurement split at all. MozReview-Commit-ID: 21CaZ2KMeIa
mobile/android/app/build.gradle
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -447,8 +447,42 @@ android.applicationVariants.all { varian
 
         dependsOn "assemble${variant.name.capitalize()}"
     }
 }
 
 // Bug 1353055 - Strip 'vars' debugging information to agree with moz.build.
 apply from: "${topsrcdir}/mobile/android/gradle/debug_level.gradle"
 android.applicationVariants.all configureVariantDebugLevel
+
+
+// Bug 1320310 - Hack up the manifest produced by Gradle to match that produced
+// by moz.build.
+import groovy.xml.XmlUtil
+
+android.applicationVariants.all { variant ->
+    variant.outputs.each { output ->
+        output.processManifest.doLast {
+            [output.processManifest.manifestOutputFile,
+             output.processManifest.instantRunManifestOutputFile,
+            ].each({ File manifestOutFile ->
+                if (manifestOutFile.exists()) {
+                    def contents = manifestOutFile.getText('UTF-8')
+
+                    // A non-validating, non-namespace aware XML processor.
+                    def xml = new XmlSlurper(false, false).parseText(contents)
+
+                    // First, reinstate our <activity-alias android:name=".App">.
+                    xml.depthFirst()
+                        .findAll { it.name() == 'activity-alias' && it.'@android:name' == 'org.mozilla.gecko.App' }
+                        .each { it.'@android:name' = '.App' }
+
+                    // Second, cull all manifest entries provided by com.google.android.gms.measurement.
+                    xml.depthFirst()
+                        .findAll { it.'@android:name'.text().contains('AppMeasurement') }
+                        .each { it.replaceNode {} }
+
+                    manifestOutFile.write(XmlUtil.serialize(xml), 'UTF-8')
+                }
+            })
+        }
+    }
+}