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. |
| 15 | # - my_apk_split_configs: The configurations for which to generate splits. |
| 16 | # - built_apk_splits: The paths where AAPT should generate the splits. |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 17 | # |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 18 | # Output variables: |
Adam Lesinski | 4c45205 | 2016-08-12 12:57:17 -0700 | [diff] [blame] | 19 | # - my_res_resources_flat |
| 20 | # - my_overlay_resources_flat |
| 21 | # - my_generated_resources_flata |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 22 | # |
| 23 | ###################################### |
| 24 | |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 25 | # Compile all the resource files. |
| 26 | my_res_resources_flat := \ |
| 27 | $(foreach r, $(my_res_resources),\ |
| 28 | $(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\ |
| 29 | $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\ |
| 30 | $(o)) |
| 31 | |
| 32 | my_overlay_resources_flat := \ |
| 33 | $(foreach r, $(my_overlay_resources),\ |
| 34 | $(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\ |
| 35 | $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\ |
| 36 | $(o)) |
| 37 | |
| 38 | my_generated_resources_flata := |
| 39 | # Compile generated resources |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 40 | ifneq ($(my_generated_res_dirs),) |
| 41 | my_generated_resources_flata := $(my_compiled_res_base_dir)/gen_res.flata |
| 42 | $(my_generated_resources_flata): PRIVATE_SOURCE_RES_DIRS := $(my_generated_res_dirs) |
Dan Willemsen | c401a62 | 2017-06-08 00:14:32 -0700 | [diff] [blame] | 43 | $(my_generated_resources_flata) : $(my_generated_res_dirs_deps) $(AAPT2) |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 44 | @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_DIRS)" |
| 45 | $(call aapt2-compile-resource-dirs) |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 46 | |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 47 | my_generated_resources_flata += $(my_generated_resources_flata) |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 48 | endif |
| 49 | |
Colin Cross | d5cce4c | 2017-10-27 16:10:18 -0700 | [diff] [blame] | 50 | # Always set --pseudo-localize, it will be stripped out later for release |
| 51 | # builds that don't want it. |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 52 | $(my_res_resources_flat) $(my_overlay_resources_flat) $(my_generated_resources_flata): \ |
Colin Cross | d5cce4c | 2017-10-27 16:10:18 -0700 | [diff] [blame] | 53 | PRIVATE_AAPT2_CFLAGS := --pseudo-localize |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 54 | |
Adam Lesinski | e758f93 | 2016-02-26 11:13:43 -0800 | [diff] [blame] | 55 | my_static_library_resources := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES)),\ |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 56 | $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk) |
| 57 | my_shared_library_resources := $(foreach l, $(LOCAL_SHARED_ANDROID_LIBRARIES),\ |
| 58 | $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk) |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 59 | |
Ying Wang | 75e962a | 2016-03-02 18:55:46 -0800 | [diff] [blame] | 60 | ifneq ($(my_static_library_resources),) |
| 61 | $(my_res_package): PRIVATE_AAPT_FLAGS += --auto-add-overlay |
| 62 | endif |
| 63 | |
Adam Lesinski | 4c45205 | 2016-08-12 12:57:17 -0700 | [diff] [blame] | 64 | ifneq ($(my_apk_split_configs),) |
| 65 | # Join the Split APK paths with their configuration, separated by a ':'. |
| 66 | $(my_res_package): PRIVATE_AAPT_FLAGS += $(addprefix --split ,$(join $(built_apk_splits),$(addprefix :,$(my_apk_split_configs)))) |
| 67 | endif |
| 68 | |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 69 | $(my_res_package): PRIVATE_RES_FLAT := $(my_res_resources_flat) |
Adam Lesinski | e758f93 | 2016-02-26 11:13:43 -0800 | [diff] [blame] | 70 | $(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_static_library_resources) $(my_generated_resources_flata) $(my_overlay_resources_flat) |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 71 | $(my_res_package): PRIVATE_SHARED_ANDROID_LIBRARIES := $(my_shared_library_resources) |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 72 | $(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file) |
Adam Lesinski | 981de83 | 2017-03-16 04:53:05 +0000 | [diff] [blame] | 73 | $(my_res_package): PRIVATE_ASSET_DIRS := $(my_asset_dirs) |
Dan Willemsen | ba9b0fb | 2017-09-29 19:18:21 -0700 | [diff] [blame] | 74 | $(my_res_package): .KATI_IMPLICIT_OUTPUTS := |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 75 | |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 76 | ifdef R_file_stamp |
Dan Willemsen | ba9b0fb | 2017-09-29 19:18:21 -0700 | [diff] [blame] | 77 | $(my_res_package): PRIVATE_R_FILE_STAMP := $(R_file_stamp) |
| 78 | $(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(R_file_stamp) |
Ying Wang | e295c3d | 2016-02-24 14:11:55 -0800 | [diff] [blame] | 79 | endif |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 80 | |
| 81 | resource_export_package := |
| 82 | ifdef LOCAL_EXPORT_PACKAGE_RESOURCES |
| 83 | # Put this module's resources into a PRODUCT-agnositc package that |
| 84 | # other packages can use to build their own PRODUCT-agnostic R.java (etc.) |
| 85 | # files. |
| 86 | resource_export_package := $(intermediates.COMMON)/package-export.apk |
Dan Willemsen | ba9b0fb | 2017-09-29 19:18:21 -0700 | [diff] [blame] | 87 | $(my_res_package): PRIVATE_RESOURCE_EXPORT_PACKAGE := $(resource_export_package) |
| 88 | $(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(resource_export_package) |
| 89 | endif |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 90 | |
Dan Willemsen | ba9b0fb | 2017-09-29 19:18:21 -0700 | [diff] [blame] | 91 | ifdef proguard_options_file |
| 92 | $(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(proguard_options_file) |
| 93 | endif |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 94 | |
Dan Willemsen | ba9b0fb | 2017-09-29 19:18:21 -0700 | [diff] [blame] | 95 | $(my_res_package): $(full_android_manifest) $(my_static_library_resources) $(my_shared_library_resources) |
| 96 | $(my_res_package): $(my_full_asset_paths) |
| 97 | $(my_res_package): $(my_res_resources_flat) $(my_overlay_resources_flat) \ |
| 98 | $(my_generated_resources_flata) $(my_static_library_resources) \ |
| 99 | $(AAPT2) |
| 100 | @echo "AAPT2 link $@" |
| 101 | $(call aapt2-link) |
| 102 | ifdef R_file_stamp |
| 103 | @rm -f $(PRIVATE_R_FILE_STAMP) |
| 104 | $(call find-generated-R.java,$(PRIVATE_R_FILE_STAMP)) |
| 105 | endif |
| 106 | ifdef LOCAL_EXPORT_PACKAGE_RESOURCES |
| 107 | @rm -f $(PRIVATE_RESOURCE_EXPORT_PACKAGE) |
| 108 | |
| 109 | cp $@ $(PRIVATE_RESOURCE_EXPORT_PACKAGE) |
Ying Wang | dd71c85 | 2015-12-04 13:59:18 -0800 | [diff] [blame] | 110 | endif |
Dan Willemsen | d927abe | 2017-11-15 17:00:46 -0800 | [diff] [blame] | 111 | |
| 112 | # Clear inputs only used in this file, so that they're not re-used during the next build |
| 113 | my_res_resources := |
| 114 | my_overlay_resources := |
| 115 | my_compiled_res_base_dir := |
| 116 | my_asset_dirs := |
| 117 | my_full_asset_paths := |
| 118 | my_apk_split_configs := |
| 119 | my_generated_res_dirs := |
| 120 | my_generated_res_dirs_deps := |