Bug 1233238 - Compile with play-services-{ads,analytics,appindexing} to support Adjust SDK. r=nalexander draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 04 Feb 2016 16:10:29 -0800
changeset 329889 96f30d735e898cb9853d53f236ac8e2337186814
parent 329874 517676505f44d907b04319f8dc631e1c01f7cefe
child 514052 1234641dad85e1cdf2ba49d21592293f24f92a96
push id10626
push usernalexander@mozilla.com
push dateTue, 09 Feb 2016 19:50:32 +0000
reviewersnalexander
bugs1233238, 1115004
milestone47.0a1
Bug 1233238 - Compile with play-services-{ads,analytics,appindexing} to support Adjust SDK. r=nalexander When we switched to fine-grained Google Play Services bundling (Bug 1115004), we stopped shipping com.google.android.gms.analytics. That silently breaks Adjust, which queries the Google Ad ID using reflection: now the package isn't present! This patch restores the Play Services libraries that Adjust relies on. (Sadly, this bloats our APK tremendously.) There is some hijinkery, however: the Play Services libraries reference a library (org.apache.http) that is deprecated in Android 23! However, the library is still present on Android 23 devices, which buys Google time to replace the offending code. This compiles just fine, breaks the Proguard global optimization pass. To give Proguard the information, we add the library as a Proguard "library JAR". This is equivalent to the Google-provided Gradle `useLibrary` directive.
build/autoconf/android.m4
configure.in
mobile/android/app/base/build.gradle
mobile/android/base/Makefile.in
mobile/android/base/moz.build
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -351,16 +351,29 @@ if test -n "$MOZ_ANDROID_GCM" ; then
 
     MOZ_ANDROID_AAR(play-services-base, 8.1.0, google, com/google/android/gms)
     MOZ_ANDROID_AAR(play-services-basement, 8.1.0, google, com/google/android/gms)
     MOZ_ANDROID_AAR(play-services-gcm, 8.1.0, google, com/google/android/gms)
 fi
 
 ])
 
