Bug 919563 - Standardize APK generation. r=glandium
authorNick Alexander <nalexander@mozilla.com>
Tue, 01 Oct 2013 12:43:30 -0700
changeset 149510 a1e6919bff63e2582bc3325c1fcbcef1c70bf1d3
parent 149474 d8d4ebf6c7567c822ad402e3ad4037183e3e3df0
child 149511 083bbfebdf8567c895d93f1d5ce8817d618c495b
push id25392
push userkwierso@gmail.com
push dateWed, 02 Oct 2013 01:28:41 +0000
treeherderautoland@4fe6e345e0b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs919563
milestone27.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 919563 - Standardize APK generation. r=glandium This only handles the simple cases: no mobile/android/base (yet).
build/mobile/robocop/Makefile.in
build/mobile/sutagent/android/Makefile.in
build/mobile/sutagent/android/R.java
build/mobile/sutagent/android/fencp/Makefile.in
build/mobile/sutagent/android/fencp/R.java
build/mobile/sutagent/android/ffxcp/Makefile.in
build/mobile/sutagent/android/ffxcp/R.java
build/mobile/sutagent/android/watcher/Makefile.in
build/mobile/sutagent/android/watcher/R.java
config/makefiles/java-build.mk
js/src/config/makefiles/java-build.mk
--- a/build/mobile/robocop/Makefile.in
+++ b/build/mobile/robocop/Makefile.in
@@ -3,27 +3,27 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 mobile-tests := mobile/android/base/tests
 TESTPATH     := $(topsrcdir)/$(mobile-tests)
 dir-tests    := $(DEPTH)/$(mobile-tests)
 
 ANDROID_APK_NAME := robocop-debug
 
-ROBOTIUM_PATH = $(srcdir)/robotium-solo-4.2.jar
-
-JAVAFILES = \
-  R.java \
+ANDROID_EXTRA_JARS += \
+  $(srcdir)/robotium-solo-4.2.jar \
   $(NULL)
 
 ANDROID_RESFILES = \
   res/values/strings.xml \
   $(NULL)
 
-_JAVA_HARNESS = \
+ANDROID_ASSETS_DIR := $(TESTPATH)/assets
+
+_JAVA_HARNESS := \
   Actions.java \
   Assert.java \
   Driver.java \
   Element.java \
   FennecInstrumentationTestRunner.java \
   FennecNativeActions.java \
   FennecMochitestAssert.java \
   FennecTalosAssert.java \
