1###################################### 2# Compile resource with AAPT2 3# Input variables: 4# - full_android_manifest 5# - my_res_resources 6# - my_overlay_resources 7# - my_compiled_res_base_dir 8# - my_asset_dirs 9# - my_full_asset_paths 10# - my_res_package 11# - R_file_stamp 12# - proguard_options_file 13# - my_generated_res_dirs: Resources generated during the build process and we have to compile them in a single run of aapt2. 14# - my_generated_res_dirs_deps: the dependency to use for my_generated_res_dirs. 15# - my_generated_res_zips: Zip files containing resources 16# - my_apk_split_configs: The configurations for which to generate splits. 17# - built_apk_splits: The paths where AAPT should generate the splits. 18# 19# Output variables: 20# - my_res_resources_flat 21# - my_overlay_resources_flat 22# - my_generated_resources_flata 23# 24###################################### 25 26# Compile all the resource files. 27my_res_resources_flat := \ 28 $(foreach r, $(my_res_resources),\ 29 $(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\ 30 $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\ 31 $(o)) 32 33my_overlay_resources_flat := \ 34 $(foreach r, $(my_overlay_resources),\ 35 $(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\ 36 $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\ 37 $(o)) 38 39my_resources_flata := 40# Compile generated resources 41ifneq ($(my_generated_res_dirs),) 42my_generated_resources_flata := $(my_compiled_res_base_dir)/gen_res.flata 43$(my_generated_resources_flata): PRIVATE_SOURCE_RES_DIRS := $(my_generated_res_dirs) 44$(my_generated_resources_flata) : $(my_generated_res_dirs_deps) $(AAPT2) 45 @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_DIRS)" 46 $(call aapt2-compile-resource-dirs) 47 48my_resources_flata += $(my_generated_resources_flata) 49endif 50 51# Compile zipped resources 52ifneq ($(my_generated_res_zips),) 53my_zipped_resources_flata := $(my_compiled_res_base_dir)/zip_res.flata 54$(my_zipped_resources_flata): PRIVATE_SOURCE_RES_ZIPS := $(my_generated_res_zips) 55$(my_zipped_resources_flata) : $(my_generated_res_zips) $(AAPT2) $(ZIPSYNC) 56 @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_ZIPS)" 57 $(call aapt2-compile-resource-zips) 58 59my_resources_flata += $(my_zipped_resources_flata) 60endif 61 62# Always set --pseudo-localize, it will be stripped out later for release 63# builds that don't want it. 64$(my_res_resources_flat) $(my_overlay_resources_flat) $(my_resources_flata) $(my_generated_resources_flata) $(my_zippped_resources_flata): \ 65 PRIVATE_AAPT2_CFLAGS := --pseudo-localize $(filter --legacy,$(LOCAL_AAPT_FLAGS)) 66 67# TODO(b/78447299): Forbid LOCAL_STATIC_JAVA_AAR_LIBRARIES in aapt2 and remove 68# support for it. 69my_static_library_resources := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),\ 70 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk) 71my_static_library_transitive_resource_packages_lists := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),\ 72 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/transitive-res-packages) 73my_static_library_extra_packages := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),\ 74 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/extra_packages) 75my_shared_library_resources := $(foreach l, $(LOCAL_SHARED_ANDROID_LIBRARIES),\ 76 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk) 77 78ifneq ($(my_static_library_resources),) 79$(my_res_package): PRIVATE_AAPT_FLAGS += --auto-add-overlay 80endif 81 82ifneq ($(my_apk_split_configs),) 83# Join the Split APK paths with their configuration, separated by a ':'. 84$(my_res_package): PRIVATE_AAPT_FLAGS += $(addprefix --split ,$(join $(built_apk_splits),$(addprefix :,$(my_apk_split_configs)))) 85endif 86 87my_srcjar := $(intermediates.COMMON)/aapt2.srcjar 88LOCAL_SRCJARS += $(my_srcjar) 89 90aapt_extra_packages := $(intermediates.COMMON)/extra_packages 91 92$(my_res_package): PRIVATE_RES_FLAT := $(my_res_resources_flat) 93$(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_static_library_resources) $(my_resources_flata) $(my_overlay_resources_flat) 94$(my_res_package): PRIVATE_SHARED_ANDROID_LIBRARIES := $(my_shared_library_resources) 95$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) 96$(my_res_package): PRIVATE_ASSET_DIRS := $(my_asset_dirs) 97$(my_res_package): PRIVATE_JAVA_GEN_DIR := $(intermediates.COMMON)/aapt2 98$(my_res_package): PRIVATE_SRCJAR := $(my_srcjar) 99$(my_res_package): PRIVATE_STATIC_LIBRARY_EXTRA_PACKAGES := $(my_static_library_extra_packages) 100$(my_res_package): PRIVATE_STATIC_LIBRARY_TRANSITIVE_RES_PACKAGES_LISTS := $(my_static_library_transitive_resource_packages_lists) 101$(my_res_package): PRIVATE_AAPT_EXTRA_PACKAGES := $(aapt_extra_packages) 102$(my_res_package): .KATI_IMPLICIT_OUTPUTS := $(my_srcjar) $(aapt_extra_packages) 103 104ifdef R_file_stamp 105$(my_res_package): PRIVATE_R_FILE_STAMP := $(R_file_stamp) 106$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(R_file_stamp) 107endif 108 109resource_export_package := 110ifdef LOCAL_EXPORT_PACKAGE_RESOURCES 111# Put this module's resources into a PRODUCT-agnositc package that 112# other packages can use to build their own PRODUCT-agnostic R.java (etc.) 113# files. 114resource_export_package := $(intermediates.COMMON)/package-export.apk 115$(my_res_package): PRIVATE_RESOURCE_EXPORT_PACKAGE := $(resource_export_package) 116$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(resource_export_package) 117endif 118 119ifdef proguard_options_file 120$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(proguard_options_file) 121endif 122 123$(my_res_package): $(full_android_manifest) $(my_static_library_resources) $(my_static_library_transitive_resource_packages_lists) $(my_shared_library_resources) 124$(my_res_package): $(my_full_asset_paths) 125$(my_res_package): $(my_res_resources_flat) $(my_overlay_resources_flat) \ 126 $(my_resources_flata) $(my_static_library_resources) $(my_static_library_extra_packages) \ 127 $(AAPT2) $(SOONG_ZIP) $(EXTRACT_JAR_PACKAGES) 128 @echo "AAPT2 link $@" 129 $(call aapt2-link) 130ifdef R_file_stamp 131 @rm -f $(PRIVATE_R_FILE_STAMP) 132 $(call find-generated-R.java,$(PRIVATE_JAVA_GEN_DIR),$(PRIVATE_R_FILE_STAMP)) 133endif 134ifdef LOCAL_EXPORT_PACKAGE_RESOURCES 135 @rm -f $(PRIVATE_RESOURCE_EXPORT_PACKAGE) 136 137 cp $@ $(PRIVATE_RESOURCE_EXPORT_PACKAGE) 138endif 139 140# Clear inputs only used in this file, so that they're not re-used during the next build 141my_res_resources := 142my_overlay_resources := 143my_compiled_res_base_dir := 144my_asset_dirs := 145my_full_asset_paths := 146my_apk_split_configs := 147my_generated_res_dirs := 148my_generated_res_dirs_deps := 149my_generated_res_zips := 150