Rebuild odex files in PDK fusion build.

To rebuild odex files of Java libraries and apps,
we store the jars/apks without stripping the classes.dex inside the
platform.zip. We also save the build variables that may affect how we
rebuild an odex in pdk_dexpreopt_config.mk in the platform.zip.
We store the files and configuration only for libraries/apps that get
installed to the system.img (or vendor.img).

In PDK fusion build, we auto-generate prebuilt module definitions for
the javalib.jar and package.dex.apk carried in the platform.zip, using
configuration stored in pdk_dexpreopt_config.mk.
With the prebult modules, we override the implicit rule that directly
copies the odex from the platform.zip.
To rebuild odex of javalib.jar, we added support for prebuilt shared Java
library to prebiult_internal.mk. An installable prebuilt Java library is
treated as shared Java library, i.e. with classes.dex in the jar instead
of a set of .class files.
For apks in the platform.zip, we install the stripped version from
platform files inside platform.zip, instead of the package.dex.apk,
using a new variable LOCAL_REPLACE_PREBUILT_APK_INSTALLED. We can't
strip package.dex.apk because we can't re-sign the stripped apk at this
point.

We generate prebuilt module only if it's not already defined in the
source tree.

Bug: 27543283
Change-Id: I9e146f8b713d6f57c397fd28d88c9ab700757ca1
(cherry-pick from commit 3a61eeb6cb)
This commit is contained in:
Ying Wang 2016-03-11 10:32:01 -08:00
parent 6557ba5335
commit fbc5b9f56b
12 changed files with 256 additions and 32 deletions

View File

