Bug 1006158 - Add ability to pull in v7 libraries and google support libraries. r=nalexander
authorWes Johnston <wjohnston@mozilla.com>
Wed, 11 Jun 2014 11:00:17 -0700
changeset 209229 a2b9ea476e59464f554b510ae8389cbca115fad2
parent 209228 626291e664abd1047d569220e4d4b239f10bae49
child 209230 9451a90e1b7a4ad6e12cbd9fa475822e969feb9e
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1006158
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1006158 - Add ability to pull in v7 libraries and google support libraries. r=nalexander
build/autoconf/android.m4
build/mobile/robocop/Makefile.in
config/android-common.mk
mobile/android/base/AndroidManifest.xml.in
mobile/android/base/Makefile.in
mobile/android/base/moz.build
mobile/android/config/proguard.cfg
mobile/android/confvars.sh
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -319,29 +319,71 @@ case "$target" in
     if test -d "$android_build_tools" -a -f "$android_build_tools/aapt"; then
         AC_MSG_RESULT([$android_build_tools])
     else
         AC_MSG_ERROR([not found. Please check your SDK for the subdirectory of build-tools. With the current configuration, it should be in $android_sdk_root/build_tools])
     fi
 
     ANDROID_SDK="${android_sdk}"
     ANDROID_SDK_ROOT="${android_sdk_root}"
-    if test -e "${ANDROID_SDK_ROOT}/extras/android/compatibility/v4/android-support-v4.jar" ; then
-        ANDROID_COMPAT_LIB="${ANDROID_SDK_ROOT}/extras/android/compatibility/v4/android-support-v4.jar"
+
+    AC_MSG_CHECKING([for compat library dirs])
+    if test -e "${android_sdk_root}/extras/android/compatibility/v4/android-support-v4.jar" ; then
+        ANDROID_COMPAT_DIR_BASE="${android_sdk_root}/extras/android/compatibility";
     else
-        ANDROID_COMPAT_LIB="${ANDROID_SDK_ROOT}/extras/android/support/v4/android-support-v4.jar";
+        ANDROID_COMPAT_DIR_BASE="${android_sdk_root}/extras/android/support";
     fi
+    AC_MSG_RESULT([$ANDROID_COMPAT_DIR_BASE])
+
     ANDROID_TOOLS="${android_tools}"
     ANDROID_PLATFORM_TOOLS="${android_platform_tools}"
     ANDROID_BUILD_TOOLS="${android_build_tools}"
     AC_SUBST(ANDROID_SDK_ROOT)
     AC_SUBST(ANDROID_SDK)
+
+    ANDROID_COMPAT_LIB=$ANDROID_COMPAT_DIR_BASE/v4/android-support-v4.jar
+    AC_MSG_CHECKING([for v4 compat library])
     AC_SUBST(ANDROID_COMPAT_LIB)
     if ! test -e $ANDROID_COMPAT_LIB ; then
