Merge "Support to install prebuilt split APKs with LOCAL_PACKAGE_SPLITS" into lmp-dev
diff --git a/core/definitions.mk b/core/definitions.mk
index e433b69..6656591 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -1805,18 +1805,6 @@
 $(hide) mv $@.aligned $@
 endef
 
-# Build a split APK
-# The splti APKs are already built in the same command building the base APK.
-# We only need to do zipalign and signing etc.
-# This macro must be called with $(eval).
-# $(1): the path to the built split APK.
-# $(2): the path to the base APK.
-define build-split-apk
-$(1) : $(2)
-	$$(sign-package)
-	$$(align-package)
-endef
-
 define install-dex-debug
 $(hide) if [ -f "$(PRIVATE_INTERMEDIATES_DIR)/classes.dex" ]; then \
 	    mkdir -p $(TOP)/dalvik/DEBUG-FILES; \
diff --git a/core/package_internal.mk b/core/package_internal.mk
index a5b1142..3f8bdfe 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -410,19 +410,29 @@
 ###############################
 ## APK splits
 ifdef LOCAL_PACKAGE_SPLITS
+# LOCAL_PACKAGE_SPLITS is a list of resource labels.
 built_apk_splits := $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/package_$(s).apk)
 installed_apk_splits := $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
 
+# The splits should have been built in the same command building the base apk.
+# This rule just runs signing and zipalign etc.
+# Note that we explicily check the existence of the split apk and remove the
+# built base apk if the split apk isn't there.
+# That way the build system will rerun the aapt after the user changes the splitting parameters.
 $(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
 $(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
-# The splits should have been built in the same command building the base apk.
-# This rule just establishes the dependency and make sure the splits are up to date.
-$(foreach s,$(built_apk_splits),\
-  $(eval $(call build-split-apk,$(s),$(LOCAL_BUILT_MODULE))))
+$(built_apk_splits) : $(built_module_path)/%.apk : $(LOCAL_BUILT_MODULE)
+	$(hide) if [ ! -f $@ ]; then \
+	  echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
+	  rm $<; exit 1; \
+	fi
+	$(sign-package)
+	$(align-package)
 
 # Rules to install the splits
-$(foreach s,$(LOCAL_PACKAGE_SPLITS),\
-  $(eval $(call copy-one-file,$(built_module_path)/package_$(s).apk,$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)))
+$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(built_module_path)/package_%.apk | $(ACP)
+	@echo "Install: $@"
+	$(copy-file-to-new-target)
 
 # Register the additional built and installed files.
 ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
diff --git a/core/pathmap.mk b/core/pathmap.mk
index a4a60fa..30b1ab7 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -118,7 +118,7 @@
         v17/leanback
 
 #
-# A list of all source roots under frameworks/support.
+# A list of all source roots under frameworks/multidex.
 #
 FRAMEWORKS_MULTIDEX_SUBDIRS := \
         multidex \
@@ -130,7 +130,7 @@
 #
 FRAMEWORKS_SUPPORT_JAVA_SRC_DIRS := \
 	$(addprefix frameworks/support/,$(FRAMEWORKS_SUPPORT_SUBDIRS)) \
-        $(addprefix frameworks/,$(FRAMEWORKS_MULTIDEX_SUBDIRS))
+        $(addsuffix /src,$(addprefix frameworks/,$(FRAMEWORKS_MULTIDEX_SUBDIRS)))
 
 #
 # A list of support library modules.
diff --git a/target/product/base.mk b/target/product/base.mk
index fa0489b..303818b 100644
--- a/target/product/base.mk
+++ b/target/product/base.mk
@@ -18,6 +18,7 @@
 PRODUCT_PACKAGES += \
     20-dns.conf \
     95-configured \
+    appwidget \
     am \
     android.policy \
     android.test.runner \