@ -1237,16 +1237,53 @@ systemtarball-nodeps: $(FS_GET_STATS) \
.PHONY: stnod .PHONY: stnod
stnod: systemtarball-nodeps stnod: systemtarball-nodeps
####### # -----------------------------------------------------------------
## platform.zip: system, plus other files to be used in PDK fusion build, ## platform.zip: system, plus other files to be used in PDK fusion build,
## in a zip file ## in a zip file
## ##
## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip. ## PDK_PLATFORM_ZIP_PRODUCT_BINARIES is used to store specified files to platform.zip.
## The variable will be typically set from BoardConfig.mk. ## The variable will be typically set from BoardConfig.mk.
## Files under out dir will be rejected to prevent possible conflicts with other rules. ## Files under out dir will be rejected to prevent possible conflicts with other rules.
pdk_odex_javalibs := $(strip $(foreach m,$(DEXPREOPT.MODULES.JAVA_LIBRARIES),\
$(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
pdk_odex_apps := $(strip $(foreach m,$(DEXPREOPT.MODULES.APPS),\
$(if $(filter $(DEXPREOPT.$(m).INSTALLED),$(ALL_DEFAULT_INSTALLED_MODULES)),$(m))))
pdk_classes_dex := $(strip \
$(foreach m,$(pdk_odex_javalibs),$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar) \
$(foreach m,$(pdk_odex_apps),$(call intermediates-dir-for,APPS,$(m))/package.dex.apk))
pdk_odex_config_mk := $(PRODUCT_OUT)/pdk_dexpreopt_config.mk
$(pdk_odex_config_mk): PRIVATE_JAVA_LIBRARIES := $(pdk_odex_javalibs)
$(pdk_odex_config_mk): PRIVATE_APPS := $(pdk_odex_apps)
$(pdk_odex_config_mk) :
@echo "PDK odex config makefile: $@"
$(hide) mkdir -p $(dir $@)
$(hide) echo "# Auto-generated. Do not modify." > $@
$(hide) echo "PDK.DEXPREOPT.JAVA_LIBRARIES:=$(PRIVATE_JAVA_LIBRARIES)" >> $@
$(hide) echo "PDK.DEXPREOPT.APPS:=$(PRIVATE_APPS)" >> $@
$(foreach m,$(PRIVATE_JAVA_LIBRARIES),\
$(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,JAVA_LIBRARIES,$(m),,COMMON)/javalib.jar)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
)
$(foreach m,$(PRIVATE_APPS),\
$(hide) echo "PDK.DEXPREOPT.$(m).SRC:=$(patsubst $(OUT_DIR)/%,%,$(call intermediates-dir-for,APPS,$(m))/package.dex.apk)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT:=$(DEXPREOPT.$(m).DEX_PREOPT)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).MULTILIB:=$(DEXPREOPT.$(m).MULTILIB)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).DEX_PREOPT_FLAGS:=$(DEXPREOPT.$(m).DEX_PREOPT_FLAGS)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).PRIVILEGED_MODULE:=$(DEXPREOPT.$(m).PRIVILEGED_MODULE)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).PROPRIETARY_MODULE:=$(DEXPREOPT.$(m).PROPRIETARY_MODULE)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).TARGET_ARCH:=$(DEXPREOPT.$(m).TARGET_ARCH)" >> $@$(newline)\
$(hide) echo "PDK.DEXPREOPT.$(m).STRIPPED_SRC:=$(patsubst $(PRODUCT_OUT)/%,%,$(DEXPREOPT.$(m).INSTALLED_STRIPPED))" >> $@$(newline)\
)
PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)) PDK_PLATFORM_ZIP_PRODUCT_BINARIES := $(filter-out $(OUT_DIR)/%,$(PDK_PLATFORM_ZIP_PRODUCT_BINARIES))
INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip INSTALLED_PLATFORM_ZIP := $(PRODUCT_OUT)/platform.zip
$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES)
$(INSTALLED_PLATFORM_ZIP): PRIVATE_DEX_FILES := $(pdk_classes_dex)
$(INSTALLED_PLATFORM_ZIP): PRIVATE_ODEX_CONFIG := $(pdk_odex_config_mk)
$(INSTALLED_PLATFORM_ZIP) : $(INTERNAL_SYSTEMIMAGE_FILES) $(pdk_odex_config_mk)
$(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)") $(call pretty,"Platform zip package: $(INSTALLED_PLATFORM_ZIP)")
$(hide) rm -f $@ $(hide) rm -f $@
$(hide) cd $(dir $@) && zip -qryX $(notdir $@) \ $(hide) cd $(dir $@) && zip -qryX $(notdir $@) \
@ -1263,6 +1300,9 @@ endif
ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),) ifneq ($(PDK_PLATFORM_ZIP_PRODUCT_BINARIES),)
$(hide) zip -qryX $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES) $(hide) zip -qryX $@ $(PDK_PLATFORM_ZIP_PRODUCT_BINARIES)
endif endif
@# Add dex-preopt files and config.
$(if $(PRIVATE_DEX_FILES),$(hide) cd $(OUT_DIR) && zip -qryX $(patsubst $(OUT_DIR)/%,%,$@ $(PRIVATE_DEX_FILES)))
$(hide) zip -qryXj $@ $(PRIVATE_ODEX_CONFIG)
.PHONY: platform .PHONY: platform
platform: $(INSTALLED_PLATFORM_ZIP) platform: $(INSTALLED_PLATFORM_ZIP)
@ -1275,7 +1315,7 @@ ifneq (,$(filter platform platform-java, $(MAKECMDGOALS)))
$(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP)) $(call dist-for-goals, platform platform-java, $(INSTALLED_PLATFORM_ZIP))
endif endif
####### # -----------------------------------------------------------------
## boot tarball ## boot tarball
define build-boottarball-target define build-boottarball-target
$(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)" $(hide) echo "Target boot fs tarball: $(INSTALLED_BOOTTARBALL_TARGET)"

View File

@ -187,6 +187,9 @@ LOCAL_DBUS_PROXY_PREFIX:=
LOCAL_INIT_RC:= LOCAL_INIT_RC:=
LOCAL_MODULE_HOST_OS:= LOCAL_MODULE_HOST_OS:=
LOCAL_NOTICE_FILE:= LOCAL_NOTICE_FILE:=
# Used to replace the installed file of a presigned prebuilt apk in PDK fusion build,
# to avoid installing the presigned apks with classes.dex unstripped.
LOCAL_REPLACE_PREBUILT_APK_INSTALLED:=
# arch specific variables # arch specific variables
LOCAL_SRC_FILES_$(TARGET_ARCH):= LOCAL_SRC_FILES_$(TARGET_ARCH):=

View File

@ -439,6 +439,8 @@ ifeq (,$(wildcard $(PDK_FUSION_PLATFORM_ZIP)))
endif endif
endif endif
BUILD_PLATFORM_ZIP := $(filter platform platform-java,$(MAKECMDGOALS))
# #
# Tools that are prebuilts for TARGET_BUILD_APPS # Tools that are prebuilts for TARGET_BUILD_APPS
# #

