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