From bc0c494d3af1bce637289e4aceaba90cbdadacba Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 12 Mar 2018 23:33:15 -0700 Subject: [PATCH] Allow aapt2 rules to take zipped resource files Allow aapt2 rules to take zipped resource files similar to the way the javac rules take srcjars. For now, unzip the files using extract_srcjars.sh, and then use aapt2 compile --dir. Eventually it could be done with aapt2 compile --zip. Bug: 73885582 Bug: 74574557 Test: m checkbuild Change-Id: I97ea3ff305e7a9ef2a908b4cf0bca903af62c6b1 --- core/aapt2.mk | 23 ++++++++++++++++++----- core/definitions.mk | 9 +++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/core/aapt2.mk b/core/aapt2.mk index c582e30df9..895bd371f6 100644 --- a/core/aapt2.mk +++ b/core/aapt2.mk @@ -12,6 +12,7 @@ # - proguard_options_file # - my_generated_res_dirs: Resources generated during the build process and we have to compile them in a single run of aapt2. # - my_generated_res_dirs_deps: the dependency to use for my_generated_res_dirs. +# - my_generated_res_zips: Zip files containing resources # - my_apk_split_configs: The configurations for which to generate splits. # - built_apk_splits: The paths where AAPT should generate the splits. # @@ -35,7 +36,7 @@ my_overlay_resources_flat := \ $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\ $(o)) -my_generated_resources_flata := +my_resources_flata := # Compile generated resources ifneq ($(my_generated_res_dirs),) my_generated_resources_flata := $(my_compiled_res_base_dir)/gen_res.flata @@ -44,12 +45,23 @@ $(my_generated_resources_flata) : $(my_generated_res_dirs_deps) $(AAPT2) @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_DIRS)" $(call aapt2-compile-resource-dirs) -my_generated_resources_flata += $(my_generated_resources_flata) +my_resources_flata += $(my_generated_resources_flata) +endif + +# Compile zipped resources +ifneq ($(my_generated_res_zips),) +my_zipped_resources_flata := $(my_compiled_res_base_dir)/zip_res.flata +$(my_zipped_resources_flata): PRIVATE_SOURCE_RES_ZIPS := $(my_generated_res_zips) +$(my_zipped_resources_flata) : $(my_generated_res_deps) $(AAPT2) $(EXTRACT_SRCJARS) + @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_ZIPS)" + $(call aapt2-compile-resource-zips) + +my_resources_flata += $(my_zipped_resources_flata) endif # Always set --pseudo-localize, it will be stripped out later for release # builds that don't want it. -$(my_res_resources_flat) $(my_overlay_resources_flat) $(my_generated_resources_flata): \ +$(my_res_resources_flat) $(my_overlay_resources_flat) $(my_resources_flata): \ PRIVATE_AAPT2_CFLAGS := --pseudo-localize my_static_library_resources := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES)),\ @@ -67,7 +79,7 @@ $(my_res_package): PRIVATE_AAPT_FLAGS += $(addprefix --split ,$(join $(built_apk endif $(my_res_package): PRIVATE_RES_FLAT := $(my_res_resources_flat) -$(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_static_library_resources) $(my_generated_resources_flata) $(my_overlay_resources_flat) +$(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_static_library_resources) $(my_resources_flata) $(my_overlay_resources_flat) $(my_res_package): PRIVATE_SHARED_ANDROID_LIBRARIES := $(my_shared_library_resources) $(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) $(my_res_package): PRIVATE_ASSET_DIRS := $(my_asset_dirs) @@ -95,7 +107,7 @@ endif $(my_res_package): $(full_android_manifest) $(my_static_library_resources) $(my_shared_library_resources) $(my_res_package): $(my_full_asset_paths) $(my_res_package): $(my_res_resources_flat) $(my_overlay_resources_flat) \ - $(my_generated_resources_flata) $(my_static_library_resources) \ + $(my_resources_flata) $(my_static_library_resources) \ $(AAPT2) @echo "AAPT2 link $@" $(call aapt2-link) @@ -118,3 +130,4 @@ my_full_asset_paths := my_apk_split_configs := my_generated_res_dirs := my_generated_res_dirs_deps := +my_generated_res_zips := diff --git a/core/definitions.mk b/core/definitions.mk index 1300115e47..b0dcb01454 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2079,6 +2079,15 @@ $(hide) $(AAPT2) compile -o $@ $(addprefix --dir ,$(PRIVATE_SOURCE_RES_DIRS)) \ $(PRIVATE_AAPT2_CFLAGS) --legacy endef +# TODO(b/74574557): use aapt2 compile --zip if it gets implemented +define aapt2-compile-resource-zips +@mkdir -p $(dir $@) +rm -rf $@.contents +mkdir -p $@.contents +$(EXTRACT_SRCJARS) $@.contents $@.list $(PRIVATE_SOURCE_RES_ZIPS) +$(hide) $(AAPT2) compile -o $@ --dir $@.tmp $(PRIVATE_AAPT2_CFLAGS) --legacy +endef + # Set up rule to compile one resource file with aapt2. # Must be called with $(eval). # $(1): the source file