View File

@ -2283,7 +2283,12 @@ endef
#TODO: update the manifest to point to the dex file #TODO: update the manifest to point to the dex file
define add-dex-to-package define add-dex-to-package
$(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $@ $(call add-dex-to-package-arg,$@)
endef
# $(1): the package file.
define add-dex-to-package-arg
$(hide) find $(dir $(PRIVATE_DEX_FILE)) -maxdepth 1 -name "classes*.dex" | sort | xargs zip -qjX $(1)
endef endef
# Add java resources added by the current module. # Add java resources added by the current module.
@ -2322,12 +2327,17 @@ endef
# Sign a package using the specified key/cert. # Sign a package using the specified key/cert.
# #
define sign-package define sign-package
$(hide) mv $@ $@.unsigned $(call sign-package-arg,$@)
endef
# $(1): the package file we are signing.
define sign-package-arg
$(hide) mv $(1) $(1).unsigned
$(hide) java -Djava.library.path=$(SIGNAPK_JNI_LIBRARY_PATH) -jar $(SIGNAPK_JAR) \ $(hide) java -Djava.library.path=$(SIGNAPK_JNI_LIBRARY_PATH) -jar $(SIGNAPK_JAR) \
--min-sdk-version $(call get-package-min-sdk-version-int,$@.unsigned) \ --min-sdk-version $(call get-package-min-sdk-version-int,$@.unsigned) \
$(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \ $(PRIVATE_CERTIFICATE) $(PRIVATE_PRIVATE_KEY) \
$(PRIVATE_ADDITIONAL_CERTIFICATES) $@.unsigned $@.signed $(PRIVATE_ADDITIONAL_CERTIFICATES) $(1).unsigned $(1).signed
$(hide) mv $@.signed $@ $(hide) mv $(1).signed $(1)
endef endef
# Align STORED entries of a package on 4-byte boundaries to make them easier to mmap. # Align STORED entries of a package on 4-byte boundaries to make them easier to mmap.

View File

@ -19,6 +19,24 @@ DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREO
# The default value for LOCAL_DEX_PREOPT # The default value for LOCAL_DEX_PREOPT
DEX_PREOPT_DEFAULT ?= true DEX_PREOPT_DEFAULT ?= true
# The default values for pre-opting: always preopt PIC.
# Conditional to building on linux, as dex2oat currently does not work on darwin.
ifeq ($(HOST_OS),linux)
WITH_DEXPREOPT_PIC ?= true
WITH_DEXPREOPT ?= true
# For an eng build only pre-opt the boot image. This gives reasonable performance and still
# allows a simple workflow: building in frameworks/base and syncing.
ifeq (eng,$(TARGET_BUILD_VARIANT))
WITH_DEXPREOPT_BOOT_IMG_ONLY ?= true
endif
endif
GLOBAL_DEXPREOPT_FLAGS :=
ifeq ($(WITH_DEXPREOPT_PIC),true)
# Compile boot.oat as position-independent code if WITH_DEXPREOPT_PIC=true
GLOBAL_DEXPREOPT_FLAGS += --compile-pic
endif
# $(1): the .jar or .apk to remove classes.dex # $(1): the .jar or .apk to remove classes.dex
define dexpreopt-remove-classes.dex define dexpreopt-remove-classes.dex
$(hide) zip --quiet --delete $(1) classes.dex; \ $(hide) zip --quiet --delete $(1) classes.dex; \

View File

@ -98,5 +98,6 @@ $(hide) ANDROID_LOG_TAGS="*:e" $(DEX2OAT) \
--include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info \ --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info \
--abort-on-hard-verifier-error \ --abort-on-hard-verifier-error \
--no-inline-from=core-oj.jar \ --no-inline-from=core-oj.jar \
$(PRIVATE_DEX_PREOPT_FLAGS) $(PRIVATE_DEX_PREOPT_FLAGS) \
$(GLOBAL_DEXPREOPT_FLAGS)
endef endef

View File

@ -29,11 +29,6 @@ $(my_2nd_arch_prefix)LIBART_TARGET_BOOT_OAT_UNSTRIPPED := $(TARGET_OUT_UNSTRIPPE
$(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE := $(PRODUCT_OUT)$($(my_2nd_arch_prefix)LIBART_BOOT_IMAGE_FILENAME) $(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE := $(PRODUCT_OUT)$($(my_2nd_arch_prefix)LIBART_BOOT_IMAGE_FILENAME)
# Compile boot.oat as position-independent code if WITH_DEXPREOPT_PIC=true
ifeq (true,$(WITH_DEXPREOPT_PIC))
PRODUCT_DEX_PREOPT_BOOT_FLAGS += --compile-pic
endif
# If we have a compiled-classes file, create a parameter. # If we have a compiled-classes file, create a parameter.
COMPILED_CLASSES_FLAGS := COMPILED_CLASSES_FLAGS :=
ifneq ($(COMPILED_CLASSES),) ifneq ($(COMPILED_CLASSES),)
@ -67,4 +62,4 @@ $($(my_2nd_arch_prefix)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) : $(LIBART_TARGE
--instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \ --instruction-set-features=$($(PRIVATE_2ND_ARCH_VAR_PREFIX)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \
--android-root=$(PRODUCT_OUT)/system --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info \ --android-root=$(PRODUCT_OUT)/system --include-patch-information --runtime-arg -Xnorelocate --no-generate-debug-info \
--multi-image --no-inline-from=core-oj.jar \ --multi-image --no-inline-from=core-oj.jar \
$(PRODUCT_DEX_PREOPT_BOOT_FLAGS) $(COMPILED_CLASSES_FLAGS) $(PRODUCT_DEX_PREOPT_BOOT_FLAGS) $(GLOBAL_DEXPREOPT_FLAGS) $(COMPILED_CLASSES_FLAGS)

View File

@ -88,6 +88,9 @@ endif # TARGET_2ND_ARCH
endif # LOCAL_MODULE_CLASS endif # LOCAL_MODULE_CLASS
endif # boot jar endif # boot jar
built_odex := $(strip $(built_odex))
installed_odex := $(strip $(installed_odex))
ifdef built_odex ifdef built_odex
ifndef LOCAL_DEX_PREOPT_FLAGS ifndef LOCAL_DEX_PREOPT_FLAGS
LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG) LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG)
@ -96,11 +99,6 @@ LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS)
endif endif
endif endif
# Compile apps with position-independent code if WITH_DEXPREOPT_PIC=true
ifeq (true,$(WITH_DEXPREOPT_PIC))
LOCAL_DEX_PREOPT_FLAGS += --compile-pic
endif
$(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) $(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
# Use pattern rule - we may have multiple installed odex files. # Use pattern rule - we may have multiple installed odex files.
@ -115,6 +113,19 @@ endif
ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex) ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex)
ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex) ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex)
# Record dex-preopt config.
DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT)
DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB)
DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS)
DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE)
DEXPREOPT.$(LOCAL_MODULE).PROPRIETARY_MODULE := $(LOCAL_PROPRIETARY_MODULE)
DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH)
DEXPREOPT.$(LOCAL_MODULE).INSTALLED := $(installed_odex)
DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE)
DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \
$(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE))
# Make sure to install the .odex when you run "make <module_name>" # Make sure to install the .odex when you run "make <module_name>"
$(my_register_name): $(installed_odex) $(my_register_name): $(installed_odex)