+AC_DEFUN([MOZ_ANDROID_INSTALL_TRACKING],
+[
+
+if test -n "$MOZ_INSTALL_TRACKING"; then
+    AC_SUBST(MOZ_INSTALL_TRACKING)
+    MOZ_ANDROID_AAR(play-services-ads, 8.1.0, google, com/google/android/gms)
+    MOZ_ANDROID_AAR(play-services-analytics, 8.1.0, google, com/google/android/gms)
+    MOZ_ANDROID_AAR(play-services-appindexing, 8.1.0, google, com/google/android/gms)
+    MOZ_ANDROID_AAR(play-services-basement, 8.1.0, google, com/google/android/gms)
+fi
+
+])
+
 dnl Configure an Android SDK.
 dnl Arg 1: target SDK version, like 22.
 dnl Arg 2: build tools version, like 22.0.1.
 AC_DEFUN([MOZ_ANDROID_SDK],
 [
 
 MOZ_ARG_WITH_STRING(android-sdk,
 [  --with-android-sdk=DIR
--- a/configure.in
+++ b/configure.in
@@ -4655,16 +4655,17 @@ AC_SUBST(MOZ_DISTRIBUTION_ID)
 
 dnl ========================================================
 dnl Google Play Services, placed here so it can depend on
 dnl values set by configure.sh above.
 dnl ========================================================
 
 MOZ_ANDROID_GOOGLE_PLAY_SERVICES
 MOZ_ANDROID_GOOGLE_CLOUD_MESSAGING
+MOZ_ANDROID_INSTALL_TRACKING
 
 
 dnl ========================================================
 dnl = Pango
 dnl ========================================================
 if test "$MOZ_ENABLE_GTK" -o "$MOZ_ENABLE_QT"
 then
     PKG_CHECK_MODULES(_PANGOCHK, pango >= $PANGO_VERSION)
--- a/mobile/android/app/base/build.gradle
+++ b/mobile/android/app/base/build.gradle
@@ -111,16 +111,23 @@ dependencies {
 
     if (mozconfig.substs.MOZ_NATIVE_DEVICES) {
         compile 'com.android.support:mediarouter-v7:23.0.1'
         compile 'com.google.android.gms:play-services-basement:8.1.0'
         compile 'com.google.android.gms:play-services-base:8.1.0'
         compile 'com.google.android.gms:play-services-cast:8.1.0'
     }
 
+    if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
+        compile 'com.google.android.gms:play-services-ads:8.1.0'
+        compile 'com.google.android.gms:play-services-analytics:8.1.0'
+        compile 'com.google.android.gms:play-services-appindexing:8.1.0'
+        compile 'com.google.android.gms:play-services-basement:8.1.0'
+    }
+
     if (mozconfig.substs.MOZ_ANDROID_GCM) {
         compile 'com.google.android.gms:play-services-basement:8.1.0'
         compile 'com.google.android.gms:play-services-base:8.1.0'
         compile 'com.google.android.gms:play-services-gcm:8.1.0'
     }
 
     // Gradle based builds include LeakCanary. Mach based builds only include the no-op version of
     // this library.
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -77,16 +77,25 @@ endif
 ifdef MOZ_ANDROID_GCM
     JAVA_CLASSPATH += \
         $(ANDROID_PLAY_SERVICES_BASE_AAR_LIB) \
         $(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
         $(ANDROID_PLAY_SERVICES_GCM_AAR_LIB) \
         $(NULL)
 endif
 
+ifdef MOZ_INSTALL_TRACKING
+    JAVA_CLASSPATH += \
+        $(ANDROID_PLAY_SERVICES_ADS_AAR_LIB) \
+        $(ANDROID_PLAY_SERVICES_ANALYTICS_AAR_LIB) \
+        $(ANDROID_PLAY_SERVICES_APPINDEXING_AAR_LIB) \
+        $(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
+        $(NULL)
+endif
+
 JAVA_CLASSPATH := $(subst $(NULL) ,:,$(strip $(JAVA_CLASSPATH)))
 
 # Library jars that we're bundling: these are subject to Proguard before inclusion
 # into classes.dex.
 java_bundled_libs := \
     $(ANDROID_SUPPORT_V4_AAR_LIB) \
     $(ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB) \
     $(ANDROID_APPCOMPAT_V7_AAR_LIB) \
@@ -107,16 +116,25 @@ endif
 ifdef MOZ_ANDROID_GCM
     java_bundled_libs += \
         $(ANDROID_PLAY_SERVICES_BASE_AAR_LIB) \
         $(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
         $(ANDROID_PLAY_SERVICES_GCM_AAR_LIB) \
         $(NULL)
 endif
 
+ifdef MOZ_INSTALL_TRACKING
+    java_bundled_libs += \
+        $(ANDROID_PLAY_SERVICES_ADS_AAR_LIB) \
+        $(ANDROID_PLAY_SERVICES_ANALYTICS_AAR_LIB) \
+        $(ANDROID_PLAY_SERVICES_APPINDEXING_AAR_LIB) \
+        $(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
+        $(NULL)
+endif
+
 # uniq purloined from http://stackoverflow.com/a/16151140.
 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 
 java_bundled_libs := $(call uniq,$(java_bundled_libs))
 java_bundled_libs := $(subst $(NULL) ,:,$(strip $(java_bundled_libs)))
 
 # All the jars we're compiling from source. (not to be confused with
 # java_bundled_libs, which holds the jars which we're including as binaries).
@@ -152,16 +170,40 @@ endif
 all_jars_classpath := $(subst $(NULL) ,:,$(strip $(ALL_JARS)))
 
 include $(topsrcdir)/config/config.mk
 
 library_jars := \
     $(ANDROID_SDK)/android.jar \
     $(NULL)
 
+# Android 23 (Marshmallow) deprecated a part of the Android platform, namely the
+# org.apache.http package.  Fennec removed all code that referenced said package
+# in order to easily ship to Android 23 devices (and, by extension, all devices
+# before Android 23).
+#
+# Google did not remove all code that referenced said package in their own
+# com.google.android.gms namespace!  It turns out that the org.apache.http
+# package is not removed, only deprecated and hidden by default.  Google added a
+# a `useLibrary` Gradle directive that allows legacy code to reference the
+# package, which is still (hidden) in the Android 23 platform.
+#
+# Fennec code doesn't need to compile against the deprecated package, since our
+# code doesn't reference the package anymore.  However, we do need to Proguard
+# against the deprecated package.  If we don't, Proguard -- which is a global
+# optimization -- sees Google libraries referencing "non-existent" libraries and
+# complains.  The solution is to mimic the `useLibraries` directive by declaring
+# the legacy package as a provided library jar.
+#
+# See https://bugzilla.mozilla.org/show_bug.cgi?id=1233238#c19 for symptoms and
+# more discussion.
+ifdef MOZ_INSTALL_TRACKING
+library_jars += $(ANDROID_SDK)/optional/org.apache.http.legacy.jar
+endif # MOZ_INSTALL_TRACKING
+
 library_jars := $(subst $(NULL) ,:,$(strip $(library_jars)))
 
 classes.dex: .proguard.deps
 	$(REPORT_BUILD)
 	$(DX) --dex --output=classes.dex jars-proguarded
 
 ifdef MOZ_DISABLE_PROGUARD
   PROGUARD_PASSES=0
@@ -384,16 +426,19 @@ generated/org/mozilla/gecko/R.java: .aap
 
 # If native devices are enabled, add Google Play Services, build their resources
 generated/android/support/v4/R.java: .aapt.deps ;
 generated/android/support/v7/appcompat/R.java: .aapt.deps ;
 generated/android/support/design/R.java: .aapt.deps ;
 generated/android/support/v7/mediarouter/R.java: .aapt.deps ;
 generated/android/support/v7/recyclerview/R.java: .aapt.deps ;
 generated/com/google/android/gms/R.java: .aapt.deps ;
+generated/com/google/android/gms/ads/R.java: .aapt.deps ;
+generated/com/google/android/gms/analytics/R.java: .aapt.deps ;
+generated/com/google/android/gms/appindexing/R.java: .aapt.deps ;
 generated/com/google/android/gms/base/R.java: .aapt.deps ;
 generated/com/google/android/gms/cast/R.java: .aapt.deps ;
 generated/com/google/android/gms/gcm/R.java: .aapt.deps ;
 
 gecko.ap_: .aapt.deps ;
 R.txt: .aapt.deps ;
 
 # [Comment 2/3] This tom-foolery provides a target that forces a
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -736,16 +736,45 @@ if CONFIG['MOZ_ANDROID_GCM']:
         ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR_RES']]
         resjar.generated_sources += ['com/google/android/gms/R.java']
 
     if CONFIG['ANDROID_PLAY_SERVICES_GCM_AAR']:
         ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.gcm']
         ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_GCM_AAR_RES']]
         resjar.generated_sources += ['com/google/android/gms/gcm/R.java']
 
+if CONFIG['MOZ_INSTALL_TRACKING']:
+    gbjar.extra_jars += [
+        CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_ANALYTICS_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_APPINDEXING_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB'],
+    ]
+
+    if CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR']:
+        ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.ads']
+        ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR_RES']]
+        resjar.generated_sources += ['com/google/android/gms/ads/R.java']
+
+    if CONFIG['ANDROID_PLAY_SERVICES_ANALYTICS_AAR']:
+        ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.analytics']
+        ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_ANALYTICS_AAR_RES']]
+        resjar.generated_sources += ['com/google/android/gms/analytics/R.java']
+
+    if CONFIG['ANDROID_PLAY_SERVICES_APPINDEXING_AAR']:
+        ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.appindexing']
+        ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_APPINDEXING_AAR_RES']]
+        resjar.generated_sources += ['com/google/android/gms/appindexing/R.java']
+
+
+    if CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR']:
+        ANDROID_EXTRA_PACKAGES += ['com.google.android.gms']
+        ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR_RES']]
+        resjar.generated_sources += ['com/google/android/gms/R.java']
+
 gbjar.extra_jars += [CONFIG['ANDROID_APPCOMPAT_V7_AAR_LIB']]
 gbjar.extra_jars += [CONFIG['ANDROID_DESIGN_AAR_LIB']]
 gbjar.extra_jars += [CONFIG['ANDROID_RECYCLERVIEW_V7_AAR_LIB']]
 
 gbjar.javac_flags += ['-Xlint:all,-deprecation,-fallthrough', '-J-Xmx512m', '-J-Xms128m']
 
 # gecko-thirdparty is a good place to put small independent libraries
 gtjar = add_java_jar('gecko-thirdparty')