-        AC_MSG_ERROR([You must download the Android support library when targeting Android.   Run the Android SDK tool and install Android Support Library under Extras.  See https://developer.android.com/tools/extras/support-library.html for more info. (looked for $ANDROID_COMPAT_LIB)])
+        AC_MSG_ERROR([You must download the Android v4 support library when targeting Android.  Run the Android SDK tool and install Android Support Library under Extras.  See https://developer.android.com/tools/extras/support-library.html for more info. (looked for $ANDROID_COMPAT_LIB)])
+    fi
+    AC_MSG_RESULT([$ANDROID_COMPAT_LIB])
+
+    if test -n "$MOZ_NATIVE_DEVICES" ; then
+        AC_SUBST(MOZ_NATIVE_DEVICES)
+
+        AC_MSG_CHECKING([for google play services])
+        GOOGLE_PLAY_SERVICES_LIB="${ANDROID_SDK_ROOT}/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"
+        GOOGLE_PLAY_SERVICES_RES="${ANDROID_SDK_ROOT}/extras/google/google_play_services/libproject/google-play-services_lib/res"
+        AC_SUBST(GOOGLE_PLAY_SERVICES_LIB)
+        AC_SUBST(GOOGLE_PLAY_SERVICES_RES)
+        if ! test -e $GOOGLE_PLAY_SERVICES_LIB ; then
+            AC_MSG_ERROR([You must download Google Play Services to build with native video casting support enabled.  Run the Android SDK tool and install Google Play Services under Extras.  See http://developer.android.com/google/play-services/setup.html for more info. (looked for $GOOGLE_PLAY_SERVICES_LIB) ])
+        fi
+        AC_MSG_RESULT([$GOOGLE_PLAY_SERVICES_LIB])
+
+        ANDROID_APPCOMPAT_LIB="$ANDROID_COMPAT_DIR_BASE/v7/appcompat/libs/android-support-v7-appcompat.jar"
+        ANDROID_APPCOMPAT_RES="$ANDROID_COMPAT_DIR_BASE/v7/appcompat/res"
+        AC_MSG_CHECKING([for v7 appcompat library])
+        if ! test -e $ANDROID_APPCOMPAT_LIB ; then
+            AC_MSG_ERROR([You must download the v7 app compat Android support library when targeting Android with native video casting support enabled.  Run the Android SDK tool and install Android Support Library under Extras.  See https://developer.android.com/tools/extras/support-library.html for more info. (looked for $ANDROID_APPCOMPAT_LIB)])
+        fi
+        AC_MSG_RESULT([$ANDROID_APPCOMPAT_LIB])
+        AC_SUBST(ANDROID_APPCOMPAT_LIB)
+        AC_SUBST(ANDROID_APPCOMPAT_RES)
+
+        ANDROID_MEDIAROUTER_LIB="$ANDROID_COMPAT_DIR_BASE/v7/mediarouter/libs/android-support-v7-mediarouter.jar"
+        ANDROID_MEDIAROUTER_RES="$ANDROID_COMPAT_DIR_BASE/v7/mediarouter/res"
+        AC_MSG_CHECKING([for v7 mediarouter library])
+        if ! test -e $ANDROID_MEDIAROUTER_LIB ; then
+            AC_MSG_ERROR([You must download the v7 media router Android support library when targeting Android with native video casting support enabled.  Run the Android SDK tool and install Android Support Library under Extras.  See https://developer.android.com/tools/extras/support-library.html for more info. (looked for $ANDROID_MEDIAROUTER_LIB)])
+        fi
+        AC_MSG_RESULT([$ANDROID_MEDIAROUTER_LIB])
+        AC_SUBST(ANDROID_MEDIAROUTER_LIB)
+        AC_SUBST(ANDROID_MEDIAROUTER_RES)
     fi
 
     MOZ_PATH_PROG(ZIPALIGN, zipalign, :, [$ANDROID_TOOLS])
     MOZ_PATH_PROG(DX, dx, :, [$ANDROID_BUILD_TOOLS])
     MOZ_PATH_PROG(AAPT, aapt, :, [$ANDROID_BUILD_TOOLS])
     MOZ_PATH_PROG(AIDL, aidl, :, [$ANDROID_BUILD_TOOLS])
     MOZ_PATH_PROG(ADB, adb, :, [$ANDROID_PLATFORM_TOOLS])
 
--- a/build/mobile/robocop/Makefile.in
+++ b/build/mobile/robocop/Makefile.in
@@ -90,12 +90,12 @@ include $(topsrcdir)/config/rules.mk
 tools:: $(ANDROID_APK_NAME).apk
 
 GENERATED_DIRS += $(dir-tests)
 
 # The test APK needs to know the contents of the target APK while not
 # being linked against them.  This is a best effort to avoid getting
 # out of sync with base's build config.
 JARS_DIR := $(DEPTH)/mobile/android/base
-JAVA_BOOTCLASSPATH := $(JAVA_BOOTCLASSPATH):$(subst $(NULL) ,:,$(wildcard $(JARS_DIR)/*.jar))
+JAVA_BOOTCLASSPATH := $(JAVA_BOOTCLASSPATH):$(subst $(NULL) ,:,$(wildcard $(JARS_DIR)/*.jar)):$(ANDROID_COMPAT_LIB)
 # We also want to re-compile classes.dex when the associated base
 # content changes.
 classes.dex: $(wildcard $(JARS_DIR)/*.jar)
--- a/config/android-common.mk
+++ b/config/android-common.mk
@@ -1,39 +1,35 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# Ensure JAVA_CLASSPATH and ANDROID_SDK are defined before including this file.
+# Ensure ANDROID_SDK is defined before including this file.
 # We use common android defaults for boot class path and java version.
 ifndef ANDROID_SDK
   $(error ANDROID_SDK must be defined before including android-common.mk)
 endif
 
-ifndef JAVA_CLASSPATH
-  $(error JAVA_CLASSPATH must be defined before including android-common.mk)
-endif
-
 # DEBUG_JARSIGNER always debug signs.
 DEBUG_JARSIGNER=$(PYTHON) $(abspath $(topsrcdir)/mobile/android/debug_sign_tool.py) \
   --keytool=$(KEYTOOL) \
   --jarsigner=$(JARSIGNER) \
   $(NULL)
 
 # For Android, this defaults to $(ANDROID_SDK)/android.jar
 ifndef JAVA_BOOTCLASSPATH
-  JAVA_BOOTCLASSPATH = $(ANDROID_SDK)/android.jar:$(ANDROID_COMPAT_LIB)
+  JAVA_BOOTCLASSPATH = $(ANDROID_SDK)/android.jar
 endif
 
 # For Android, we default to 1.5
 ifndef JAVA_VERSION
   JAVA_VERSION = 1.5
 endif
 
 JAVAC_FLAGS = \
   -target $(JAVA_VERSION) \
   -source $(JAVA_VERSION) \
-  -classpath $(JAVA_CLASSPATH) \
+  $(if $(JAVA_CLASSPATH),-classpath $(JAVA_CLASSPATH),) \
   -bootclasspath $(JAVA_BOOTCLASSPATH) \
   -encoding UTF8 \
   -g:source,lines \
   -Werror \
   $(NULL)
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -78,16 +78,21 @@
 #if !defined(MOZILLA_OFFICIAL) || defined(NIGHTLY_BUILD) && defined(MOZ_DEBUG)
                  android:debuggable="true">
 #else
                  android:debuggable="false">
 #endif
 
         <meta-data android:name="com.sec.android.support.multiwindow" android:value="true"/>
 
+#ifdef GOOGLE_PLAY_SERVICES
+        <!-- This resources comes from Google Play Services. Required for casting support. -->
+        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
+#endif
+
         <!-- If the windowSoftInputMode adjust* flag changes below, the
              setSoftInputMode call in BrowserSearch#onStop must also be updated. -->
         <activity android:name=".App"
                   android:label="@string/moz_app_displayname"
                   android:taskAffinity="@ANDROID_PACKAGE_NAME@.BROWSER"
                   android:alwaysRetainTaskState="true"
                   android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection"
                   android:windowSoftInputMode="stateUnspecified|adjustResize"
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -54,17 +54,33 @@ GARBAGE += \
   javah.out \
   jni-stubs.inc \
   GeneratedJNIWrappers.cpp \
   GeneratedJNIWrappers.h \
   $(NULL)
 
 GARBAGE_DIRS += classes db jars res sync services generated
 
-JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
+JAVA_BOOTCLASSPATH = \
+    $(ANDROID_SDK)/android.jar \
+    $(ANDROID_COMPAT_LIB) \
+    $(NULL)
+
+JAVA_BOOTCLASSPATH := $(subst $(NULL) ,:,$(strip $(JAVA_BOOTCLASSPATH)))
+
+# If native devices are enabled, add Google Play Services and some of the v7 compat libraries
+ifdef MOZ_NATIVE_DEVICES
+    JAVA_CLASSPATH += \
+        $(GOOGLE_PLAY_SERVICES_LIB) \
+        $(ANDROID_MEDIAROUTER_LIB) \
+        $(ANDROID_APPCOMPAT_LIB) \
+        $(NULL)
+endif
+
+JAVA_CLASSPATH := $(subst $(NULL) ,:,$(strip $(JAVA_CLASSPATH)))
 
 ALL_JARS = \
   gecko-R.jar \
   gecko-browser.jar \
   gecko-mozglue.jar \
   gecko-util.jar \
   squareup-picasso.jar \
   sync-thirdparty.jar \
@@ -78,19 +94,26 @@ endif
 include $(topsrcdir)/config/config.mk
 
 # Note that we're going to set up a dependency directly between embed_android.dex and the java files
 # Instead of on the .class files, since more than one .class file might be produced per .java file
 # Sync dependencies are provided in a single jar. Sync classes themselves are delivered as source,
 # because Android resource classes must be compiled together in order to avoid overlapping resource
 # indices.
 
+library_jars = \
+    $(JAVA_CLASSPATH) \
+    $(JAVA_BOOTCLASSPATH) \
+    $(NULL)
+
+library_jars := $(subst $(NULL) ,:,$(strip $(library_jars)))
+
 classes.dex: .proguard.deps
 	$(REPORT_BUILD)
-	$(DX) --dex --output=classes.dex jars-proguarded $(ANDROID_COMPAT_LIB)
+	$(DX) --dex --output=classes.dex jars-proguarded $(subst :, ,$(ANDROID_COMPAT_LIB):$(JAVA_CLASSPATH))
 
 ifdef MOZ_DISABLE_PROGUARD
   PROGUARD_PASSES=0
 else
   ifdef MOZ_DEBUG
     PROGUARD_PASSES=1
   else
     ifndef MOZILLA_OFFICIAL
@@ -108,17 +131,17 @@ endif
 .proguard.deps: $(ALL_JARS)
 	$(REPORT_BUILD)
 	@$(TOUCH) $@
 	java -jar $(ANDROID_SDK_ROOT)/tools/proguard/lib/proguard.jar \
 		@$(topsrcdir)/mobile/android/config/proguard.cfg \
 		-optimizationpasses $(PROGUARD_PASSES) \
 		-injars $(subst ::,:,$(subst $(NULL) ,:,$(strip $(ALL_JARS)))) \
 		-outjars jars-proguarded \
-		-libraryjars $(ANDROID_SDK)/android.jar:$(ANDROID_COMPAT_LIB)
+		-libraryjars $(library_jars)
 
 CLASSES_WITH_JNI= \
     org.mozilla.gecko.ANRReporter \
     org.mozilla.gecko.GeckoAppShell \
     org.mozilla.gecko.GeckoJavaSampler \
     org.mozilla.gecko.gfx.NativePanZoomController \
     org.mozilla.gecko.util.NativeJSContainer \
     org.mozilla.gecko.util.NativeJSObject \
@@ -136,41 +159,40 @@ endif
 jni-stubs.inc: gecko-browser.jar gecko-mozglue.jar gecko-util.jar sync-thirdparty.jar
 	$(JAVAH) -o javah.out -bootclasspath $(JAVA_BOOTCLASSPATH) -classpath $(subst $(NULL) $(NULL),:,$^) $(CLASSES_WITH_JNI)
 	$(PYTHON) $(topsrcdir)/mobile/android/base/jni-generator.py javah.out $@
 
 ANNOTATION_PROCESSOR_JAR_FILES := $(DEPTH)/build/annotationProcessors/annotationProcessors.jar
 
 GeneratedJNIWrappers.cpp: $(ANNOTATION_PROCESSOR_JAR_FILES)
 GeneratedJNIWrappers.cpp: $(ALL_JARS)
-	$(JAVA) -classpath gecko-mozglue.jar:$(JAVA_BOOTCLASSPATH):$(ANNOTATION_PROCESSOR_JAR_FILES) org.mozilla.gecko.annotationProcessors.AnnotationProcessor $(ALL_JARS)
+	$(JAVA) -classpath gecko-mozglue.jar:$(JAVA_BOOTCLASSPATH):$(JAVA_CLASSPATH):$(ANNOTATION_PROCESSOR_JAR_FILES) org.mozilla.gecko.annotationProcessors.AnnotationProcessor $(ALL_JARS)
 
-gecko_package_dir = generated/org/mozilla/gecko
 # Like generated/org/mozilla/fennec_$USERID.
 android_package_dir = $(addprefix generated/,$(subst .,/,$(ANDROID_PACKAGE_NAME)))
 
 # These _PP_JAVAFILES are specified in moz.build and defined in
 # backend.mk, which is included by config.mk.  Therefore this needs to
 # be defined after config.mk is included.
-PP_JAVAFILES := $(filter-out $(gecko_package_dir)/R.java,$(gecko-mozglue_PP_JAVAFILES) $(gecko-browser_PP_JAVAFILES))
+PP_JAVAFILES := $(filter-out generated/org/mozilla/gecko/R.java,$(gecko-mozglue_PP_JAVAFILES) $(gecko-browser_PP_JAVAFILES))
 
 manifest := \
   AndroidManifest.xml.in \
   WebappManifestFragment.xml.frag.in \
   $(NULL)
 
 PP_TARGETS += manifest
 
 # Certain source files need to be preprocessed.  This special rule
 # generates these files into generated/org/mozilla/gecko for
 # consumption by the build system and IDEs.
 
-preprocessed := $(addsuffix .in,$(subst $(gecko_package_dir)/,,$(filter $(gecko_package_dir)/%,$(PP_JAVAFILES))))
+preprocessed := $(addsuffix .in,$(subst generated/org/mozilla/gecko/,,$(filter generated/org/mozilla/gecko/%,$(PP_JAVAFILES))))
 
-preprocessed_PATH := $(gecko_package_dir)
+preprocessed_PATH := generated/org/mozilla/gecko
 preprocessed_KEEP_PATH := 1
 
 PP_TARGETS += preprocessed
 
 # Certain source files have Java package name @ANDROID_PACKAGE_NAME@.
 # We hate these files but they are necessary for backwards
 # compatibility.  These special rules generate these files into
 # generated/org/mozilla/{firefox,firefox_beta,fennec,fennec_$USER} for
@@ -217,16 +239,17 @@ android_res_files := $(filter-out $(not_
 # if any recipe command fails. It is crucial that the sub-Make touch
 # the target files (those depending on .locales.deps) only when there
 # contents have changed; otherwise, this will force rebuild them as
 # part of every build.
 .locales.deps: FORCE
 	$(TOUCH) $@
 	$(MAKE) -C locales
 
+
 # This .deps pattern saves an invocation of the sub-Make: the single
 # invocation generates both strings.xml and suggestedsites.json. The
 # trailing semi-colon defines an empty recipe: defining no recipe at
 # all causes Make to treat the target differently, in a way that
 # defeats our dependencies.
 res/values/strings.xml: .locales.deps ;
 res/raw/suggestedsites.json: .locales.deps ;
 
@@ -263,17 +286,34 @@ geckoview_resources.zip: $(all_resources
 	$(foreach dir,$(ANDROID_RES_DIRS),$(call zip_directory_with_relative_paths,$(CURDIR)/$@,$(dir)))
 
 # All of generated/org/mozilla/gecko/R.java, gecko.ap_, and R.txt are
 # produced by aapt; this saves aapt invocations.  The trailing
 # semi-colon defines an empty recipe; defining no recipe at all causes
 # Make to treat the target differently, in a way that defeats our
 # dependencies.
 
-$(gecko_package_dir)/R.java: .aapt.deps ;
+generated/org/mozilla/gecko/R.java: .aapt.deps ;
+
+# If native devices are enabled, add Google Play Services, build their resources
+generated/android/support/v7/appcompat/R.java: .aapt.deps ;
+generated/android/support/v7/mediarouter/R.java: .aapt.deps ;
+generated/com/google/android/gms/R.java: .aapt.deps ;
+
+ifdef MOZ_NATIVE_DEVICES
+    extra_packages += android.support.v7.appcompat
+    extra_res_dirs += $(ANDROID_APPCOMPAT_RES)
+
+    extra_packages += android.support.v7.mediarouter
+    extra_res_dirs += $(ANDROID_MEDIAROUTER_RES)
+
+    extra_packages += com.google.android.gms
+    extra_res_dirs += $(GOOGLE_PLAY_SERVICES_RES)
+endif
+
 gecko.ap_: .aapt.deps ;
 R.txt: .aapt.deps ;
 
 # [Comment 2/3] This tom-foolery provides a target that forces a
 # rebuild of gecko.ap_.  This is used during packaging to ensure that
 # resources are fresh.  The alternative would be complicated; see
 # [Comment 1/3].
 
@@ -284,52 +324,59 @@ gecko-nodeps/R.txt: .aapt.nodeps ;
 # This ignores the default set of resources ignored by aapt, plus
 # files starting with '#'.  (Emacs produces temp files named #temp#.)
 # This doesn't actually set the environment variable; it's used as a
 # parameter in the aapt invocation below.  Consider updating
 # not_android_res_files as well.
 
 ANDROID_AAPT_IGNORE := !.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:\#*:*.rej:*.orig
 
+extra_packages := $(subst $(NULL) ,:,$(strip $(extra_packages)))
+
 # 1: target file.
 # 2: dependencies.
 # 3: name of ap_ file to write.
 # 4: directory to write R.java into.
 # 5: directory to write R.txt into.
 # We touch the target file before invoking aapt so that aapt's outputs
 # are fresher than the target, preventing a subsequent invocation from
 # thinking aapt's outputs are stale.  This is safe because Make
 # removes the target file if any recipe command fails.
 define aapt_command
 $(1): $$(call mkdir_deps,$(filter-out ./,$(dir $(3) $(4) $(5)))) $(2)
 	@$$(TOUCH) $$@
-	$$(AAPT) package -f -M AndroidManifest.xml -I $$(ANDROID_SDK)/android.jar \
+	$$(AAPT) package -f -m \
+		-M AndroidManifest.xml \
+		-I $(ANDROID_SDK)/android.jar \
 		--auto-add-overlay \
 		$$(addprefix -S ,$$(ANDROID_RES_DIRS)) \
-		--custom-package org.mozilla.gecko --non-constant-id \
+		$(if $(extra_res_dirs),$$(addprefix -S ,$$(extra_res_dirs)),) \
+		$(if $(extra_packages),--extra-packages $$(extra_packages),) \
+		--custom-package org.mozilla.gecko \
+		--non-constant-id \
 		-F $(3) \
 		-J $(4) \
 		--output-text-symbols $(5) \
 		--ignore-assets "$$(ANDROID_AAPT_IGNORE)"
 endef
 
 # [Comment 3/3] The first of these rules is used during regular
 # builds.  The second writes an ap_ file that is only used during
 # packaging.  It doesn't write the normal ap_, or R.java, since we
 # don't want the packaging step to write anything that would make a
 # further no-op build do work.  See also
 # toolkit/mozapps/installer/packager.mk.
 
 # .aapt.deps: $(all_resources)
-$(eval $(call aapt_command,.aapt.deps,$(all_resources),gecko.ap_,$(gecko_package_dir)/,./))
+$(eval $(call aapt_command,.aapt.deps,$(all_resources),gecko.ap_,generated/,./))
 
 # .aapt.nodeps: $(CURDIR)/AndroidManifest.xml FORCE
 $(eval $(call aapt_command,.aapt.nodeps,$(CURDIR)/AndroidManifest.xml FORCE,gecko-nodeps.ap_,gecko-nodeps/,gecko-nodeps/))
 
-fennec_ids.txt: $(gecko_package_dir)/R.java fennec-ids-generator.py
+fennec_ids.txt: generated/org/mozilla/gecko/R.java fennec-ids-generator.py
 	$(PYTHON) $(topsrcdir)/mobile/android/base/fennec-ids-generator.py -i $< -o $@
 
 # Override the Java settings with some specific android settings
 include $(topsrcdir)/config/android-common.mk
 
 libs:: geckoview_resources.zip classes.dex jni-stubs.inc GeneratedJNIWrappers.cpp fennec_ids.txt
 	$(INSTALL) geckoview_resources.zip $(FINAL_TARGET)
 	$(INSTALL) classes.dex $(FINAL_TARGET)
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -11,16 +11,23 @@ include('android-services.mozbuild')
 
 thirdparty_source_dir = TOPSRCDIR + '/mobile/android/thirdparty/'
 
 resjar = add_java_jar('gecko-R')
 resjar.sources = []
 resjar.generated_sources += [
     'org/mozilla/gecko/R.java',
 ]
+
+if CONFIG['MOZ_NATIVE_DEVICES']:
+    resjar.generated_sources += ['com/google/android/gms/R.java']
+    DEFINES["GOOGLE_PLAY_SERVICES"] = 1
+    resjar.generated_sources += ['android/support/v7/appcompat/R.java']
+    resjar.generated_sources += ['android/support/v7/mediarouter/R.java']
+
 resjar.javac_flags += ['-Xlint:all']
 
 mgjar = add_java_jar('gecko-mozglue')
 mgjar.sources += [
     'mozglue/ByteBufferInputStream.java',
     'mozglue/DirectBufferAllocator.java',
     'mozglue/generatorannotations/GeneratorOptions.java',
     'mozglue/generatorannotations/OptionalGeneratedParameter.java',
@@ -465,16 +472,22 @@ gbjar.generated_sources += sync_generate
 gbjar.extra_jars = [
     'gecko-R.jar',
     'gecko-mozglue.jar',
     'gecko-util.jar',
     'squareup-picasso.jar',
     'sync-thirdparty.jar',
     'websockets.jar',
 ]
+
+if CONFIG['MOZ_NATIVE_DEVICES']:
+    gbjar.extra_jars += [CONFIG['ANDROID_APPCOMPAT_LIB']]
+    gbjar.extra_jars += [CONFIG['ANDROID_MEDIAROUTER_LIB']]
+    gbjar.extra_jars += [CONFIG['GOOGLE_PLAY_SERVICES_LIB']]
+
 gbjar.javac_flags += ['-Xlint:all,-deprecation,-fallthrough']
 
 spjar = add_java_jar('squareup-picasso')
 spjar.sources += [ thirdparty_source_dir + f for f in [
     'com/squareup/picasso/Action.java',
     'com/squareup/picasso/AssetBitmapHunter.java',
     'com/squareup/picasso/BitmapHunter.java',
     'com/squareup/picasso/Cache.java',
--- a/mobile/android/config/proguard.cfg
+++ b/mobile/android/config/proguard.cfg
@@ -189,13 +189,15 @@
 }
 
 -keep @interface org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI
 -keep @org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI class *
 -keepclassmembers @org.mozilla.gecko.mozglue.generatorannotations.WrapEntireClassForJNI class * {
     *;
 }
 
+-keep class **.R$*
+
 # Disable obfuscation because it makes exception stack traces more difficult to read.
 -dontobfuscate
 
 # Suppress warnings about missing descriptor classes.
 #-dontnote **,!ch.boye.**,!org.mozilla.gecko.sync.**
--- a/mobile/android/confvars.sh
+++ b/mobile/android/confvars.sh
@@ -64,8 +64,11 @@ MOZ_SERVICES_FXACCOUNTS=1
 # Enable Wifi-AP/cell tower data reporting
 MOZ_DATA_REPORTING=1
 
 # Enable runtime locale switching.
 MOZ_LOCALE_SWITCHER=1
 
 # Enable second screen and casting support for external devices.
 MOZ_DEVICES=1
+
+# Enable second screen using native Android libraries
+MOZ_NATIVE_DEVICES=