View File

@ -539,6 +539,11 @@ endif
$(foreach mk, $(subdir_makefiles),$(info including $(mk) ...)$(eval include $(mk))) $(foreach mk, $(subdir_makefiles),$(info including $(mk) ...)$(eval include $(mk)))
ifdef PDK_FUSION_PLATFORM_ZIP
# Bring in the PDK platform.zip modules.
include $(BUILD_SYSTEM)/pdk_fusion_modules.mk
endif # PDK_FUSION_PLATFORM_ZIP
endif # dont_bother endif # dont_bother
endif # ONE_SHOT_MAKEFILE endif # ONE_SHOT_MAKEFILE
@ -766,7 +771,7 @@ overridden_packages := $(call get-package-overrides,$(modules_to_install))
ifdef overridden_packages ifdef overridden_packages
# old_modules_to_install := $(modules_to_install) # old_modules_to_install := $(modules_to_install)
modules_to_install := \ modules_to_install := \
$(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \ $(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk %/$(p).odex), \
$(modules_to_install)) $(modules_to_install))
endif endif
#$(error filtered out #$(error filtered out

View File

@ -438,13 +438,17 @@ endif
ifeq ($(full_classes_jar),) ifeq ($(full_classes_jar),)
# We don't build jar, need to add the Java resources here. # We don't build jar, need to add the Java resources here.
$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@)) $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call add-java-resources-to,$@))
else else # full_classes_jar
$(add-dex-to-package) $(add-dex-to-package)
endif endif # full_classes_jar
ifdef LOCAL_JACK_ENABLED ifdef LOCAL_JACK_ENABLED
$(add-carried-jack-resources) $(add-carried-jack-resources)
endif endif
ifdef LOCAL_DEX_PREOPT ifdef LOCAL_DEX_PREOPT
ifneq ($(BUILD_PLATFORM_ZIP),)
@# Keep a copy of apk with classes.dex unstripped
$(hide) cp -f $@ $(dir $@)package.dex.apk
endif # BUILD_PLATFORM_ZIP
ifneq (nostripping,$(LOCAL_DEX_PREOPT)) ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,$@) $(call dexpreopt-remove-classes.dex,$@)
endif endif