@@ -46,17 +46,16 @@ java-tests-src  := $(wildcard $(TESTPATH
 java-tests-dep  := $(patsubst $(TESTPATH)/%.java.in,$(dir-tests)/%.java,$(java-tests-src))
 java-tests      := $(java-tests-src)
 java-tests_PATH := $(dir-tests)
 
 PP_TARGETS        += manifest
 manifest          := $(srcdir)/AndroidManifest.xml.in
 manifest_TARGET   := AndroidManifest.xml
 
-
 # Install robocop configs and helper
 INSTALL_TARGETS += robocop
 robocop_TARGET  := libs
 robocop_DEST    := $(CURDIR)
 robocop_FILES   := \
   $(TESTPATH)/robocop.ini \
   $(TESTPATH)/robocop_autophone.ini \
   $(TESTPATH)/robocop_x86.ini \
@@ -70,57 +69,32 @@ MOCHITEST_ROBOCOP_FILES := \
   $(wildcard $(TESTPATH)/test*.js) \
   $(wildcard $(TESTPATH)/robocop*.js) \
   $(wildcard $(TESTPATH)/*.xml) \
   $(NULL)
 
 GARBAGE += \
   AndroidManifest.xml \
   $(java-tests-dep) \
-  $(_JAVA_HARNESS) \
-  classes.dex \
-  $(ANDROID_APK_NAME).ap_ \
-  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
-  $(ANDROID_APK_NAME)-unaligned.apk \
-  $(ANDROID_APK_NAME).apk \
+  $(java-harness-dep) \
   $(robocop-deps) \
   $(NULL)
 
+JAVAFILES += \
+  $(robocop-deps) \
+  $(java-harness-dep) \
+  $(java-tests-dep) \
+  $(NULL)
+
 DEFINES += \
   -DANDROID_PACKAGE_NAME=$(ANDROID_PACKAGE_NAME) \
   $(NULL)
 
-JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar:$(ROBOTIUM_PATH)
-
 include $(topsrcdir)/config/rules.mk
 
-# Override rules.mk java flags with the android specific ones
-include $(topsrcdir)/config/android-common.mk
-
-GENERATED_DIRS_tools = classes $(dir-tests)
-
 tools:: $(ANDROID_APK_NAME).apk
 
-classes.dex: $(ANDROID_APK_NAME).ap_
-classes.dex: $(robocop-deps)
-classes.dex: $(java-harness-dep)
-classes.dex: $(java-tests-dep)
-	$(JAVAC) $(JAVAC_FLAGS) -d classes $(JAVAFILES) $(_JAVA_HARNESS) $(java-tests-dep)
-	$(DX) --dex --output=$@ classes $(ROBOTIUM_PATH) $(ANDROID_COMPT_LIB)
-
-$(ANDROID_APK_NAME).ap_: AndroidManifest.xml $(TESTPATH)/assets/*
-	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar -I . -S res -A $(TESTPATH)/assets -F $@ -J ./
-
-$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
-	cp $< $@
-	$(ZIP) -0 $@ classes.dex
-
-$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
-	cp $< $@
-	$(DEBUG_JARSIGNER) $@
-
-$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
-	$(ZIPALIGN) -f -v 4 $< $@
+GENERATED_DIRS += $(dir-tests)
 
 # PP_java-tests not fully usable here
 # Intermediate step toward a library rule.
 $(dir-tests)/%.java: $(TESTPATH)/%.java.in $(call mkdir_deps,$(dir-tests))
 	$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) $< > $@
--- a/build/mobile/sutagent/android/Makefile.in
+++ b/build/mobile/sutagent/android/Makefile.in
@@ -13,60 +13,28 @@ JAVAFILES = \
   DoCommand.java \
   FindProcThread.java \
   Power.java \
   RedirOutputThread.java \
   RunCmdThread.java \
   RunDataThread.java \
   SUTAgentAndroid.java \
   WifiConfiguration.java \
-  R.java \
   $(NULL)
 
 ANDROID_RESFILES = \
   res/drawable/icon.png \
   res/drawable/ateamlogo.png \
   res/drawable/ic_stat_first.png \
   res/drawable/ic_stat_neterror.png \
   res/drawable/ic_stat_warning.png \
   res/layout/main.xml \
   res/values/strings.xml \
   $(NULL)
 
-GARBAGE += \
-  AndroidManifest.xml  \
-  classes.dex  \
-  $(ANDROID_APK_NAME).ap_ \
-  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
-  $(ANDROID_APK_NAME)-unaligned.apk \
-  $(ANDROID_APK_NAME).apk \
+ANDROID_EXTRA_JARS = \
+  $(srcdir)/network-libs/commons-net-2.0.jar \
+  $(srcdir)/network-libs/jmdns.jar \
   $(NULL)
 
-GARBAGE_DIRS += network-libs
-
-EXTRA_JARS = $(srcdir)/network-libs/commons-net-2.0.jar:$(srcdir)/network-libs/jmdns.jar
-
-JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar:$(EXTRA_JARS)
-
 include $(topsrcdir)/config/rules.mk
 
-# include Android specific java flags - using these instead of what's in rules.mk
-include $(topsrcdir)/config/android-common.mk
-
 tools:: $(ANDROID_APK_NAME).apk
-
-classes.dex: $(JAVAFILES)
-	$(JAVAC) $(JAVAC_FLAGS) -d classes  $(addprefix $(srcdir)/,$(JAVAFILES))
-	$(DX) --dex --output=$@ classes $(subst :, ,$(EXTRA_JARS))
-
-$(ANDROID_APK_NAME).ap_: AndroidManifest.xml
-	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar -S res -F $@
-
-$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
-	cp $< $@
-	$(ZIP) -0 $@ classes.dex
-
-$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
-	cp $< $@
-	$(DEBUG_JARSIGNER) $@
-
-$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
-	$(ZIPALIGN) -f -v 4 $< $@
deleted file mode 100755
--- a/build/mobile/sutagent/android/R.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* 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/. */
-
-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package com.mozilla.SUTAgentAndroid;
-
-public final class R {
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int ateamlogo=0x7f020000;
-        public static final int ic_stat_first=0x7f020001;
-        public static final int ic_stat_neterror=0x7f020002;
-        public static final int ic_stat_second=0x7f020003;
-        public static final int ic_stat_warning=0x7f020004;
-        public static final int icon=0x7f020005;
-    }
-    public static final class id {
-        public static final int Button01=0x7f050001;
-        public static final int Textview01=0x7f050000;
-    }
-    public static final class layout {
-        public static final int main=0x7f030000;
-    }
-    public static final class string {
-        public static final int app_name=0x7f040001;
-        public static final int foreground_service_started=0x7f040002;
-        public static final int hello=0x7f040000;
-    }
-}
--- a/build/mobile/sutagent/android/fencp/Makefile.in
+++ b/build/mobile/sutagent/android/fencp/Makefile.in
@@ -4,56 +4,21 @@
 
 ANDROID_APK_NAME := FenCP
 
 JAVAFILES = \
   DirCursor.java \
   FenCP.java \
   FenCPFP.java \
   FileCursor.java \
-  R.java \
   $(NULL)
 
 ANDROID_RESFILES = \
   res/drawable-hdpi/icon.png \
   res/drawable-ldpi/icon.png \
   res/drawable-mdpi/icon.png \
   res/layout/main.xml \
   res/values/strings.xml \
   $(NULL)
 
-GARBAGE += \
-  AndroidManifest.xml  \
-  classes.dex  \
-  $(ANDROID_APK_NAME).ap_ \
-  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
-  $(ANDROID_APK_NAME)-unaligned.apk \
-  $(ANDROID_APK_NAME).apk \
-  $(NULL)
-
-GARBAGE_DIRS += network-libs
-
-JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
-
 include $(topsrcdir)/config/rules.mk
 
-# include Android specific java flags - using these instead of what's in rules.mk
-include $(topsrcdir)/config/android-common.mk
-
 tools:: $(ANDROID_APK_NAME).apk
-
-classes.dex: $(JAVAFILES)
-	$(JAVAC) $(JAVAC_FLAGS) -d classes  $(addprefix $(srcdir)/,$(JAVAFILES))
-	$(DX) --dex --output=$@ classes
-
-$(ANDROID_APK_NAME).ap_: AndroidManifest.xml
-	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar -S res -F $@
-
-$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
-	cp $< $@
-	$(ZIP) -0 $@ classes.dex
-
-$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
-	cp $< $@
-	$(DEBUG_JARSIGNER) $@
-
-$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
-	$(ZIPALIGN) -f -v 4 $< $@
deleted file mode 100644
--- a/build/mobile/sutagent/android/fencp/R.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/* 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/. */
-
-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package org.mozilla.fencp;
-
-public final class R {
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int icon=0x7f020000;
-    }
-    public static final class layout {
-        public static final int main=0x7f030000;
-    }
-    public static final class string {
-        public static final int app_name=0x7f040001;
-        public static final int hello=0x7f040000;
-    }
-}
--- a/build/mobile/sutagent/android/ffxcp/Makefile.in
+++ b/build/mobile/sutagent/android/ffxcp/Makefile.in
@@ -4,56 +4,21 @@
 
 ANDROID_APK_NAME := FfxCP
 
 JAVAFILES = \
   DirCursor.java \
   ffxcp.java \
   FfxCPFP.java \
   FileCursor.java \
-  R.java \
   $(NULL)
 
 ANDROID_RESFILES = \
   res/drawable-hdpi/icon.png \
   res/drawable-ldpi/icon.png \
   res/drawable-mdpi/icon.png \
   res/layout/main.xml \
   res/values/strings.xml \
   $(NULL)
 
-GARBAGE += \
-  AndroidManifest.xml  \
-  classes.dex  \
-  $(ANDROID_APK_NAME).ap_ \
-  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
-  $(ANDROID_APK_NAME)-unaligned.apk \
-  $(ANDROID_APK_NAME).apk \
-  $(NULL)
-
-GARBAGE_DIRS += network-libs
-
-JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
-
 include $(topsrcdir)/config/rules.mk
 
-# include Android specific java flags - using these instead of what's in rules.mk
-include $(topsrcdir)/config/android-common.mk
-
 tools:: $(ANDROID_APK_NAME).apk
-
-classes.dex: $(JAVAFILES)
-	$(JAVAC) $(JAVAC_FLAGS) -d classes  $(addprefix $(srcdir)/,$(JAVAFILES))
-	$(DX) --dex --output=$@ classes
-
-$(ANDROID_APK_NAME).ap_: AndroidManifest.xml
-	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar -S res -F $@
-
-$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
-	cp $< $@
-	$(ZIP) -0 $@ classes.dex
-
-$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
-	cp $< $@
-	$(DEBUG_JARSIGNER) $@
-
-$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
-	$(ZIPALIGN) -f -v 4 $< $@
deleted file mode 100644
--- a/build/mobile/sutagent/android/ffxcp/R.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/* 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/. */
-
-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package org.mozilla.ffxcp;
-
-public final class R {
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int icon=0x7f020000;
-    }
-    public static final class layout {
-        public static final int main=0x7f030000;
-    }
-    public static final class string {
-        public static final int app_name=0x7f040001;
-        public static final int hello=0x7f040000;
-    }
-}
--- a/build/mobile/sutagent/android/watcher/Makefile.in
+++ b/build/mobile/sutagent/android/watcher/Makefile.in
@@ -2,63 +2,27 @@
 # 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/.
 
 ANDROID_APK_NAME := Watcher
 
 JAVAFILES = \
   IWatcherService.java \
   RedirOutputThread.java \
