blob: fbbf3dd58f28deb8431d0b611cf5ecd68168043a [file] [log] [blame]
Ying Wangdd71c852015-12-04 13:59:18 -08001######################################
2# Compile resource with AAPT2
3# Input variables:
Adam Lesinski4c452052016-08-12 12:57:17 -07004# - full_android_manifest
5# - my_res_resources
6# - my_overlay_resources
7# - my_compiled_res_base_dir
Adam Lesinski981de832017-03-16 04:53:05 +00008# - my_asset_dirs
9# - my_full_asset_paths
Adam Lesinski4c452052016-08-12 12:57:17 -070010# - 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 Crossbc0c4942018-03-12 23:33:15 -070015# - my_generated_res_zips: Zip files containing resources
Adam Lesinski4c452052016-08-12 12:57:17 -070016# - my_apk_split_configs: The configurations for which to generate splits.
17# - built_apk_splits: The paths where AAPT should generate the splits.
Ying Wange295c3d2016-02-24 14:11:55 -080018#
Ying Wangdd71c852015-12-04 13:59:18 -080019# Output variables:
Adam Lesinski4c452052016-08-12 12:57:17 -070020# - my_res_resources_flat
21# - my_overlay_resources_flat
22# - my_generated_resources_flata
Ying Wangdd71c852015-12-04 13:59:18 -080023#
24######################################
25
Ying Wangdd71c852015-12-04 13:59:18 -080026# 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
Colin Crossbc0c4942018-03-12 23:33:15 -070039my_resources_flata :=
Ying Wangdd71c852015-12-04 13:59:18 -080040# Compile generated resources
Ying Wange295c3d2016-02-24 14:11:55 -080041ifneq ($(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)
Dan Willemsenc401a622017-06-08 00:14:32 -070044$(my_generated_resources_flata) : $(my_generated_res_dirs_deps) $(AAPT2)
Ying Wange295c3d2016-02-24 14:11:55 -080045 @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_DIRS)"
46 $(call aapt2-compile-resource-dirs)
Ying Wangdd71c852015-12-04 13:59:18 -080047
Colin Crossbc0c4942018-03-12 23:33:15 -070048my_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)
Colin Cross14658062018-05-15 16:04:47 -070055$(my_zipped_resources_flata) : $(my_generated_res_zips) $(AAPT2) $(ZIPSYNC)
Colin Crossbc0c4942018-03-12 23:33:15 -070056 @echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_ZIPS)"
57 $(call aapt2-compile-resource-zips)
58
59my_resources_flata += $(my_zipped_resources_flata)
Ying Wangdd71c852015-12-04 13:59:18 -080060endif
61
Colin Crossd5cce4c2017-10-27 16:10:18 -070062# Always set --pseudo-localize, it will be stripped out later for release
63# builds that don't want it.
Colin Crossbc0c4942018-03-12 23:33:15 -070064$(my_res_resources_flat) $(my_overlay_resources_flat) $(my_resources_flata): \
Colin Crossd5cce4c2017-10-27 16:10:18 -070065 PRIVATE_AAPT2_CFLAGS := --pseudo-localize
Ying Wangdd71c852015-12-04 13:59:18 -080066
Colin Cross71c5b952018-05-23 13:35:53 -070067# 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)),\
Ying Wange295c3d2016-02-24 14:11:55 -080070 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk)
Colin Cross71c5b952018-05-23 13:35:53 -070071my_static_library_extra_packages := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),\
Colin Cross43c247e2018-05-02 12:52:43 -070072 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/extra_packages)
Ying Wange295c3d2016-02-24 14:11:55 -080073my_shared_library_resources := $(foreach l, $(LOCAL_SHARED_ANDROID_LIBRARIES),\
74 $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk)
Ying Wangdd71c852015-12-04 13:59:18 -080075
Ying Wang75e962a2016-03-02 18:55:46 -080076ifneq ($(my_static_library_resources),)
77$(my_res_package): PRIVATE_AAPT_FLAGS += --auto-add-overlay
78endif
79
Adam Lesinski4c452052016-08-12 12:57:17 -070080ifneq ($(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))))
83endif
84
Colin Crossf6d68cf2018-03-08 16:49:16 -080085my_srcjar := $(intermediates.COMMON)/aapt2.srcjar
86LOCAL_SRCJARS += $(my_srcjar)
87
Colin Cross43c247e2018-05-02 12:52:43 -070088aapt_extra_packages := $(intermediates.COMMON)/extra_packages
89
Ying Wangdd71c852015-12-04 13:59:18 -080090$(my_res_package): PRIVATE_RES_FLAT := $(my_res_resources_flat)
Colin Crossbc0c4942018-03-12 23:33:15 -070091$(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_static_library_resources) $(my_resources_flata) $(my_overlay_resources_flat)
Ying Wange295c3d2016-02-24 14:11:55 -080092$(my_res_package): PRIVATE_SHARED_ANDROID_LIBRARIES := $(my_shared_library_resources)
Ying Wangdd71c852015-12-04 13:59:18 -080093$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
Adam Lesinski981de832017-03-16 04:53:05 +000094$(my_res_package): PRIVATE_ASSET_DIRS := $(my_asset_dirs)
Colin Crossf6d68cf2018-03-08 16:49:16 -080095$(my_res_package): PRIVATE_JAVA_GEN_DIR := $(intermediates.COMMON)/aapt2
96$(my_res_package): PRIVATE_SRCJAR := $(my_srcjar)
Colin Cross43c247e2018-05-02 12:52:43 -070097$(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 Wangdd71c852015-12-04 13:59:18 -0800100
Ying Wange295c3d2016-02-24 14:11:55 -0800101ifdef R_file_stamp
Dan Willemsenba9b0fb2017-09-29 19:18:21 -0700102$(my_res_package): PRIVATE_R_FILE_STAMP := $(R_file_stamp)
103$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(R_file_stamp)
Ying Wange295c3d2016-02-24 14:11:55 -0800104endif
Ying Wangdd71c852015-12-04 13:59:18 -0800105
106resource_export_package :=
107ifdef 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.
111resource_export_package := $(intermediates.COMMON)/package-export.apk
Dan Willemsenba9b0fb2017-09-29 19:18:21 -0700112$(my_res_package): PRIVATE_RESOURCE_EXPORT_PACKAGE := $(resource_export_package)
113$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(resource_export_package)
114endif
Ying Wangdd71c852015-12-04 13:59:18 -0800115
Dan Willemsenba9b0fb2017-09-29 19:18:21 -0700116ifdef proguard_options_file
117$(my_res_package): .KATI_IMPLICIT_OUTPUTS += $(proguard_options_file)
118endif
Ying Wangdd71c852015-12-04 13:59:18 -0800119
Dan Willemsenba9b0fb2017-09-29 19:18:21 -0700120$(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 Cross43c247e2018-05-02 12:52:43 -0700123 $(my_resources_flata) $(my_static_library_resources) $(my_static_library_extra_packages) \
124 $(AAPT2) $(SOONG_ZIP) $(EXTRACT_JAR_PACKAGES)
Dan Willemsenba9b0fb2017-09-29 19:18:21 -0700125 @echo "AAPT2 link $@"
126 $(call aapt2-link)
127ifdef R_file_stamp
128 @rm -f $(PRIVATE_R_FILE_STAMP)
Colin Crossf6d68cf2018-03-08 16:49:16 -0800129 $(call find-generated-R.java,$(PRIVATE_JAVA_GEN_DIR),$(PRIVATE_R_FILE_STAMP))
Dan Willemsenba9b0fb2017-09-29 19:18:21 -0700130endif
131ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
132 @rm -f $(PRIVATE_RESOURCE_EXPORT_PACKAGE)
133
134 cp $@ $(PRIVATE_RESOURCE_EXPORT_PACKAGE)
Ying Wangdd71c852015-12-04 13:59:18 -0800135endif
Dan Willemsend927abe2017-11-15 17:00:46 -0800136
137# Clear inputs only used in this file, so that they're not re-used during the next build
138my_res_resources :=
139my_overlay_resources :=
140my_compiled_res_base_dir :=
141my_asset_dirs :=
142my_full_asset_paths :=
143my_apk_split_configs :=
144my_generated_res_dirs :=
145my_generated_res_dirs_deps :=
Colin Crossbc0c4942018-03-12 23:33:15 -0700146my_generated_res_zips :=