Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit c48a870

Browse files
committed
Bug 1233238 - Compile with play-services-{ads,analytics,appindexing} to support Adjust SDK. r=nalexander
On a CLOSED TREE because this is Android only. 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. --HG-- extra : commitid : I4rTyC8lxLd extra : rebase_source : 96f30d735e898cb9853d53f236ac8e2337186814 extra : amend_source : 3e4d68789b3ef980e4e1d7f743e332bdbb6be176
1 parent 0713020 commit c48a870

5 files changed

Lines changed: 95 additions & 0 deletions

File tree

build/autoconf/android.m4

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,19 @@ fi
356356
357357
])
358358

359+
AC_DEFUN([MOZ_ANDROID_INSTALL_TRACKING],
360+
[
361+
362+
if test -n "$MOZ_INSTALL_TRACKING"; then
363+
AC_SUBST(MOZ_INSTALL_TRACKING)
364+
MOZ_ANDROID_AAR(play-services-ads, 8.1.0, google, com/google/android/gms)
365+
MOZ_ANDROID_AAR(play-services-analytics, 8.1.0, google, com/google/android/gms)
366+
MOZ_ANDROID_AAR(play-services-appindexing, 8.1.0, google, com/google/android/gms)
367+
MOZ_ANDROID_AAR(play-services-basement, 8.1.0, google, com/google/android/gms)
368+
fi
369+
370+
])
371+
359372
dnl Configure an Android SDK.
360373
dnl Arg 1: target SDK version, like 22.
361374
dnl Arg 2: build tools version, like 22.0.1.

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,7 @@ dnl ========================================================
46604660

46614661
MOZ_ANDROID_GOOGLE_PLAY_SERVICES
46624662
MOZ_ANDROID_GOOGLE_CLOUD_MESSAGING
4663+
MOZ_ANDROID_INSTALL_TRACKING
46634664

46644665

46654666
dnl ========================================================

mobile/android/app/base/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ dependencies {
116116
compile 'com.google.android.gms:play-services-cast:8.1.0'
117117
}
118118