-  R.java \
   WatcherMain.java \
   WatcherReceiver.java \
   WatcherService.java \
   $(NULL)
 
 ANDROID_RESFILES = \
   res/drawable-hdpi/icon.png \
   res/drawable-hdpi/ateamlogo.png \
   res/drawable-ldpi/icon.png \
   res/drawable-ldpi/ateamlogo.png \
   res/drawable-mdpi/icon.png \
   res/drawable-mdpi/ateamlogo.png \
   res/layout/main.xml \
   res/values/strings.xml \
   $(NULL)
 
-GARBAGE += \
-  AndroidManifest.xml  \
-  classes.dex  \
-  $(ANDROID_APK_NAME).ap_ \
-  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
-  $(ANDROID_APK_NAME)-unaligned.apk \
-  $(ANDROID_APK_NAME).apk \
-  $(NULL)
-
-GARBAGE_DIRS += res classes network-libs
-
-JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
-
 include $(topsrcdir)/config/rules.mk
 
-# include Android specific java flags - using these instead of what's in rules.mk
-include $(topsrcdir)/config/android-common.mk
-
 tools:: $(ANDROID_APK_NAME).apk
-
-classes.dex: $(JAVAFILES)
-	$(NSINSTALL) -D classes
-	$(JAVAC) $(JAVAC_FLAGS) -d classes  $(addprefix $(srcdir)/,$(JAVAFILES))
-	$(DX) --dex --output=$@ classes
-
-$(ANDROID_APK_NAME).ap_: AndroidManifest.xml
-	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar -S res -F $@
-
-$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
-	cp $< $@
-	$(ZIP) -0 $@ classes.dex
-
-$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
-	cp $< $@
-	$(DEBUG_JARSIGNER) $@
-
-$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
-	$(ZIPALIGN) -f -v 4 $< $@
deleted file mode 100644
--- a/build/mobile/sutagent/android/watcher/R.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 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/. */
-
-/* AUTO-GENERATED FILE.  DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found.  It
- * should not be modified by hand.
- */
-
-package com.mozilla.watcher;
-
-public final class R {
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int ateamlogo=0x7f020000;
-        public static final int icon=0x7f020001;
-    }
-    public static final class layout {
-        public static final int main=0x7f030000;
-    }
-    public static final class string {
-        public static final int app_name=0x7f040001;
-        public static final int foreground_service_started=0x7f040002;
-        public static final int hello=0x7f040000;
-    }
-}
--- a/config/makefiles/java-build.mk
+++ b/config/makefiles/java-build.mk
@@ -20,21 +20,76 @@ res-dep-preqs := \
   $(call mkdir_deps,res) \
   $(if $(IS_LANGUAGE_REPACK),FORCE) \
   $(NULL)
 
 # nop-build: only copy res/ files when needed
 $(res-dep): $(res-dep-preqs)
 	$(call copy_dir,$(srcdir)/res,$(CURDIR)/res)
 	@$(TOUCH) $@