View File

@ -0,0 +1,75 @@
# Auto-generate module defitions from platform.zip.
# We use these rules to rebuild .odex files of the .jar/.apk inside the platform.zip.
#
pdk_dexpreopt_config_mk := $(TARGET_OUT_INTERMEDIATES)/pdk_dexpreopt_config.mk
$(shell rm -f $(pdk_dexpreopt_config_mk) && mkdir -p $(dir $(pdk_dexpreopt_config_mk)) && \
unzip -qo $(PDK_FUSION_PLATFORM_ZIP) -d $(dir $(pdk_dexpreopt_config_mk)) pdk_dexpreopt_config.mk 2>/dev/null)
-include $(pdk_dexpreopt_config_mk)
# Define a PDK prebuilt module that comes from platform.zip.
# Must be called with $(eval)
define prebuilt-pdk-java-module
include $(CLEAR_VARS)
LOCAL_MODULE:=$(1)
LOCAL_MODULE_CLASS:=$(2)
# Use LOCAL_PREBUILT_MODULE_FILE instead of LOCAL_SRC_FILES so we don't need to deal with LOCAL_PATH.
LOCAL_PREBUILT_MODULE_FILE:=$(3)
LOCAL_DEX_PREOPT:=$(4)
LOCAL_MULTILIB:=$(5)
LOCAL_DEX_PREOPT_FLAGS:=$(6)
LOCAL_BUILT_MODULE_STEM:=$(7)
LOCAL_MODULE_SUFFIX:=$(suffix $(7))
LOCAL_PRIVILEGED_MODULE:=$(8)
LOCAL_PROPRIETARY_MODULE:=$(9)
LOCAL_MODULE_TARGET_ARCH:=$(10)
LOCAL_REPLACE_PREBUILT_APK_INSTALLED:=$(11)
LOCAL_CERTIFICATE:=PRESIGNED
include $(BUILD_PREBUILT)
# The source prebuilts are extracted in the rule of _pdk_fusion_stamp.
# Use a touch rule to establish the dependency.
$(3) $(11) : $(_pdk_fusion_stamp)
$(hide) if [ ! -f $$@ ]; then \
echo 'Error: $$@ does not exist. Check your platform.zip.' 1>&2; \
exit 1; \
fi
$(hide) touch $$@
endef
##### Java libraries.
# Only set up rules for modules that aren't built from source.
pdk_prebuilt_libraries := $(foreach l,$(PDK.DEXPREOPT.JAVA_LIBRARIES),\
$(if $(MODULE.TARGET.JAVA_LIBRARIES.$(l)),,$(l)))
$(foreach l,$(pdk_prebuilt_libraries), $(eval \
$(call prebuilt-pdk-java-module,\
$(l),\
JAVA_LIBRARIES,\
$(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(l).SRC),\
$(PDK.DEXPREOPT.$(l).DEX_PREOPT),\
$(PDK.DEXPREOPT.$(l).MULTILIB),\
$(PDK.DEXPREOPT.$(l).DEX_PREOPT_FLAGS),\
javalib.jar,\
)))
###### Apps.
pdk_prebuilt_apps := $(foreach a,$(PDK.DEXPREOPT.APPS),\
$(if $(MODULE.TARGET.APPS.$(a)),,$(a)))
$(foreach a,$(pdk_prebuilt_apps), $(eval \
$(call prebuilt-pdk-java-module,\
$(a),\
APPS,\
$(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(a).SRC),\
$(PDK.DEXPREOPT.$(a).DEX_PREOPT),\
$(PDK.DEXPREOPT.$(a).MULTILIB),\
$(PDK.DEXPREOPT.$(a).DEX_PREOPT_FLAGS),\
package.apk,\
$(PDK.DEXPREOPT.$(a).PRIVILEGED_MODULE),\
$(PDK.DEXPREOPT.$(a).PROPRIETARY_MODULE),\
$(PDK.DEXPREOPT.$(a).TARGET_ARCH),\
$(_pdk_fusion_intermediates)/$(PDK.DEXPREOPT.$(a).STRIPPED_SRC),\
)))