119+
if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
120+
compile 'com.google.android.gms:play-services-ads:8.1.0'
121+
compile 'com.google.android.gms:play-services-analytics:8.1.0'
122+
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
123+
compile 'com.google.android.gms:play-services-basement:8.1.0'
124+
}
125+
119126
if (mozconfig.substs.MOZ_ANDROID_GCM) {
120127
compile 'com.google.android.gms:play-services-basement:8.1.0'
121128
compile 'com.google.android.gms:play-services-base:8.1.0'

mobile/android/base/Makefile.in

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ ifdef MOZ_ANDROID_GCM
8282
$(NULL)
8383
endif
8484

85+
ifdef MOZ_INSTALL_TRACKING
86+
JAVA_CLASSPATH += \
87+
$(ANDROID_PLAY_SERVICES_ADS_AAR_LIB) \
88+
$(ANDROID_PLAY_SERVICES_ANALYTICS_AAR_LIB) \
89+
$(ANDROID_PLAY_SERVICES_APPINDEXING_AAR_LIB) \
90+
$(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
91+
$(NULL)
92+
endif
93+
8594
JAVA_CLASSPATH := $(subst $(NULL) ,:,$(strip $(JAVA_CLASSPATH)))
8695

8796
# Library jars that we're bundling: these are subject to Proguard before inclusion
@@ -112,6 +121,15 @@ ifdef MOZ_ANDROID_GCM
112121
$(NULL)
113122
endif
114123

124+
ifdef MOZ_INSTALL_TRACKING
125+
java_bundled_libs += \
126+
$(ANDROID_PLAY_SERVICES_ADS_AAR_LIB) \
127+
$(ANDROID_PLAY_SERVICES_ANALYTICS_AAR_LIB) \
128+
$(ANDROID_PLAY_SERVICES_APPINDEXING_AAR_LIB) \
129+
$(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
130+
$(NULL)
131+
endif
132+
115133
# uniq purloined from http://stackoverflow.com/a/16151140.
116134
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
117135

@@ -157,6 +175,30 @@ library_jars := \
157175
$(ANDROID_SDK)/android.jar \
158176
$(NULL)
159177

178+
# Android 23 (Marshmallow) deprecated a part of the Android platform, namely the
179+
# org.apache.http package. Fennec removed all code that referenced said package
180+
# in order to easily ship to Android 23 devices (and, by extension, all devices
181+
# before Android 23).
182+
#
183+
# Google did not remove all code that referenced said package in their own
184+
# com.google.android.gms namespace! It turns out that the org.apache.http
185+
# package is not removed, only deprecated and hidden by default. Google added a
186+
# a `useLibrary` Gradle directive that allows legacy code to reference the
187+
# package, which is still (hidden) in the Android 23 platform.
188+
#
189+
# Fennec code doesn't need to compile against the deprecated package, since our
190+
# code doesn't reference the package anymore. However, we do need to Proguard
191+
# against the deprecated package. If we don't, Proguard -- which is a global
192+
# optimization -- sees Google libraries referencing "non-existent" libraries and
193+
# complains. The solution is to mimic the `useLibraries` directive by declaring
194+
# the legacy package as a provided library jar.
195+
#
196+
# See https://bugzilla.mozilla.org/show_bug.cgi?id=1233238#c19 for symptoms and
197+
# more discussion.
198+
ifdef MOZ_INSTALL_TRACKING
199+
library_jars += $(ANDROID_SDK)/optional/org.apache.http.legacy.jar
200+
endif # MOZ_INSTALL_TRACKING
201+
160202
library_jars := $(subst $(NULL) ,:,$(strip $(library_jars)))
161203

162204
classes.dex: .proguard.deps
@@ -389,6 +431,9 @@ generated/android/support/design/R.java: .aapt.deps ;
389431
generated/android/support/v7/mediarouter/R.java: .aapt.deps ;
390432
generated/android/support/v7/recyclerview/R.java: .aapt.deps ;
391433
generated/com/google/android/gms/R.java: .aapt.deps ;
434+
generated/com/google/android/gms/ads/R.java: .aapt.deps ;
435+
generated/com/google/android/gms/analytics/R.java: .aapt.deps ;
436+
generated/com/google/android/gms/appindexing/R.java: .aapt.deps ;
392437
generated/com/google/android/gms/base/R.java: .aapt.deps ;
393438
generated/com/google/android/gms/cast/R.java: .aapt.deps ;
394439
generated/com/google/android/gms/gcm/R.java: .aapt.deps ;

mobile/android/base/moz.build

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,35 @@ if CONFIG['MOZ_ANDROID_GCM']:
741741
ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_GCM_AAR_RES']]
742742
resjar.generated_sources += ['com/google/android/gms/gcm/R.java']
743743

744+
if CONFIG['MOZ_INSTALL_TRACKING']:
745+
gbjar.extra_jars += [
746+
CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR_LIB'],
747+
CONFIG['ANDROID_PLAY_SERVICES_ANALYTICS_AAR_LIB'],
748+
CONFIG['ANDROID_PLAY_SERVICES_APPINDEXING_AAR_LIB'],
749+
CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB'],
750+
]
751+
752+
if CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR']:
753+
ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.ads']
754+
ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR_RES']]
755+
resjar.generated_sources += ['com/google/android/gms/ads/R.java']
756+
757+
if CONFIG['ANDROID_PLAY_SERVICES_ANALYTICS_AAR']:
758+
ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.analytics']
759+
ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_ANALYTICS_AAR_RES']]
760+
resjar.generated_sources += ['com/google/android/gms/analytics/R.java']
761+
762+
if CONFIG['ANDROID_PLAY_SERVICES_APPINDEXING_AAR']:
763+
ANDROID_EXTRA_PACKAGES += ['com.google.android.gms.appindexing']
764+
ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_APPINDEXING_AAR_RES']]
765+
resjar.generated_sources += ['com/google/android/gms/appindexing/R.java']
766+
767+
768+
if CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR']:
769+
ANDROID_EXTRA_PACKAGES += ['com.google.android.gms']
770+
ANDROID_EXTRA_RES_DIRS += ['%' + CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR_RES']]
771+
resjar.generated_sources += ['com/google/android/gms/R.java']
772+
744773
gbjar.extra_jars += [CONFIG['ANDROID_APPCOMPAT_V7_AAR_LIB']]
745774
gbjar.extra_jars += [CONFIG['ANDROID_DESIGN_AAR_LIB']]
746775
gbjar.extra_jars += [CONFIG['ANDROID_RECYCLERVIEW_V7_AAR_LIB']]

0 commit comments

Comments
 (0)