-endif #}
+endif #} ANDROID_RESFILES
 
 
 ifdef JAVAFILES #{
 GENERATED_DIRS += classes
 
 export:: classes
 classes: $(call mkdir_deps,classes)
-endif #}
+endif #} JAVAFILES
+
+
+ifdef ANDROID_APK_NAME #{
+_ANDROID_RES_FLAG := -S $(or $(ANDROID_RES_DIR),res)
+_ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR))
+
+GENERATED_DIRS += classes
+
+classes.dex: $(call mkdir_deps,classes)
+classes.dex: R.java
+classes.dex: $(ANDROID_APK_NAME).ap_
+classes.dex: $(JAVAFILES)
+	$(JAVAC) $(JAVAC_FLAGS) -d classes $(filter %.java,$^)
+	$(DX) --dex --output=$@ classes $(ANDROID_EXTRA_JARS)
+
+# R.java and $(ANDROID_APK_NAME).ap_ are both produced by aapt.  To
+# save an aapt invocation, we produce them both at the same time.
+
+R.java: .aapt.deps
+$(ANDROID_APK_NAME).ap_: .aapt.deps
+
+.aapt.deps: AndroidManifest.xml $(wildcard $(ANDROID_RES_DIR)) $(wildcard $(ANDROID_ASSETS_DIR))
+	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \
+		-J ${@D} \
+		-F $(ANDROID_APK_NAME).ap_
+	@$(TOUCH) $@
+
+$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
+	cp $< $@
+	$(ZIP) -0 $@ classes.dex
+
+$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
+	cp $< $@
+	$(DEBUG_JARSIGNER) $@
+
+$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
+	$(ZIPALIGN) -f -v 4 $< $@
+
+GARBAGE += \
+  R.java \
+  classes.dex  \
+  $(ANDROID_APK_NAME).ap_ \
+  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
+  $(ANDROID_APK_NAME)-unaligned.apk \
+  $(ANDROID_APK_NAME).apk \
+  $(NULL)
+
+JAVA_CLASSPATH := $(ANDROID_SDK)/android.jar
+ifdef ANDROID_EXTRA_JARS #{
+JAVA_CLASSPATH := $(JAVA_CLASSPATH):$(subst $(NULL) ,:,$(strip $(ANDROID_EXTRA_JARS)))
+endif #} ANDROID_EXTRA_JARS
+
+# Include Android specific java flags, instead of what's in rules.mk.
+include $(topsrcdir)/config/android-common.mk
+endif #} ANDROID_APK_NAME
 
 INCLUDED_JAVA_BUILD_MK := 1
 
 endif #} INCLUDED_JAVA_BUILD_MK