View File

@ -77,6 +77,12 @@ ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
endif endif
endif endif
ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE)))
prebuilt_module_is_dex_javalib := true
else
prebuilt_module_is_dex_javalib :=
endif
ifeq ($(LOCAL_MODULE_CLASS),APPS) ifeq ($(LOCAL_MODULE_CLASS),APPS)
LOCAL_BUILT_MODULE_STEM := package.apk LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
@ -203,16 +209,23 @@ else
endif endif
# Disable dex-preopt of prebuilts to save space, if requested. # Disable dex-preopt of prebuilts to save space, if requested.
ifndef LOCAL_DEX_PREOPT
ifeq ($(DONT_DEXPREOPT_PREBUILTS),true) ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
LOCAL_DEX_PREOPT := false LOCAL_DEX_PREOPT := false
endif endif
endif
####################################### #######################################
# defines built_odex along with rule to install odex # defines built_odex along with rule to install odex
include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
####################################### #######################################
# Sign and align non-presigned .apks. ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
# There is a replacement for the prebuilt .apk we can install without any processing.
$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED) | $(ACP)
$(transform-prebuilt-to-target)
else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
# Sign and align non-presigned .apks.
# The embedded prebuilt jni to uncompress. # The embedded prebuilt jni to uncompress.
ifeq ($(LOCAL_CERTIFICATE),PRESIGNED) ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
# For PRESIGNED apks we must uncompress every .so file: # For PRESIGNED apks we must uncompress every .so file:
@ -229,18 +242,25 @@ $(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR) $(AAPT) $(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR) $(AAPT)
$(transform-prebuilt-to-target) $(transform-prebuilt-to-target)
$(uncompress-shared-libs) $(uncompress-shared-libs)
ifdef LOCAL_DEX_PREOPT
ifneq ($(BUILD_PLATFORM_ZIP),)
@# Keep a copy of apk with classes.dex unstripped
$(hide) cp -f $@ $(dir $@)package.dex.apk
endif # BUILD_PLATFORM_ZIP
endif # LOCAL_DEX_PREOPT
ifneq ($(LOCAL_CERTIFICATE),PRESIGNED) ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
@# Only strip out files if we can re-sign the package. @# Only strip out files if we can re-sign the package.
ifdef LOCAL_DEX_PREOPT ifdef LOCAL_DEX_PREOPT
ifneq (nostripping,$(LOCAL_DEX_PREOPT)) ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,$@) $(call dexpreopt-remove-classes.dex,$@)
endif endif # LOCAL_DEX_PREOPT != nostripping
endif endif # LOCAL_DEX_PREOPT
$(sign-package) $(sign-package)
# No need for align-package because sign-package takes care of alignment # No need for align-package because sign-package takes care of alignment
else else # LOCAL_CERTIFICATE == PRESIGNED
$(align-package) $(align-package)
endif endif # LOCAL_CERTIFICATE
endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
############################### ###############################
## Rule to build the odex file ## Rule to build the odex file
@ -284,8 +304,39 @@ $(my_register_name): $(installed_apk_splits)
endif # LOCAL_PACKAGE_SPLITS endif # LOCAL_PACKAGE_SPLITS
else # LOCAL_MODULE_CLASS != APPS else ifeq ($(prebuilt_module_is_dex_javalib),true) # LOCAL_MODULE_CLASS != APPS
# This is a target shared library, i.e. a jar with classes.dex.
#######################################
# defines built_odex along with rule to install odex
include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
#######################################
ifdef LOCAL_DEX_PREOPT
ifneq ($(dexpreopt_boot_jar_module),) # boot jar
# boot jar's rules are defined in dex_preopt.mk
dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
$(built_module) : $(dexpreopted_boot_jar) | $(ACP)
$(call copy-file-to-target)
# For libart boot jars, we don't have .odex files.
else # ! boot jar
$(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE)
# Use pattern rule - we may have multiple built odex files.
$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(my_prebuilt_src_file)
@echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
$(call dexpreopt-one-file,$<,$@)
$(built_module) : $(my_prebuilt_src_file) | $(ACP)
$(call copy-file-to-target)
ifneq (nostripping,$(LOCAL_DEX_PREOPT))
$(call dexpreopt-remove-classes.dex,$@)
endif
endif # boot jar
else # ! LOCAL_DEX_PREOPT
$(built_module) : $(my_prebuilt_src_file) | $(ACP)
$(call copy-file-to-target)
endif # LOCAL_DEX_PREOPT
else # ! prebuilt_module_is_dex_javalib
$(built_module) : $(my_prebuilt_src_file) $(built_module) : $(my_prebuilt_src_file)
ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),) ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
$(transform-prebuilt-to-target-strip-comments) $(transform-prebuilt-to-target-strip-comments)
@ -295,21 +346,25 @@ endif
ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES)
$(hide) chmod +x $@ $(hide) chmod +x $@
endif endif
endif # ! prebuilt_module_is_dex_javalib
endif # LOCAL_MODULE_CLASS != APPS
ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
my_src_jar := $(my_prebuilt_src_file) my_src_jar := $(my_prebuilt_src_file)
ifeq ($(LOCAL_IS_HOST_MODULE),) ifeq ($(LOCAL_IS_HOST_MODULE),)
# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir, # for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
# while the deps should be in the common dir, so we make a copy in the common dir. # while the deps should be in the common dir, so we make a copy in the common dir.
# For nonstatic library, $(common_javalib_jar) is the dependency file,
# while $(common_classes_jar) is used to link.
common_classes_jar := $(intermediates.COMMON)/classes.jar common_classes_jar := $(intermediates.COMMON)/classes.jar
common_javalib_jar := $(intermediates.COMMON)/javalib.jar common_javalib_jar := $(intermediates.COMMON)/javalib.jar
$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE) $(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
ifeq ($(prebuilt_module_is_dex_javalib),true)
# For prebuilt shared Java library we don't have classes.jar.
$(common_javalib_jar) : $(my_src_jar) | $(ACP)
$(transform-prebuilt-to-target)
else # ! prebuilt_module_is_dex_javalib
ifneq ($(filter %.aar, $(my_prebuilt_src_file)),) ifneq ($(filter %.aar, $(my_prebuilt_src_file)),)
# This is .aar file, archive of classes.jar and Android resources. # This is .aar file, archive of classes.jar and Android resources.
my_src_jar := $(intermediates.COMMON)/aar/classes.jar my_src_jar := $(intermediates.COMMON)/aar/classes.jar
@ -321,6 +376,7 @@ $(my_src_jar) : $(my_prebuilt_src_file)
$(hide) touch $@ $(hide) touch $@
endif endif
$(common_classes_jar) : $(my_src_jar) $(common_classes_jar) : $(my_src_jar)
$(transform-prebuilt-to-target) $(transform-prebuilt-to-target)
@ -331,8 +387,11 @@ $(call define-jar-to-toc-rule, $(common_classes_jar))
# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE) # make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
$(built_module) : $(common_javalib_jar) $(built_module) : $(common_javalib_jar)
endif # ! prebuilt_module_is_dex_javalib
endif # LOCAL_IS_HOST_MODULE is not set endif # LOCAL_IS_HOST_MODULE is not set
ifneq ($(prebuilt_module_is_dex_javalib),true)
ifneq ($(LOCAL_JILL_FLAGS),) ifneq ($(LOCAL_JILL_FLAGS),)
$(error LOCAL_JILL_FLAGS is not supported any more, please use jack options in LOCAL_JACK_FLAGS instead) $(error LOCAL_JILL_FLAGS is not supported any more, please use jack options in LOCAL_JACK_FLAGS instead)
endif endif
@ -349,6 +408,7 @@ $(intermediates.COMMON)/classes.jack : $(my_src_jar) \
$(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack $(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack
touch $@ touch $@
endif # ! prebuilt_module_is_dex_javalib
endif # JAVA_LIBRARIES endif # JAVA_LIBRARIES
$(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES) $(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)