blob: 1b4062429823856b09842a35193865fc8f06305e [file] [log] [blame]
Colin Cross8e404122014-02-06 14:45:37 -08001#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17###########################################################
18## Standard rules for building an application package.
19##
20## Additional inputs from base_rules.make:
21## LOCAL_PACKAGE_NAME: The name of the package; the directory
22## will be called this.
23##
24## MODULE, MODULE_PATH, and MODULE_SUFFIX will
25## be set for you.
26###########################################################
27
Colin Cross8e404122014-02-06 14:45:37 -080028LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
29ifeq ($(LOCAL_PACKAGE_NAME),)
30$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
31endif
32
33ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
34$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
35endif
36LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
37
38ifneq ($(strip $(LOCAL_MODULE)),)
39$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
40endif
41LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
42
Colin Cross8e404122014-02-06 14:45:37 -080043ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
44$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
45endif
46LOCAL_MODULE_CLASS := APPS
47
Ying Wangdd71c852015-12-04 13:59:18 -080048intermediates := $(call local-intermediates-dir)
49intermediates.COMMON := $(call local-intermediates-dir,COMMON)
50
Colin Cross8e404122014-02-06 14:45:37 -080051# Package LOCAL_MODULE_TAGS default to optional
52LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
53ifeq ($(LOCAL_MODULE_TAGS),)
54LOCAL_MODULE_TAGS := optional
55endif
56
57ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
58# Force localization check if it's not tagged as tests.
59LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
60endif
61
Ying Wang4cb04992014-07-29 10:34:30 -070062need_compile_asset :=
Colin Cross8e404122014-02-06 14:45:37 -080063ifeq (,$(LOCAL_ASSET_DIR))
64LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
Ying Wang4cb04992014-07-29 10:34:30 -070065else
66need_compile_asset := true
Colin Cross8e404122014-02-06 14:45:37 -080067endif
68
Ying Wang61291922014-06-25 13:23:58 -070069# LOCAL_RESOURCE_DIR may point to resource generated during the build
70need_compile_res :=
Colin Cross8e404122014-02-06 14:45:37 -080071ifeq (,$(LOCAL_RESOURCE_DIR))
72 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
Ying Wang61291922014-06-25 13:23:58 -070073else
74 need_compile_res := true
Dan Willemsenfa7ecfb2017-05-02 23:55:44 -070075 LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d)))
Colin Cross8e404122014-02-06 14:45:37 -080076endif
77
Jiyong Park185d41e2019-01-05 12:57:54 +090078# If LOCAL_MODULE matches a rule in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES,
Jiyong Park9ee3a162019-01-16 01:07:35 +090079# override the manifest package name by the (first) rule matched
Jiyong Park185d41e2019-01-05 12:57:54 +090080override_manifest_name := $(strip $(word 1,\
81 $(foreach rule,$(PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES),\
82 $(eval _pkg_name_pat := $(call word-colon,1,$(rule)))\
83 $(eval _manifest_name_pat := $(call word-colon,2,$(rule)))\
84 $(if $(filter $(_pkg_name_pat),$(LOCAL_MODULE)),\
85 $(patsubst $(_pkg_name_pat),$(_manifest_name_pat),$(LOCAL_MODULE))\
86 )\
87 )\
88))
89
90ifneq (,$(override_manifest_name))
Jiyong Park9ee3a162019-01-16 01:07:35 +090091# Note: this can override LOCAL_MANIFEST_PACKAGE_NAME value set in Android.mk
Jiyong Park185d41e2019-01-05 12:57:54 +090092LOCAL_MANIFEST_PACKAGE_NAME := $(override_manifest_name)
93endif
94
Colin Cross20299032018-05-09 13:29:51 -070095include $(BUILD_SYSTEM)/force_aapt2.mk
96
Colin Cross7bc6cab2018-05-17 15:05:47 -070097# Process Support Library dependencies.
98include $(BUILD_SYSTEM)/support_libraries.mk
99
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000100# Determine whether auto-RRO is enabled for this package.
101enforce_rro_enabled :=
Yo Chiang4693fd12019-10-01 12:55:26 +0800102ifneq (,$(filter *, $(PRODUCT_ENFORCE_RRO_TARGETS)))
Jeongik Chad99e77d2020-03-09 12:31:23 +0900103 # * means all system and system_ext APKs, so enable conditionally based on module path.
104 # Note that modules in PRODUCT_ENFORCE_RRO_EXEMPTED_TARGETS are excluded even if it is '*'
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000105
106 # Note that base_rules.mk has not yet been included, so it's likely that only
107 # one of LOCAL_MODULE_PATH and the LOCAL_X_MODULE flags has been set.
108 ifeq (,$(LOCAL_MODULE_PATH))
Jeongik Chad99e77d2020-03-09 12:31:23 +0900109 non_rro_target_module := $(filter true,\
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000110 $(LOCAL_ODM_MODULE) \
111 $(LOCAL_OEM_MODULE) \
112 $(LOCAL_PRODUCT_MODULE) \
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000113 $(LOCAL_PROPRIETARY_MODULE) \
114 $(LOCAL_VENDOR_MODULE))
Jeongik Chad99e77d2020-03-09 12:31:23 +0900115 enforce_rro_enabled := $(if $(non_rro_target_module),,true)
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000116 else ifneq ($(filter $(TARGET_OUT)/%,$(LOCAL_MODULE_PATH)),)
117 enforce_rro_enabled := true
118 endif
119else ifneq (,$(filter $(LOCAL_PACKAGE_NAME), $(PRODUCT_ENFORCE_RRO_TARGETS)))
120 enforce_rro_enabled := true
121endif
122
Jeongik Chad99e77d2020-03-09 12:31:23 +0900123# TODO(b/150820813) Some modules depend on static overlay, remove this after eliminating the dependency.
124ifneq (,$(filter $(LOCAL_PACKAGE_NAME), $(PRODUCT_ENFORCE_RRO_EXEMPTED_TARGETS)))
125 enforce_rro_enabled :=
126endif
127
128
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000129product_package_overlays := $(strip \
Colin Cross8e404122014-02-06 14:45:37 -0800130 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000131 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
132device_package_overlays := $(strip \
Colin Cross8e404122014-02-06 14:45:37 -0800133 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
134 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
135
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000136static_resource_overlays :=
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000137runtime_resource_overlays_product :=
138runtime_resource_overlays_vendor :=
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900139ifdef enforce_rro_enabled
140 ifneq ($(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS),)
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000141 # The PRODUCT_ exclusion variable applies to both inclusion variables..
142 static_resource_overlays += $(filter $(addsuffix %,$(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS)),$(product_package_overlays))
143 static_resource_overlays += $(filter $(addsuffix %,$(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS)),$(device_package_overlays))
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900144 endif
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000145 runtime_resource_overlays_product := $(filter-out $(static_resource_overlays),$(product_package_overlays))
146 runtime_resource_overlays_vendor := $(filter-out $(static_resource_overlays),$(device_package_overlays))
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900147else
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000148 static_resource_overlays := $(product_package_overlays) $(device_package_overlays)
Jaekyun Seok30706102017-02-02 00:44:58 +0900149endif
Colin Cross8e404122014-02-06 14:45:37 -0800150
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000151# Add the static overlays. Auto-RRO is created later, as it depends on
152# other logic in this file.
153LOCAL_RESOURCE_DIR := $(static_resource_overlays) $(LOCAL_RESOURCE_DIR)
154
Colin Cross2c321442014-02-12 13:06:30 -0800155all_assets := $(strip \
156 $(foreach dir, $(LOCAL_ASSET_DIR), \
157 $(addprefix $(dir)/, \
158 $(patsubst assets/%,%, \
159 $(call find-subdir-assets, $(dir)) \
160 ) \
161 ) \
162 ))
Colin Cross8e404122014-02-06 14:45:37 -0800163
Ying Wang4cb04992014-07-29 10:34:30 -0700164ifneq ($(all_assets),)
165need_compile_asset := true
166endif
167
Adam Lesinskie758f932016-02-26 11:13:43 -0800168my_res_package :=
Ying Wangdd71c852015-12-04 13:59:18 -0800169# In aapt2 the last takes precedence.
170my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
Adam Lesinskie758f932016-02-26 11:13:43 -0800171my_res_dir :=
172my_overlay_res_dirs :=
173
Colin Cross71c5b952018-05-23 13:35:53 -0700174ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),)
Adam Lesinskie758f932016-02-26 11:13:43 -0800175# If we are using static android libraries, every source file becomes an overlay.
176# This is to emulate old AAPT behavior which simulated library support.
177my_res_dir :=
178my_overlay_res_dirs := $(my_resource_dirs)
179else
180# Without static libraries, the first directory is our directory, which can then be
181# overlaid by the rest. (First directory in my_resource_dirs is last directory in
182# $(LOCAL_RESOURCE_DIR) due to it being reversed.
183my_res_dir := $(firstword $(my_resource_dirs))
184my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs))
185endif
186
Ying Wangdd71c852015-12-04 13:59:18 -0800187my_overlay_resources := $(strip \
Adam Lesinskie758f932016-02-26 11:13:43 -0800188 $(foreach d,$(my_overlay_res_dirs),\
Ying Wangdd71c852015-12-04 13:59:18 -0800189 $(addprefix $(d)/, \
190 $(call find-subdir-assets,$(d)))))
191
Colin Crossfe109632016-11-29 11:12:56 -0800192my_res_resources := $(if $(my_res_dir),$(strip \
Ying Wangdd71c852015-12-04 13:59:18 -0800193 $(addprefix $(my_res_dir)/, \
Colin Crossfe109632016-11-29 11:12:56 -0800194 $(call find-subdir-assets,$(my_res_dir)))))
Ying Wangdd71c852015-12-04 13:59:18 -0800195
196all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
197
198# The linked resource package.
199my_res_package := $(intermediates)/package-res.apk
200LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
201
Colin Crosse6210f62019-02-25 22:21:24 -0800202my_bundle_module := $(intermediates)/base.zip
203LOCAL_INTERMEDIATE_TARGETS += $(my_bundle_module)
Colin Cross35eb2e32018-11-01 20:34:08 +0000204
Ying Wange5853972016-03-01 12:06:47 -0800205# Always run aapt2, because we need to at least compile the AndroidManifest.xml.
Ying Wangdd71c852015-12-04 13:59:18 -0800206need_compile_res := true
207
Ying Wang61291922014-06-25 13:23:58 -0700208ifneq ($(all_resources),)
209 need_compile_res := true
210endif
211
Colin Cross8e404122014-02-06 14:45:37 -0800212all_res_assets := $(strip $(all_assets) $(all_resources))
213
Colin Cross8e404122014-02-06 14:45:37 -0800214# If no assets or resources were found, clear the directory variables so
215# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700216ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800217LOCAL_ASSET_DIR:=
218endif
Ying Wang61291922014-06-25 13:23:58 -0700219ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800220LOCAL_RESOURCE_DIR:=
221R_file_stamp :=
222else
223# Make sure that R_file_stamp inherits the proper PRIVATE vars.
224# If R.stamp moves, be sure to update the framework makefile,
225# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800226R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800227LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
228endif
229
Narayan Kamath7c205102017-08-07 12:31:17 +0100230ifdef LOCAL_COMPRESSED_MODULE
231ifneq (true,$(LOCAL_COMPRESSED_MODULE))
232$(call pretty-error, Unknown value for LOCAL_COMPRESSED_MODULE $(LOCAL_COMPRESSED_MODULE))
233endif
234endif
235
236ifdef LOCAL_COMPRESSED_MODULE
Narayan Kamath6a4bd692017-08-14 10:53:50 +0100237PACKAGES.$(LOCAL_PACKAGE_NAME).COMPRESSED := gz
Narayan Kamath7c205102017-08-07 12:31:17 +0100238LOCAL_BUILT_MODULE_STEM := package.apk.gz
239LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk.gz
240else # !LOCAL_COMPRESSED_MODULE
Colin Cross8e404122014-02-06 14:45:37 -0800241LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700242LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Narayan Kamath7c205102017-08-07 12:31:17 +0100243endif
Colin Cross8e404122014-02-06 14:45:37 -0800244
245LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
246ifndef LOCAL_PROGUARD_ENABLED
247ifneq ($(DISABLE_PROGUARD),true)
248 LOCAL_PROGUARD_ENABLED :=full
249endif
250endif
251ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
252 # the package explicitly request to disable proguard.
253 LOCAL_PROGUARD_ENABLED :=
254endif
255proguard_options_file :=
256ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700257ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800258 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700259endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800260endif # !custom
261LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
Dan Willemsen829abae2019-08-09 09:14:45 -0700262LOCAL_PROGUARD_FLAGS_DEPS += $(proguard_options_file)
Colin Cross8e404122014-02-06 14:45:37 -0800263
264ifeq (true,$(EMMA_INSTRUMENT))
265ifndef LOCAL_EMMA_INSTRUMENT
Jeff Gastonaaae43c2017-04-11 16:36:46 -0700266# No jacoco for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800267ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800268LOCAL_EMMA_INSTRUMENT := true
269endif # No test apk
270endif # LOCAL_EMMA_INSTRUMENT is not set
271else
272LOCAL_EMMA_INSTRUMENT := false
273endif # EMMA_INSTRUMENT is true
274
275ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
276ifeq (true,$(EMMA_INSTRUMENT_STATIC))
Colin Cross11e2d552018-03-07 15:44:54 -0800277ifneq ($(LOCAL_SRC_FILES)$(LOCAL_SRCJARS)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
Colin Cross79e2f732016-12-21 14:29:13 -0800278# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100279LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Colin Crossdc4a6b82018-01-03 12:39:11 -0800280# Exclude jacoco classes from proguard
281LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Dan Willemsen829abae2019-08-09 09:14:45 -0700282LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800283endif # Contains java code
284else
Colin Cross8e404122014-02-06 14:45:37 -0800285ifdef LOCAL_SDK_VERSION
286ifdef TARGET_BUILD_APPS
Sebastien Hertz2319e562016-03-31 16:48:26 +0200287# In unbundled build, merge the coverage library into the apk.
Colin Cross79e2f732016-12-21 14:29:13 -0800288ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
289# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100290LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Sebastien Hertz2319e562016-03-31 16:48:26 +0200291# Exclude jacoco classes from proguard
292LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Dan Willemsen829abae2019-08-09 09:14:45 -0700293LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800294endif # Contains java code
Colin Crosse673deb2017-09-27 14:28:41 -0700295endif # TARGET_BUILD_APPS
Colin Cross8e404122014-02-06 14:45:37 -0800296endif # LOCAL_SDK_VERSION
Colin Cross79e2f732016-12-21 14:29:13 -0800297endif # EMMA_INSTRUMENT_STATIC
Colin Cross8e404122014-02-06 14:45:37 -0800298endif # LOCAL_EMMA_INSTRUMENT
299
300rs_compatibility_jni_libs :=
301
Narayan Kamath7c205102017-08-07 12:31:17 +0100302# If the module is a compressed module, we don't pre-opt it because its final
303# installation location will be the data partition.
304ifdef LOCAL_COMPRESSED_MODULE
305LOCAL_DEX_PREOPT := false
306endif
307
Colin Crossead7b662019-02-06 16:36:32 -0800308# Default to use uncompressed native libraries in APKs if minSdkVersion >= marshmallow
309ifndef LOCAL_USE_EMBEDDED_NATIVE_LIBS
310 LOCAL_USE_EMBEDDED_NATIVE_LIBS := $(call math_gt_or_eq, \
311 $(patsubst $(PLATFORM_VERSION_CODENAME),100,$(call module-min-sdk-version)),23)
312endif
313
Ying Wange9dd9f22014-10-29 15:48:32 -0700314include $(BUILD_SYSTEM)/android_manifest.mk
315
Colin Cross7a281582018-03-06 16:21:36 -0800316resource_export_package :=
317
318include $(BUILD_SYSTEM)/java_renderscript.mk
319
320include $(BUILD_SYSTEM)/aapt_flags.mk
321
322ifeq ($(need_compile_res),true)
323
324###############################
325## APK splits
326built_apk_splits :=
327installed_apk_splits :=
328my_apk_split_configs :=
329
330ifdef LOCAL_PACKAGE_SPLITS
331ifdef LOCAL_COMPRESSED_MODULE
332$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs)
333endif # LOCAL_COMPRESSED_MODULE
334
335my_apk_split_configs := $(LOCAL_PACKAGE_SPLITS)
336my_split_suffixes := $(subst $(comma),_,$(my_apk_split_configs))
337built_apk_splits := $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk)
338endif
339
Colin Cross18f28c72019-06-22 13:03:09 -0700340$(R_file_stamp) $(my_res_package): PRIVATE_AAPT_FLAGS := $(filter-out --legacy,$(LOCAL_AAPT_FLAGS))
Colin Cross7a281582018-03-06 16:21:36 -0800341$(R_file_stamp) $(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
342$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
343$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
344
345###############################
Colin Crosse6210f62019-02-25 22:21:24 -0800346## AAPT2
Colin Cross7a281582018-03-06 16:21:36 -0800347
Colin Crosse6210f62019-02-25 22:21:24 -0800348my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res
349ifneq (,$(filter-out current,$(renderscript_target_api)))
350 ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true)
351 my_generated_res_zips := $(rs_generated_res_zip)
352 endif # renderscript_target_api < 21
353endif # renderscript_target_api is set
354my_asset_dirs := $(LOCAL_ASSET_DIR)
355my_full_asset_paths := $(all_assets)
Colin Cross7a281582018-03-06 16:21:36 -0800356
Colin Crosse6210f62019-02-25 22:21:24 -0800357# Add AAPT2 link specific flags.
Colin Crosse6210f62019-02-25 22:21:24 -0800358ifndef LOCAL_AAPT_NAMESPACES
359 $(my_res_package): PRIVATE_AAPT_FLAGS += --no-static-lib-packages
360endif
Colin Cross7a281582018-03-06 16:21:36 -0800361
Colin Crosse6210f62019-02-25 22:21:24 -0800362include $(BUILD_SYSTEM)/aapt2.mk
Colin Cross7a281582018-03-06 16:21:36 -0800363
364endif # need_compile_res
365
Colin Cross6db5b0e2018-11-16 21:26:33 -0800366my_dex_jar := $(intermediates.COMMON)/dex.jar
367
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100368called_from_package_internal := true
Colin Cross8e404122014-02-06 14:45:37 -0800369#################################
370include $(BUILD_SYSTEM)/java.mk
371#################################
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100372called_from_package_internal :=
Colin Cross8e404122014-02-06 14:45:37 -0800373
Colin Cross7a281582018-03-06 16:21:36 -0800374ifeq ($(need_compile_res),true)
375
376# Other modules should depend on the BUILT module if
377# they want to use this module's R.java file.
378$(LOCAL_BUILT_MODULE): $(R_file_stamp)
379
Dan Willemsene1cbfc72020-04-28 15:55:49 -0700380ifneq ($(full_classes_jar),)
Colin Cross7a281582018-03-06 16:21:36 -0800381# The R.java file must exist by the time the java source
382# list is generated
383$(java_source_list_file): $(R_file_stamp)
Dan Willemsene1cbfc72020-04-28 15:55:49 -0700384endif
Colin Cross7a281582018-03-06 16:21:36 -0800385
386endif # need_compile_res
387
Colin Cross8e404122014-02-06 14:45:37 -0800388LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
389ifeq ($(LOCAL_SDK_RES_VERSION),)
390 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
391endif
392
Colin Cross8e404122014-02-06 14:45:37 -0800393$(LOCAL_INTERMEDIATE_TARGETS): \
394 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Colin Cross8e404122014-02-06 14:45:37 -0800395
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800396framework_res_package_export :=
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800397
398ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Colin Cross8e404122014-02-06 14:45:37 -0800399# Most packages should link against the resources defined by framework-res.
400# Even if they don't have their own resources, they may use framework
401# resources.
Dan Willemsenc51b7b02018-02-16 13:31:17 -0800402ifeq ($(LOCAL_SDK_RES_VERSION),core_current)
403# core_current doesn't contain any framework resources.
Jeongik Chad05b57a2020-07-08 18:10:38 +0900404else ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_USE_PREBUILT_SDKS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),)
Colin Cross8e404122014-02-06 14:45:37 -0800405# for released sdk versions, the platform resources were built into android.jar.
406framework_res_package_export := \
Anton Hansson66d47b82018-04-27 14:11:17 +0100407 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION))
Colin Cross8e404122014-02-06 14:45:37 -0800408else # LOCAL_SDK_RES_VERSION
409framework_res_package_export := \
410 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
Colin Cross8e404122014-02-06 14:45:37 -0800411endif # LOCAL_SDK_RES_VERSION
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800412endif # LOCAL_NO_STANDARD_LIBRARIES
413
Adam Lesinskide057c32014-03-13 18:48:27 -0700414all_library_res_package_exports := \
415 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700416 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700417 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
418
419all_library_res_package_export_deps := \
Colin Cross6e136922018-02-20 14:31:33 -0800420 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700421 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700422 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
Ying Wangb5745642014-06-19 16:07:30 -0700423$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800424$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700425 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Ying Wangdd71c852015-12-04 13:59:18 -0800426
Ying Wangdd71c852015-12-04 13:59:18 -0800427$(my_res_package) : $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800428
429ifneq ($(full_classes_jar),)
430$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Colin Cross79e2f732016-12-21 14:29:13 -0800431# Use the jarjar processed arhive as the initial package file.
Colin Crossffbf0a62017-03-29 12:58:15 -0700432$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
Dan Willemsenf14179b2019-06-12 21:18:31 +0000433$(LOCAL_BUILT_MODULE): $(built_dex) $(full_classes_pre_proguard_jar)
Ying Wang33360dd2015-01-14 14:23:56 -0800434else
435$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
Colin Cross79e2f732016-12-21 14:29:13 -0800436$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800437endif # full_classes_jar
438
Ying Wang96bcad42014-04-17 13:38:04 -0700439include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800440
441# Pick a key to sign the package with. If this package hasn't specified
442# an explicit certificate, use the default.
443# Secure release builds will have their packages signed after the fact,
444# so it's ok for these private keys to be in the clear.
445ifeq ($(LOCAL_CERTIFICATE),)
446 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
447endif
448
449ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
450 # The special value "EXTERNAL" means that we will sign it with the
451 # default devkey, apply predexopt, but then expect the final .apk
452 # (after dexopting) to be signed by an outside tool.
453 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
454 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
455endif
456
457# If this is not an absolute certificate, assign it to a generic one.
458ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
459 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
460endif
Jeongik Chab2c4bb72018-12-17 14:45:15 +0900461include $(BUILD_SYSTEM)/app_certificate_validate.mk
Colin Cross8e404122014-02-06 14:45:37 -0800462private_key := $(LOCAL_CERTIFICATE).pk8
463certificate := $(LOCAL_CERTIFICATE).x509.pem
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900464additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
Colin Cross8e404122014-02-06 14:45:37 -0800465
Colin Crossf272adb2019-08-08 12:56:01 -0700466$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR) $(SIGNAPK_JNI_LIBRARY_PATH)
Colin Cross8e404122014-02-06 14:45:37 -0800467$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
468$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
469
470PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
471PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
472
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900473$(LOCAL_BUILT_MODULE): $(additional_certificates)
474$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
Colin Cross8e404122014-02-06 14:45:37 -0800475
Jaewoong Jung95445e62020-04-02 13:01:08 -0700476$(LOCAL_BUILT_MODULE): $(LOCAL_CERTIFICATE_LINEAGE)
477$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE_LINEAGE := $(LOCAL_CERTIFICATE_LINEAGE)
478
Bill Peckham19c3feb2020-03-20 18:31:43 -0700479# Set a actual_partition_tag (calculated in base_rules.mk) for the package.
480PACKAGES.$(LOCAL_PACKAGE_NAME).PARTITION := $(actual_partition_tag)
481
Colin Cross56199af2019-05-22 10:25:59 -0700482# Verify LOCAL_USES_LIBRARIES/LOCAL_OPTIONAL_USES_LIBRARIES
483# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or
484# LOCAL_OPTIONAL_USES_LIBRARIES are specified.
485# Will change the default to true unconditionally in the future.
486ifndef LOCAL_ENFORCE_USES_LIBRARIES
487 ifneq (,$(strip $(LOCAL_USES_LIBRARIES)$(LOCAL_OPTIONAL_USES_LIBRARIES)))
488 LOCAL_ENFORCE_USES_LIBRARIES := true
489 endif
490endif
491
492my_enforced_uses_libraries :=
493ifdef LOCAL_ENFORCE_USES_LIBRARIES
494 my_manifest_check := $(intermediates.COMMON)/manifest/AndroidManifest.xml.check
495 $(my_manifest_check): $(MANIFEST_CHECK)
496 $(my_manifest_check): PRIVATE_USES_LIBRARIES := $(LOCAL_USES_LIBRARIES)
497 $(my_manifest_check): PRIVATE_OPTIONAL_USES_LIBRARIES := $(LOCAL_OPTIONAL_USES_LIBRARIES)
498 $(my_manifest_check): $(full_android_manifest)
499 @echo Checking manifest: $<
500 $(MANIFEST_CHECK) --enforce-uses-libraries \
501 $(addprefix --uses-library ,$(PRIVATE_USES_LIBRARIES)) \
502 $(addprefix --optional-uses-library ,$(PRIVATE_OPTIONAL_USES_LIBRARIES)) \
503 $< -o $@
504 $(LOCAL_BUILT_MODULE): $(my_manifest_check)
505endif
506
Colin Cross8e404122014-02-06 14:45:37 -0800507# Define the rule to build the actual package.
Ying Wang8e20ef62014-06-24 20:01:52 -0700508# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
509$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
510# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
511$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800512ifneq ($(TARGET_BUILD_APPS),)
513 # Include all resources for unbundled apps.
514 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
515endif
516ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
Adam Lesinskie758f932016-02-26 11:13:43 -0800517 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
518 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Colin Cross8e404122014-02-06 14:45:37 -0800519else
Adam Lesinskie758f932016-02-26 11:13:43 -0800520 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700521ifdef LOCAL_PACKAGE_SPLITS
Adam Lesinskie758f932016-02-26 11:13:43 -0800522 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Ying Wang934008f2014-07-30 13:40:14 -0700523else
Adam Lesinskie758f932016-02-26 11:13:43 -0800524 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
Colin Cross8e404122014-02-06 14:45:37 -0800525endif
Ying Wang934008f2014-07-30 13:40:14 -0700526endif
Colin Cross303567c2017-08-03 03:17:34 +0000527
Justin Yun6151e3f2019-06-25 15:58:13 +0900528# Run veridex on product, system_ext and vendor modules.
David Brazdil825770e2018-07-31 11:31:30 +0100529# We skip it for unbundled app builds where we cannot build veridex.
530module_run_appcompat :=
Jeongik Cha83c50322019-01-18 15:09:09 +0900531ifeq (true,$(non_system_module))
Dan Willemsena3f66322020-05-28 15:46:33 -0700532ifeq (,$(TARGET_BUILD_APPS)) # ! unbundled app build
Adrian Roos21028b72019-01-15 18:30:51 +0100533ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
David Brazdil825770e2018-07-31 11:31:30 +0100534 module_run_appcompat := true
535endif
536endif
Adrian Roos21028b72019-01-15 18:30:51 +0100537endif
David Brazdil825770e2018-07-31 11:31:30 +0100538
539ifeq ($(module_run_appcompat),true)
Dan Willemsenb73ccb72018-09-17 14:36:37 -0700540$(LOCAL_BUILT_MODULE) : $(appcompat-files)
Dario Freni716e9b62018-07-31 15:29:13 +0100541$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE)
Dario Freni1ecc9252018-07-13 16:44:28 +0100542endif
543
Colin Cross303567c2017-08-03 03:17:34 +0000544$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/resources
Ying Wangdd71c852015-12-04 13:59:18 -0800545$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
Colin Crossc9e49762018-09-14 13:39:07 -0700546$(LOCAL_BUILT_MODULE) : $(JAR_ARGS) $(SOONG_ZIP) $(MERGE_ZIPS) $(ZIP2ZIP)
Ying Wangdd71c852015-12-04 13:59:18 -0800547$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
Dan Willemsen288bedf2019-05-28 15:36:47 -0700548$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2)
Narayan Kamath7c205102017-08-07 12:31:17 +0100549ifdef LOCAL_COMPRESSED_MODULE
550$(LOCAL_BUILT_MODULE) : $(MINIGZIP)
551endif
Colin Crossdac94ff2018-10-07 21:32:07 -0700552ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
553$(LOCAL_BUILT_MODULE) : $(ZIP2ZIP)
554endif
Colin Cross9644ec82021-01-12 15:08:08 -0800555ifeq ($(full_classes_jar),)
556 # We don't build jar, need to add the Java resources here.
557 $(LOCAL_BUILT_MODULE): $(java_resource_sources)
558endif
Colin Crossead7b662019-02-06 16:36:32 -0800559$(LOCAL_BUILT_MODULE): PRIVATE_USE_EMBEDDED_NATIVE_LIBS := $(LOCAL_USE_EMBEDDED_NATIVE_LIBS)
Colin Cross53c8f972018-09-28 16:19:42 -0700560$(LOCAL_BUILT_MODULE):
Colin Cross8e404122014-02-06 14:45:37 -0800561 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Colin Crossc9e49762018-09-14 13:39:07 -0700562 rm -rf $@.parts
563 mkdir -p $@.parts
Colin Cross53c8f972018-09-28 16:19:42 -0700564 cp -f $(PRIVATE_RES_PACKAGE) $@.parts/apk.zip
Colin Cross8e404122014-02-06 14:45:37 -0800565ifneq ($(jni_shared_libraries),)
Colin Crossead7b662019-02-06 16:36:32 -0800566 $(call create-jni-shared-libs-package,$@.parts/jni.zip,$(PRIVATE_USE_EMBEDDED_NATIVE_LIBS))
Colin Cross8e404122014-02-06 14:45:37 -0800567endif
Ying Wang8b27d182015-03-27 11:07:17 -0700568ifeq ($(full_classes_jar),)
569# We don't build jar, need to add the Java resources here.
Colin Crossc9e49762018-09-14 13:39:07 -0700570 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call create-java-resources-jar,$@.parts/res.zip))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800571else # full_classes_jar
Colin Crossc9e49762018-09-14 13:39:07 -0700572 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
573 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800574endif # full_classes_jar
Colin Crossc9e49762018-09-14 13:39:07 -0700575 $(MERGE_ZIPS) $@ $@.parts/*.zip
576 rm -rf $@.parts
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000577ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
578 @# No need to align, sign-package below will do it.
579 $(uncompress-dexs)
580endif
Nicolas Geoffray2ca0e492019-10-18 14:47:19 +0100581# Run appcompat before signing.
David Brazdil825770e2018-07-31 11:31:30 +0100582ifeq ($(module_run_appcompat),true)
Dario Freni716e9b62018-07-31 15:29:13 +0100583 $(appcompat-header)
Dario Freni1ecc9252018-07-13 16:44:28 +0100584 $(run-appcompat)
David Brazdil825770e2018-07-31 11:31:30 +0100585endif # module_run_appcompat
Kenny Rootdff37552015-04-15 12:09:32 -0700586 $(sign-package)
Narayan Kamath7c205102017-08-07 12:31:17 +0100587ifdef LOCAL_COMPRESSED_MODULE
588 $(compress-package)
589endif # LOCAL_COMPRESSED_MODULE
Colin Cross8e404122014-02-06 14:45:37 -0800590
Colin Crosse6210f62019-02-25 22:21:24 -0800591my_package_res_pb := $(intermediates)/package-res.pb.apk
592$(my_package_res_pb): $(my_res_package) $(AAPT2)
Colin Cross35eb2e32018-11-01 20:34:08 +0000593 $(AAPT2) convert --output-format proto $< -o $@
594
Colin Crosse6210f62019-02-25 22:21:24 -0800595$(my_bundle_module): $(my_package_res_pb)
596$(my_bundle_module): PRIVATE_RES_PACKAGE := $(my_package_res_pb)
Colin Cross35eb2e32018-11-01 20:34:08 +0000597
Colin Crosse6210f62019-02-25 22:21:24 -0800598$(my_bundle_module): $(jni_shared_libraries)
599$(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
600$(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross35eb2e32018-11-01 20:34:08 +0000601
Colin Crosse6210f62019-02-25 22:21:24 -0800602ifneq ($(full_classes_jar),)
603 $(my_bundle_module): PRIVATE_DEX_FILE := $(built_dex)
604 # Use the jarjar processed archive as the initial package file.
605 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
606 $(my_bundle_module): $(built_dex)
607else
608 $(my_bundle_module): PRIVATE_DEX_FILE :=
609 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross9644ec82021-01-12 15:08:08 -0800610 # We don't build jar, need to add the Java resources here.
611 $(my_bundle_module): $(java_resource_sources)
Colin Crosse6210f62019-02-25 22:21:24 -0800612endif # full_classes_jar
Colin Cross35eb2e32018-11-01 20:34:08 +0000613
Colin Crosse6210f62019-02-25 22:21:24 -0800614$(my_bundle_module): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP)
Colin Cross35eb2e32018-11-01 20:34:08 +0000615 @echo "target Bundle: $(PRIVATE_MODULE) ($@)"
616 rm -rf $@.parts
617 mkdir -p $@.parts
618 $(ZIP2ZIP) -i $(PRIVATE_RES_PACKAGE) -o $@.parts/apk.zip AndroidManifest.xml:manifest/AndroidManifest.xml resources.pb "res/**/*" "assets/**/*"
Colin Crosse6210f62019-02-25 22:21:24 -0800619 ifneq ($(jni_shared_libraries),)
Colin Cross35eb2e32018-11-01 20:34:08 +0000620 $(call create-jni-shared-libs-package,$@.parts/jni.zip)
Colin Crosse6210f62019-02-25 22:21:24 -0800621 endif
622 ifeq ($(full_classes_jar),)
623 # We don't build jar, need to add the Java resources here.
Colin Cross85fa3de2018-11-05 10:13:10 -0800624 $(if $(PRIVATE_EXTRA_JAR_ARGS),\
625 $(call create-java-resources-jar,$@.parts/res.zip) && \
626 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/" && \
627 mv -f $@.parts/res.zip.tmp $@.parts/res.zip)
Colin Crosse6210f62019-02-25 22:21:24 -0800628 else # full_classes_jar
Colin Cross35eb2e32018-11-01 20:34:08 +0000629 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
630 $(ZIP2ZIP) -i $@.parts/dex.zip -o $@.parts/dex.zip.tmp "classes*.dex:dex/"
631 mv -f $@.parts/dex.zip.tmp $@.parts/dex.zip
632 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
Colin Cross85fa3de2018-11-05 10:13:10 -0800633 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/"
634 mv -f $@.parts/res.zip.tmp $@.parts/res.zip
Colin Crosse6210f62019-02-25 22:21:24 -0800635 endif # full_classes_jar
Colin Cross35eb2e32018-11-01 20:34:08 +0000636 $(MERGE_ZIPS) $@ $@.parts/*.zip
637 rm -rf $@.parts
Yo Chiang58142472020-05-08 15:38:46 +0800638ALL_MODULES.$(my_register_name).BUNDLE := $(my_bundle_module)
Colin Cross35eb2e32018-11-01 20:34:08 +0000639
Ying Wang8070b202014-12-01 17:46:56 -0800640ifdef TARGET_BUILD_APPS
Colin Crosse6210f62019-02-25 22:21:24 -0800641 ifdef LOCAL_DPI_VARIANTS
642 $(call pretty-error,Building DPI-specific APKs is no longer supported)
643 endif
Ying Wang8070b202014-12-01 17:46:56 -0800644endif
645
646###############################
Colin Cross6db5b0e2018-11-16 21:26:33 -0800647## Rule to build a jar containing dex files to dexpreopt without waiting for
648## the APK
Ying Wang36142f62014-05-21 16:13:33 -0700649ifdef LOCAL_DEX_PREOPT
Colin Cross6db5b0e2018-11-16 21:26:33 -0800650 $(my_dex_jar): PRIVATE_DEX_FILE := $(built_dex)
Dan Willemsen0706faa2019-06-12 06:05:02 +0000651 $(my_dex_jar): $(built_dex) $(SOONG_ZIP)
Ying Wang994c2262014-05-28 13:34:59 -0700652 $(hide) mkdir -p $(dir $@) && rm -f $@
Colin Crossc9e49762018-09-14 13:39:07 -0700653 $(call create-dex-jar,$@,$(PRIVATE_DEX_FILE))
Ying Wang36142f62014-05-21 16:13:33 -0700654endif
655
Ying Wang1425e2d2014-07-22 15:42:11 -0700656###############################
657## APK splits
658ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700659# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800660# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700661# Note that we explicily check the existence of the split apk and remove the
662# built base apk if the split apk isn't there.
663# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700664$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
665$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Dan Willemsenf72308a2017-05-15 23:38:04 -0700666$(built_apk_splits) : $(intermediates)/%.apk : $(LOCAL_BUILT_MODULE)
Ying Wang7f625aa2014-07-23 10:27:57 -0700667 $(hide) if [ ! -f $@ ]; then \
668 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
669 rm $<; exit 1; \
670 fi
671 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700672
673# Rules to install the splits
Colin Cross7a281582018-03-06 16:21:36 -0800674installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Dan Willemsenf72308a2017-05-15 23:38:04 -0700675$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(intermediates)/package_%.apk
Ying Wang7f625aa2014-07-23 10:27:57 -0700676 @echo "Install: $@"
677 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700678
679# Register the additional built and installed files.
680ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
681ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Dan Willemsenf72308a2017-05-15 23:38:04 -0700682 $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700683
684# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700685$(my_all_targets): $(installed_apk_splits)
Ying Wang16243612015-06-03 12:43:50 -0700686
687ifdef LOCAL_COMPATIBILITY_SUITE
Ying Wang16243612015-06-03 12:43:50 -0700688
Nelson Li1f8357f2019-03-14 01:04:05 +0000689$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
690 $(eval my_compat_dist_$(suite) := $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
691 $(foreach s,$(my_split_suffixes),\
692 $(call compat-copy-pair,$(intermediates)/package_$(s).apk,$(dir)/$(LOCAL_MODULE)_$(s).apk)))))
Ying Wang16243612015-06-03 12:43:50 -0700693
Simran Basi6bea37c2017-02-16 18:04:10 -0800694$(call create-suite-dependencies)
695
Ying Wang16243612015-06-03 12:43:50 -0700696endif # LOCAL_COMPATIBILITY_SUITE
Ying Wang1425e2d2014-07-22 15:42:11 -0700697endif # LOCAL_PACKAGE_SPLITS
698
Colin Cross8e404122014-02-06 14:45:37 -0800699# Save information about this package
700PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
701PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
Colin Cross8e404122014-02-06 14:45:37 -0800702
Jiyong Park9314d8c2020-05-03 10:51:14 +0900703ifneq ($(LOCAL_MODULE_STEM),)
704 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE_STEM)
705else
706 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE)
707endif
708
Colin Cross8e404122014-02-06 14:45:37 -0800709PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
710
Colin Cross8e404122014-02-06 14:45:37 -0800711# Reset internal variables.
712all_res_assets :=
Jaekyun Seok30706102017-02-02 00:44:58 +0900713
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000714ifneq (,$(runtime_resource_overlays_product)$(runtime_resource_overlays_vendor))
Jaekyun Seok30706102017-02-02 00:44:58 +0900715 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
716 enforce_rro_use_res_lib := true
717 else
718 enforce_rro_use_res_lib := false
719 endif
720
721 ifdef LOCAL_MANIFEST_PACKAGE_NAME
722 enforce_rro_is_manifest_package_name := true
723 enforce_rro_manifest_package_info := $(LOCAL_MANIFEST_PACKAGE_NAME)
724 else
725 enforce_rro_is_manifest_package_name := false
726 enforce_rro_manifest_package_info := $(full_android_manifest)
727 endif
728
Anton Hanssoncb8276f2019-03-18 11:43:30 +0000729 ifdef runtime_resource_overlays_product
730 $(call append_enforce_rro_sources, \
731 $(my_register_name), \
732 $(enforce_rro_is_manifest_package_name), \
733 $(enforce_rro_manifest_package_info), \
734 $(enforce_rro_use_res_lib), \
735 $(runtime_resource_overlays_product), \
736 product \
737 )
738 endif
739 ifdef runtime_resource_overlays_vendor
740 $(call append_enforce_rro_sources, \
741 $(my_register_name), \
742 $(enforce_rro_is_manifest_package_name), \
743 $(enforce_rro_manifest_package_info), \
744 $(enforce_rro_use_res_lib), \
745 $(runtime_resource_overlays_vendor), \
746 vendor \
747 )
748 endif
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000749endif