--- a/js/src/config/makefiles/java-build.mk
+++ b/js/src/config/makefiles/java-build.mk
@@ -20,21 +20,76 @@ res-dep-preqs := \
   $(call mkdir_deps,res) \
   $(if $(IS_LANGUAGE_REPACK),FORCE) \
   $(NULL)
 
 # nop-build: only copy res/ files when needed
 $(res-dep): $(res-dep-preqs)
 	$(call copy_dir,$(srcdir)/res,$(CURDIR)/res)
 	@$(TOUCH) $@
-endif #}
+endif #} ANDROID_RESFILES
 
 
 ifdef JAVAFILES #{
 GENERATED_DIRS += classes
 
 export:: classes
 classes: $(call mkdir_deps,classes)
-endif #}
+endif #} JAVAFILES
+
+
+ifdef ANDROID_APK_NAME #{
+_ANDROID_RES_FLAG := -S $(or $(ANDROID_RES_DIR),res)
+_ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR))
+
+GENERATED_DIRS += classes
+
+classes.dex: $(call mkdir_deps,classes)
+classes.dex: R.java
+classes.dex: $(ANDROID_APK_NAME).ap_
+classes.dex: $(JAVAFILES)
+	$(JAVAC) $(JAVAC_FLAGS) -d classes $(filter %.java,$^)
+	$(DX) --dex --output=$@ classes $(ANDROID_EXTRA_JARS)
+
+# R.java and $(ANDROID_APK_NAME).ap_ are both produced by aapt.  To
+# save an aapt invocation, we produce them both at the same time.
+
+R.java: .aapt.deps
+$(ANDROID_APK_NAME).ap_: .aapt.deps
+
+.aapt.deps: AndroidManifest.xml $(wildcard $(ANDROID_RES_DIR)) $(wildcard $(ANDROID_ASSETS_DIR))
+	$(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \
+		-J ${@D} \
+		-F $(ANDROID_APK_NAME).ap_
+	@$(TOUCH) $@
+
+$(ANDROID_APK_NAME)-unsigned-unaligned.apk: $(ANDROID_APK_NAME).ap_ classes.dex
+	cp $< $@
+	$(ZIP) -0 $@ classes.dex
+
+$(ANDROID_APK_NAME)-unaligned.apk: $(ANDROID_APK_NAME)-unsigned-unaligned.apk
+	cp $< $@
+	$(DEBUG_JARSIGNER) $@
+
+$(ANDROID_APK_NAME).apk: $(ANDROID_APK_NAME)-unaligned.apk
+	$(ZIPALIGN) -f -v 4 $< $@
+
+GARBAGE += \
+  R.java \
+  classes.dex  \
+  $(ANDROID_APK_NAME).ap_ \
+  $(ANDROID_APK_NAME)-unsigned-unaligned.apk \
+  $(ANDROID_APK_NAME)-unaligned.apk \
+  $(ANDROID_APK_NAME).apk \
+  $(NULL)
+
+JAVA_CLASSPATH := $(ANDROID_SDK)/android.jar
+ifdef ANDROID_EXTRA_JARS #{
+JAVA_CLASSPATH := $(JAVA_CLASSPATH):$(subst $(NULL) ,:,$(strip $(ANDROID_EXTRA_JARS)))
+endif #} ANDROID_EXTRA_JARS
+
+# Include Android specific java flags, instead of what's in rules.mk.
+include $(topsrcdir)/config/android-common.mk
+endif #} ANDROID_APK_NAME
 
 INCLUDED_JAVA_BUILD_MK := 1
 
 endif #} INCLUDED_JAVA_BUILD_MK