blob: 9043710f2e3ae232a5227592a211c5531ce5b7c9 [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
28# If this makefile is being read from within an inheritance,
29# use the new values.
30skip_definition:=
31ifdef LOCAL_PACKAGE_OVERRIDES
32 package_overridden := $(call set-inherited-package-variables)
33 ifeq ($(strip $(package_overridden)),)
34 skip_definition := true
35 endif
36endif
37
38ifndef skip_definition
39
40LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
41ifeq ($(LOCAL_PACKAGE_NAME),)
42$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
43endif
44
45ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
46$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
47endif
48LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
49
50ifneq ($(strip $(LOCAL_MODULE)),)
51$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
52endif
53LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
54
Colin Cross8e404122014-02-06 14:45:37 -080055ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
56$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
57endif
58LOCAL_MODULE_CLASS := APPS
59
Ying Wangdd71c852015-12-04 13:59:18 -080060intermediates := $(call local-intermediates-dir)
61intermediates.COMMON := $(call local-intermediates-dir,COMMON)
62
Colin Cross8e404122014-02-06 14:45:37 -080063# Package LOCAL_MODULE_TAGS default to optional
64LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
65ifeq ($(LOCAL_MODULE_TAGS),)
66LOCAL_MODULE_TAGS := optional
67endif
68
69ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
70# Force localization check if it's not tagged as tests.
71LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
72endif
73
Ying Wang4cb04992014-07-29 10:34:30 -070074need_compile_asset :=
Colin Cross8e404122014-02-06 14:45:37 -080075ifeq (,$(LOCAL_ASSET_DIR))
76LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
Ying Wang4cb04992014-07-29 10:34:30 -070077else
78need_compile_asset := true
Colin Cross8e404122014-02-06 14:45:37 -080079endif
80
Ying Wang61291922014-06-25 13:23:58 -070081# LOCAL_RESOURCE_DIR may point to resource generated during the build
82need_compile_res :=
Colin Cross8e404122014-02-06 14:45:37 -080083ifeq (,$(LOCAL_RESOURCE_DIR))
84 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
Ying Wang61291922014-06-25 13:23:58 -070085else
86 need_compile_res := true
Dan Willemsenfa7ecfb2017-05-02 23:55:44 -070087 LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d)))
Colin Cross8e404122014-02-06 14:45:37 -080088endif
89
Jiyong Park185d41e2019-01-05 12:57:54 +090090# If LOCAL_MODULE matches a rule in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES,
Jiyong Park9ee3a162019-01-16 01:07:35 +090091# override the manifest package name by the (first) rule matched
Jiyong Park185d41e2019-01-05 12:57:54 +090092override_manifest_name := $(strip $(word 1,\
93 $(foreach rule,$(PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES),\
94 $(eval _pkg_name_pat := $(call word-colon,1,$(rule)))\
95 $(eval _manifest_name_pat := $(call word-colon,2,$(rule)))\
96 $(if $(filter $(_pkg_name_pat),$(LOCAL_MODULE)),\
97 $(patsubst $(_pkg_name_pat),$(_manifest_name_pat),$(LOCAL_MODULE))\
98 )\
99 )\
100))
101
102ifneq (,$(override_manifest_name))
Jiyong Park9ee3a162019-01-16 01:07:35 +0900103# Note: this can override LOCAL_MANIFEST_PACKAGE_NAME value set in Android.mk
Jiyong Park185d41e2019-01-05 12:57:54 +0900104LOCAL_MANIFEST_PACKAGE_NAME := $(override_manifest_name)
105endif
106
Colin Cross20299032018-05-09 13:29:51 -0700107include $(BUILD_SYSTEM)/force_aapt2.mk
108
Colin Cross7bc6cab2018-05-17 15:05:47 -0700109# Process Support Library dependencies.
110include $(BUILD_SYSTEM)/support_libraries.mk
111
Colin Cross8e404122014-02-06 14:45:37 -0800112package_resource_overlays := $(strip \
113 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
114 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
115 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
116 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
117
Jaekyun Seok30706102017-02-02 00:44:58 +0900118enforce_rro_enabled :=
Jaekyun Seok2a209992017-03-30 11:25:02 +0900119ifneq ($(PRODUCT_ENFORCE_RRO_TARGETS),)
120 ifneq ($(package_resource_overlays),)
121 ifeq ($(PRODUCT_ENFORCE_RRO_TARGETS),*)
122 enforce_rro_enabled := true
123 else ifneq (,$(filter $(LOCAL_PACKAGE_NAME), $(PRODUCT_ENFORCE_RRO_TARGETS)))
Jaekyun Seok30706102017-02-02 00:44:58 +0900124 enforce_rro_enabled := true
125 endif
126 endif
127
128 ifdef enforce_rro_enabled
129 ifeq (,$(LOCAL_MODULE_PATH))
130 ifeq (true,$(LOCAL_PROPRIETARY_MODULE))
131 enforce_rro_enabled :=
132 else ifeq (true,$(LOCAL_OEM_MODULE))
133 enforce_rro_enabled :=
134 else ifeq (true,$(LOCAL_ODM_MODULE))
135 enforce_rro_enabled :=
Jaekyun Seokb7735d82017-11-27 17:04:47 +0900136 else ifeq (true,$(LOCAL_PRODUCT_MODULE))
137 enforce_rro_enabled :=
Dario Freni5f681e12018-05-29 13:09:01 +0100138 else ifeq (true,$(LOCAL_PRODUCT_SERVICES_MODULE))
139 enforce_rro_enabled :=
Jaekyun Seok30706102017-02-02 00:44:58 +0900140 endif
141 else ifeq ($(filter $(TARGET_OUT)/%,$(LOCAL_MODULE_PATH)),)
142 enforce_rro_enabled :=
143 endif
144 endif
145endif
146
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900147ifdef enforce_rro_enabled
148 ifneq ($(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS),)
149 static_only_resource_overlays := $(filter $(addsuffix %,$(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS)),$(package_resource_overlays))
150 ifneq ($(static_only_resource_overlays),)
151 package_resource_overlays := $(filter-out $(static_only_resource_overlays),$(package_resource_overlays))
152 LOCAL_RESOURCE_DIR := $(static_only_resource_overlays) $(LOCAL_RESOURCE_DIR)
153 ifeq ($(package_resource_overlays),)
154 enforce_rro_enabled :=
155 endif
156 endif
157 endif
158else
Colin Cross8e404122014-02-06 14:45:37 -0800159LOCAL_RESOURCE_DIR := $(package_resource_overlays) $(LOCAL_RESOURCE_DIR)
Jaekyun Seok30706102017-02-02 00:44:58 +0900160endif
Colin Cross8e404122014-02-06 14:45:37 -0800161
Colin Cross2c321442014-02-12 13:06:30 -0800162all_assets := $(strip \
163 $(foreach dir, $(LOCAL_ASSET_DIR), \
164 $(addprefix $(dir)/, \
165 $(patsubst assets/%,%, \
166 $(call find-subdir-assets, $(dir)) \
167 ) \
168 ) \
169 ))
Colin Cross8e404122014-02-06 14:45:37 -0800170
Ying Wang4cb04992014-07-29 10:34:30 -0700171ifneq ($(all_assets),)
172need_compile_asset := true
173endif
174
Dan Willemsenbb6393c2017-11-17 15:39:52 -0800175ifdef LOCAL_AAPT2_ONLY
176LOCAL_USE_AAPT2 := true
177endif
178
Adam Lesinskie758f932016-02-26 11:13:43 -0800179my_res_package :=
Colin Cross20299032018-05-09 13:29:51 -0700180ifeq ($(LOCAL_USE_AAPT2),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800181# In aapt2 the last takes precedence.
182my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
Adam Lesinskie758f932016-02-26 11:13:43 -0800183my_res_dir :=
184my_overlay_res_dirs :=
185
Colin Cross71c5b952018-05-23 13:35:53 -0700186ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),)
Adam Lesinskie758f932016-02-26 11:13:43 -0800187# If we are using static android libraries, every source file becomes an overlay.
188# This is to emulate old AAPT behavior which simulated library support.
189my_res_dir :=
190my_overlay_res_dirs := $(my_resource_dirs)
191else
192# Without static libraries, the first directory is our directory, which can then be
193# overlaid by the rest. (First directory in my_resource_dirs is last directory in
194# $(LOCAL_RESOURCE_DIR) due to it being reversed.
195my_res_dir := $(firstword $(my_resource_dirs))
196my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs))
197endif
198
Ying Wangdd71c852015-12-04 13:59:18 -0800199my_overlay_resources := $(strip \
Adam Lesinskie758f932016-02-26 11:13:43 -0800200 $(foreach d,$(my_overlay_res_dirs),\
Ying Wangdd71c852015-12-04 13:59:18 -0800201 $(addprefix $(d)/, \
202 $(call find-subdir-assets,$(d)))))
203
Colin Crossfe109632016-11-29 11:12:56 -0800204my_res_resources := $(if $(my_res_dir),$(strip \
Ying Wangdd71c852015-12-04 13:59:18 -0800205 $(addprefix $(my_res_dir)/, \
Colin Crossfe109632016-11-29 11:12:56 -0800206 $(call find-subdir-assets,$(my_res_dir)))))
Ying Wangdd71c852015-12-04 13:59:18 -0800207
208all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
209
210# The linked resource package.
211my_res_package := $(intermediates)/package-res.apk
212LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
213
Colin Cross35eb2e32018-11-01 20:34:08 +0000214ifeq ($(LOCAL_USE_AAPT2),true)
215 my_bundle_module := $(intermediates)/base.zip
216 LOCAL_INTERMEDIATE_TARGETS += $(my_bundle_module)
217endif
218
Ying Wange5853972016-03-01 12:06:47 -0800219# Always run aapt2, because we need to at least compile the AndroidManifest.xml.
Ying Wangdd71c852015-12-04 13:59:18 -0800220need_compile_res := true
221
Ying Wange295c3d2016-02-24 14:11:55 -0800222else # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800223all_resources := $(strip \
224 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
225 $(addprefix $(dir)/, \
226 $(patsubst res/%,%, \
227 $(call find-subdir-assets,$(dir)) \
228 ) \
229 ) \
230 ))
231
Adam Lesinski4c452052016-08-12 12:57:17 -0700232ifdef LOCAL_PACKAGE_SPLITS
233LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS))
234endif
235
Ying Wange295c3d2016-02-24 14:11:55 -0800236endif # LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800237
Ying Wang61291922014-06-25 13:23:58 -0700238ifneq ($(all_resources),)
239 need_compile_res := true
240endif
241
Colin Cross8e404122014-02-06 14:45:37 -0800242all_res_assets := $(strip $(all_assets) $(all_resources))
243
Colin Cross8e404122014-02-06 14:45:37 -0800244# If no assets or resources were found, clear the directory variables so
245# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700246ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800247LOCAL_ASSET_DIR:=
248endif
Ying Wang61291922014-06-25 13:23:58 -0700249ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800250LOCAL_RESOURCE_DIR:=
251R_file_stamp :=
252else
253# Make sure that R_file_stamp inherits the proper PRIVATE vars.
254# If R.stamp moves, be sure to update the framework makefile,
255# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800256R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800257LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
258endif
259
Narayan Kamath7c205102017-08-07 12:31:17 +0100260ifdef LOCAL_COMPRESSED_MODULE
261ifneq (true,$(LOCAL_COMPRESSED_MODULE))
262$(call pretty-error, Unknown value for LOCAL_COMPRESSED_MODULE $(LOCAL_COMPRESSED_MODULE))
263endif
264endif
265
266ifdef LOCAL_COMPRESSED_MODULE
Narayan Kamath6a4bd692017-08-14 10:53:50 +0100267PACKAGES.$(LOCAL_PACKAGE_NAME).COMPRESSED := gz
Narayan Kamath7c205102017-08-07 12:31:17 +0100268LOCAL_BUILT_MODULE_STEM := package.apk.gz
269LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk.gz
270else # !LOCAL_COMPRESSED_MODULE
Colin Cross8e404122014-02-06 14:45:37 -0800271LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700272LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Narayan Kamath7c205102017-08-07 12:31:17 +0100273endif
Colin Cross8e404122014-02-06 14:45:37 -0800274
275LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
276ifndef LOCAL_PROGUARD_ENABLED
277ifneq ($(DISABLE_PROGUARD),true)
278 LOCAL_PROGUARD_ENABLED :=full
279endif
280endif
281ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
282 # the package explicitly request to disable proguard.
283 LOCAL_PROGUARD_ENABLED :=
284endif
285proguard_options_file :=
286ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700287ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800288 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700289endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800290endif # !custom
291LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
292
293ifeq (true,$(EMMA_INSTRUMENT))
294ifndef LOCAL_EMMA_INSTRUMENT
Jeff Gastonaaae43c2017-04-11 16:36:46 -0700295# No jacoco for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800296ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800297LOCAL_EMMA_INSTRUMENT := true
298endif # No test apk
299endif # LOCAL_EMMA_INSTRUMENT is not set
300else
301LOCAL_EMMA_INSTRUMENT := false
302endif # EMMA_INSTRUMENT is true
303
304ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
305ifeq (true,$(EMMA_INSTRUMENT_STATIC))
Colin Cross11e2d552018-03-07 15:44:54 -0800306ifneq ($(LOCAL_SRC_FILES)$(LOCAL_SRCJARS)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
Colin Cross79e2f732016-12-21 14:29:13 -0800307# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100308LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Colin Crossdc4a6b82018-01-03 12:39:11 -0800309# Exclude jacoco classes from proguard
310LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800311endif # Contains java code
312else
Colin Cross8e404122014-02-06 14:45:37 -0800313ifdef LOCAL_SDK_VERSION
314ifdef TARGET_BUILD_APPS
Sebastien Hertz2319e562016-03-31 16:48:26 +0200315# In unbundled build, merge the coverage library into the apk.
Colin Cross79e2f732016-12-21 14:29:13 -0800316ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
317# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100318LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Sebastien Hertz2319e562016-03-31 16:48:26 +0200319# Exclude jacoco classes from proguard
320LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800321endif # Contains java code
Colin Crosse673deb2017-09-27 14:28:41 -0700322endif # TARGET_BUILD_APPS
Colin Cross8e404122014-02-06 14:45:37 -0800323endif # LOCAL_SDK_VERSION
Colin Cross79e2f732016-12-21 14:29:13 -0800324endif # EMMA_INSTRUMENT_STATIC
Colin Cross8e404122014-02-06 14:45:37 -0800325endif # LOCAL_EMMA_INSTRUMENT
326
327rs_compatibility_jni_libs :=
328
Narayan Kamath7c205102017-08-07 12:31:17 +0100329# If the module is a compressed module, we don't pre-opt it because its final
330# installation location will be the data partition.
331ifdef LOCAL_COMPRESSED_MODULE
332LOCAL_DEX_PREOPT := false
333endif
334
Colin Crossead7b662019-02-06 16:36:32 -0800335# Default to use uncompressed native libraries in APKs if minSdkVersion >= marshmallow
336ifndef LOCAL_USE_EMBEDDED_NATIVE_LIBS
337 LOCAL_USE_EMBEDDED_NATIVE_LIBS := $(call math_gt_or_eq, \
338 $(patsubst $(PLATFORM_VERSION_CODENAME),100,$(call module-min-sdk-version)),23)
339endif
340
Ying Wange9dd9f22014-10-29 15:48:32 -0700341include $(BUILD_SYSTEM)/android_manifest.mk
342
Colin Cross7a281582018-03-06 16:21:36 -0800343resource_export_package :=
344
345include $(BUILD_SYSTEM)/java_renderscript.mk
346
347include $(BUILD_SYSTEM)/aapt_flags.mk
348
349ifeq ($(need_compile_res),true)
350
351###############################
352## APK splits
353built_apk_splits :=
354installed_apk_splits :=
355my_apk_split_configs :=
356
357ifdef LOCAL_PACKAGE_SPLITS
358ifdef LOCAL_COMPRESSED_MODULE
359$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs)
360endif # LOCAL_COMPRESSED_MODULE
361
362my_apk_split_configs := $(LOCAL_PACKAGE_SPLITS)
363my_split_suffixes := $(subst $(comma),_,$(my_apk_split_configs))
364built_apk_splits := $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk)
365endif
366
367$(R_file_stamp) $(my_res_package): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
368$(R_file_stamp) $(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
369$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
370$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
371
372###############################
373## AAPT/AAPT2
374
Colin Cross20299032018-05-09 13:29:51 -0700375ifeq ($(LOCAL_USE_AAPT2),true)
Colin Cross7a281582018-03-06 16:21:36 -0800376 my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res
Colin Cross532ae3b2018-05-15 15:15:38 -0700377 ifneq (,$(filter-out current,$(renderscript_target_api)))
Colin Cross7a281582018-03-06 16:21:36 -0800378 ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true)
379 my_generated_res_zips := $(rs_generated_res_zip)
380 endif # renderscript_target_api < 21
381 endif # renderscript_target_api is set
382 my_asset_dirs := $(LOCAL_ASSET_DIR)
383 my_full_asset_paths := $(all_assets)
384
385 # Add AAPT2 link specific flags.
386 $(my_res_package): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
387 ifndef LOCAL_AAPT_NAMESPACES
388 $(my_res_package): PRIVATE_AAPT_FLAGS += --no-static-lib-packages
389 endif
390
391 include $(BUILD_SYSTEM)/aapt2.mk
392else # LOCAL_USE_AAPT2
393
Colin Crossf6d68cf2018-03-08 16:49:16 -0800394 my_srcjar := $(intermediates.COMMON)/aapt.srcjar
395 LOCAL_SRCJARS += $(my_srcjar)
396 $(R_file_stamp): PRIVATE_SRCJAR := $(my_srcjar)
397 $(R_file_stamp): PRIVATE_JAVA_GEN_DIR := $(intermediates.COMMON)/aapt
398 $(R_file_stamp): .KATI_IMPLICIT_OUTPUTS := $(my_srcjar)
Colin Cross7a281582018-03-06 16:21:36 -0800399 # Since we don't know where the real R.java file is going to end up,
400 # we need to use another file to stand in its place. We'll just
401 # copy the generated file to src/R.stamp, which means it will
402 # have the same contents and timestamp as the actual file.
403 #
404 # At the same time, this will copy the R.java file to a central
405 # 'R' directory to make it easier to add the files to an IDE.
406 #
407
408 $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
409 $(intermediates.COMMON)/public_resources.xml
410 $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
411 $(R_file_stamp): PRIVATE_RESOURCE_LIST := $(all_res_assets)
Colin Crossf6d68cf2018-03-08 16:49:16 -0800412 $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(rs_generated_res_zip) $(AAPT) $(SOONG_ZIP) | $(ACP)
Colin Cross7a281582018-03-06 16:21:36 -0800413 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
414 @rm -rf $@ && mkdir -p $(dir $@)
415 $(create-resource-java-files)
Colin Crossf6d68cf2018-03-08 16:49:16 -0800416 $(call find-generated-R.java,$(PRIVATE_JAVA_GEN_DIR),$@)
Colin Cross7a281582018-03-06 16:21:36 -0800417
418 $(proguard_options_file): $(R_file_stamp)
419
420 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
421 # Put this module's resources into a PRODUCT-agnositc package that
422 # other packages can use to build their own PRODUCT-agnostic R.java (etc.)
423 # files.
424 resource_export_package := $(intermediates.COMMON)/package-export.apk
425 $(R_file_stamp): $(resource_export_package)
426
Colin Crossc9e49762018-09-14 13:39:07 -0700427 # create-assets-package looks at PRODUCT_AAPT_CONFIG, but this target
Colin Cross7a281582018-03-06 16:21:36 -0800428 # can't know anything about PRODUCT. Clear it out just for this target.
429 $(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
430 $(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
431 $(resource_export_package): PRIVATE_RESOURCE_LIST := $(all_res_assets)
Colin Cross14658062018-05-15 16:04:47 -0700432 $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(rs_generated_res_zip) $(AAPT)
Colin Cross7a281582018-03-06 16:21:36 -0800433 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
Colin Crossc9e49762018-09-14 13:39:07 -0700434 $(call create-assets-package,$@)
Colin Cross7a281582018-03-06 16:21:36 -0800435 endif
436
437endif # LOCAL_USE_AAPT2
438
439endif # need_compile_res
440
Colin Cross6db5b0e2018-11-16 21:26:33 -0800441my_dex_jar := $(intermediates.COMMON)/dex.jar
442
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100443called_from_package_internal := true
Colin Cross8e404122014-02-06 14:45:37 -0800444#################################
445include $(BUILD_SYSTEM)/java.mk
446#################################
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100447called_from_package_internal :=
Colin Cross8e404122014-02-06 14:45:37 -0800448
Colin Cross7a281582018-03-06 16:21:36 -0800449ifeq ($(need_compile_res),true)
450
451# Other modules should depend on the BUILT module if
452# they want to use this module's R.java file.
453$(LOCAL_BUILT_MODULE): $(R_file_stamp)
454
455# The R.java file must exist by the time the java source
456# list is generated
457$(java_source_list_file): $(R_file_stamp)
458
459endif # need_compile_res
460
Colin Cross8e404122014-02-06 14:45:37 -0800461LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
462ifeq ($(LOCAL_SDK_RES_VERSION),)
463 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
464endif
465
Colin Cross8e404122014-02-06 14:45:37 -0800466$(LOCAL_INTERMEDIATE_TARGETS): \
467 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Colin Cross8e404122014-02-06 14:45:37 -0800468
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800469framework_res_package_export :=
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800470
471ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Colin Cross8e404122014-02-06 14:45:37 -0800472# Most packages should link against the resources defined by framework-res.
473# Even if they don't have their own resources, they may use framework
474# resources.
Dan Willemsenc51b7b02018-02-16 13:31:17 -0800475ifeq ($(LOCAL_SDK_RES_VERSION),core_current)
476# core_current doesn't contain any framework resources.
Colin Cross8e0ff1c2018-12-18 22:43:16 -0800477else ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS_USE_PREBUILT_SDK),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),)
Colin Cross8e404122014-02-06 14:45:37 -0800478# for released sdk versions, the platform resources were built into android.jar.
479framework_res_package_export := \
Anton Hansson66d47b82018-04-27 14:11:17 +0100480 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION))
Colin Cross8e404122014-02-06 14:45:37 -0800481else # LOCAL_SDK_RES_VERSION
482framework_res_package_export := \
483 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
Colin Cross8e404122014-02-06 14:45:37 -0800484endif # LOCAL_SDK_RES_VERSION
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800485endif # LOCAL_NO_STANDARD_LIBRARIES
486
Adam Lesinskide057c32014-03-13 18:48:27 -0700487all_library_res_package_exports := \
488 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700489 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700490 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
491
492all_library_res_package_export_deps := \
Colin Cross6e136922018-02-20 14:31:33 -0800493 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700494 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700495 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
Ying Wangb5745642014-06-19 16:07:30 -0700496$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800497$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700498 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Ying Wangdd71c852015-12-04 13:59:18 -0800499
Colin Cross20299032018-05-09 13:29:51 -0700500ifeq ($(LOCAL_USE_AAPT2),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800501$(my_res_package) : $(all_library_res_package_export_deps)
502endif
Colin Cross8e404122014-02-06 14:45:37 -0800503
Colin Cross7a281582018-03-06 16:21:36 -0800504# These four are set above for $(R_stamp_file) and $(my_res_package), but
505# $(LOCAL_BUILT_MODULE) is not set before java.mk, so they have to be set again
506# here.
507$(LOCAL_BUILT_MODULE): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
508$(LOCAL_BUILT_MODULE): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
509$(LOCAL_BUILT_MODULE): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
510$(LOCAL_BUILT_MODULE): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
511
Colin Cross8e404122014-02-06 14:45:37 -0800512ifneq ($(full_classes_jar),)
513$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Colin Cross79e2f732016-12-21 14:29:13 -0800514# Use the jarjar processed arhive as the initial package file.
Colin Crossffbf0a62017-03-29 12:58:15 -0700515$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
Colin Cross8e404122014-02-06 14:45:37 -0800516$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800517else
518$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
Colin Cross79e2f732016-12-21 14:29:13 -0800519$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800520endif # full_classes_jar
521
Ying Wang96bcad42014-04-17 13:38:04 -0700522include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800523
524# Pick a key to sign the package with. If this package hasn't specified
525# an explicit certificate, use the default.
526# Secure release builds will have their packages signed after the fact,
527# so it's ok for these private keys to be in the clear.
528ifeq ($(LOCAL_CERTIFICATE),)
529 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
530endif
531
532ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
533 # The special value "EXTERNAL" means that we will sign it with the
534 # default devkey, apply predexopt, but then expect the final .apk
535 # (after dexopting) to be signed by an outside tool.
536 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
537 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
538endif
539
540# If this is not an absolute certificate, assign it to a generic one.
541ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
542 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
543endif
Jeongik Chab2c4bb72018-12-17 14:45:15 +0900544include $(BUILD_SYSTEM)/app_certificate_validate.mk
Colin Cross8e404122014-02-06 14:45:37 -0800545private_key := $(LOCAL_CERTIFICATE).pk8
546certificate := $(LOCAL_CERTIFICATE).x509.pem
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900547additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
Colin Cross8e404122014-02-06 14:45:37 -0800548
549$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
550$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
551$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
552
553PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
554PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
555
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900556$(LOCAL_BUILT_MODULE): $(additional_certificates)
557$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
Colin Cross8e404122014-02-06 14:45:37 -0800558
559# Define the rule to build the actual package.
Ying Wang8e20ef62014-06-24 20:01:52 -0700560# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
561$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
562# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
563$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800564ifneq ($(TARGET_BUILD_APPS),)
565 # Include all resources for unbundled apps.
566 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
567endif
568ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
Adam Lesinskie758f932016-02-26 11:13:43 -0800569 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
570 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Colin Cross8e404122014-02-06 14:45:37 -0800571else
Adam Lesinskie758f932016-02-26 11:13:43 -0800572 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700573ifdef LOCAL_PACKAGE_SPLITS
Adam Lesinskie758f932016-02-26 11:13:43 -0800574 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Ying Wang934008f2014-07-30 13:40:14 -0700575else
Adam Lesinskie758f932016-02-26 11:13:43 -0800576 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
Colin Cross8e404122014-02-06 14:45:37 -0800577endif
Ying Wang934008f2014-07-30 13:40:14 -0700578endif
Colin Cross303567c2017-08-03 03:17:34 +0000579
Dario Freni924af7d2018-08-17 00:56:14 +0100580# Run veridex on product, product_services and vendor modules.
David Brazdil825770e2018-07-31 11:31:30 +0100581# We skip it for unbundled app builds where we cannot build veridex.
582module_run_appcompat :=
Jeongik Cha83c50322019-01-18 15:09:09 +0900583ifeq (true,$(non_system_module))
David Brazdil825770e2018-07-31 11:31:30 +0100584ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build
Adrian Roos21028b72019-01-15 18:30:51 +0100585ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
David Brazdil825770e2018-07-31 11:31:30 +0100586 module_run_appcompat := true
587endif
588endif
Adrian Roos21028b72019-01-15 18:30:51 +0100589endif
David Brazdil825770e2018-07-31 11:31:30 +0100590
591ifeq ($(module_run_appcompat),true)
Dan Willemsenb73ccb72018-09-17 14:36:37 -0700592$(LOCAL_BUILT_MODULE) : $(appcompat-files)
Dario Freni716e9b62018-07-31 15:29:13 +0100593$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE)
Dario Freni1ecc9252018-07-13 16:44:28 +0100594endif
595
Colin Cross303567c2017-08-03 03:17:34 +0000596$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/resources
Ying Wangdd71c852015-12-04 13:59:18 -0800597$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
Colin Crossc9e49762018-09-14 13:39:07 -0700598$(LOCAL_BUILT_MODULE) : $(JAR_ARGS) $(SOONG_ZIP) $(MERGE_ZIPS) $(ZIP2ZIP)
Colin Cross20299032018-05-09 13:29:51 -0700599ifeq ($(LOCAL_USE_AAPT2),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800600$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
601$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
602else
Dan Willemsenf439c332017-10-02 14:22:02 -0700603$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_LIST := $(all_res_assets)
Nicolas Geoffraya95fbd12017-09-19 13:10:31 +0100604$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT) $(ZIPALIGN)
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000605endif # LOCAL_USE_AAPT2
Narayan Kamath7c205102017-08-07 12:31:17 +0100606ifdef LOCAL_COMPRESSED_MODULE
607$(LOCAL_BUILT_MODULE) : $(MINIGZIP)
608endif
Colin Crossdac94ff2018-10-07 21:32:07 -0700609ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
610$(LOCAL_BUILT_MODULE) : $(ZIP2ZIP)
611endif
Colin Cross53c8f972018-09-28 16:19:42 -0700612ifneq ($(BUILD_PLATFORM_ZIP),)
613$(LOCAL_BUILT_MODULE) : .KATI_IMPLICIT_OUTPUTS := $(dir $(LOCAL_BUILT_MODULE))package.dex.apk
614endif
Colin Cross6db5b0e2018-11-16 21:26:33 -0800615ifdef LOCAL_DEX_PREOPT
616$(LOCAL_BUILT_MODULE) : PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh
617$(LOCAL_BUILT_MODULE) : $(intermediates)/strip.sh
Colin Crossded0aec2019-01-17 16:22:04 -0800618$(LOCAL_BUILT_MODULE) : | $(DEXPREOPT_STRIP_DEPS)
Colin Cross6db5b0e2018-11-16 21:26:33 -0800619$(LOCAL_BUILT_MODULE): .KATI_DEPFILE := $(LOCAL_BUILT_MODULE).d
620endif
Colin Crossead7b662019-02-06 16:36:32 -0800621$(LOCAL_BUILT_MODULE): PRIVATE_USE_EMBEDDED_NATIVE_LIBS := $(LOCAL_USE_EMBEDDED_NATIVE_LIBS)
Colin Cross53c8f972018-09-28 16:19:42 -0700622$(LOCAL_BUILT_MODULE):
Colin Cross8e404122014-02-06 14:45:37 -0800623 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Colin Crossc9e49762018-09-14 13:39:07 -0700624 rm -rf $@.parts
625 mkdir -p $@.parts
Colin Cross20299032018-05-09 13:29:51 -0700626ifeq ($(LOCAL_USE_AAPT2),true)
Colin Cross53c8f972018-09-28 16:19:42 -0700627 cp -f $(PRIVATE_RES_PACKAGE) $@.parts/apk.zip
Ying Wang81ef4712016-03-31 10:10:42 -0700628else # ! LOCAL_USE_AAPT2
Colin Crossc9e49762018-09-14 13:39:07 -0700629 $(call create-assets-package,$@.parts/apk.zip)
Ying Wange295c3d2016-02-24 14:11:55 -0800630endif # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800631ifneq ($(jni_shared_libraries),)
Colin Crossead7b662019-02-06 16:36:32 -0800632 $(call create-jni-shared-libs-package,$@.parts/jni.zip,$(PRIVATE_USE_EMBEDDED_NATIVE_LIBS))
Colin Cross8e404122014-02-06 14:45:37 -0800633endif
Ying Wang8b27d182015-03-27 11:07:17 -0700634ifeq ($(full_classes_jar),)
635# We don't build jar, need to add the Java resources here.
Colin Crossc9e49762018-09-14 13:39:07 -0700636 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call create-java-resources-jar,$@.parts/res.zip))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800637else # full_classes_jar
Colin Crossc9e49762018-09-14 13:39:07 -0700638 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
639 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800640endif # full_classes_jar
Colin Crossc9e49762018-09-14 13:39:07 -0700641 $(MERGE_ZIPS) $@ $@.parts/*.zip
642 rm -rf $@.parts
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000643ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
644 @# No need to align, sign-package below will do it.
645 $(uncompress-dexs)
646endif
Dario Freni1ecc9252018-07-13 16:44:28 +0100647# Run appcompat before stripping the classes.dex file.
David Brazdil825770e2018-07-31 11:31:30 +0100648ifeq ($(module_run_appcompat),true)
Dario Freni716e9b62018-07-31 15:29:13 +0100649ifeq ($(LOCAL_USE_AAPT2),true)
650 $(call appcompat-header, aapt2)
651else
652 $(appcompat-header)
653endif
Dario Freni1ecc9252018-07-13 16:44:28 +0100654 $(run-appcompat)
David Brazdil825770e2018-07-31 11:31:30 +0100655endif # module_run_appcompat
Colin Cross8e404122014-02-06 14:45:37 -0800656ifdef LOCAL_DEX_PREOPT
Ying Wang3a61eeb2016-03-11 10:32:01 -0800657ifneq ($(BUILD_PLATFORM_ZIP),)
658 @# Keep a copy of apk with classes.dex unstripped
659 $(hide) cp -f $@ $(dir $@)package.dex.apk
660endif # BUILD_PLATFORM_ZIP
Dan Willemsen07b73572019-01-07 13:58:37 -0800661 mv -f $@ $@.tmp
662 $(PRIVATE_STRIP_SCRIPT) $@.tmp $@
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000663endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700664 $(sign-package)
Narayan Kamath7c205102017-08-07 12:31:17 +0100665ifdef LOCAL_COMPRESSED_MODULE
666 $(compress-package)
667endif # LOCAL_COMPRESSED_MODULE
Colin Cross8e404122014-02-06 14:45:37 -0800668
Colin Cross35eb2e32018-11-01 20:34:08 +0000669ifeq ($(LOCAL_USE_AAPT2),true)
670 my_package_res_pb := $(intermediates)/package-res.pb.apk
671 $(my_package_res_pb): $(my_res_package) $(AAPT2)
672 $(AAPT2) convert --output-format proto $< -o $@
673
674 $(my_bundle_module): $(my_package_res_pb)
675 $(my_bundle_module): PRIVATE_RES_PACKAGE := $(my_package_res_pb)
676
677 $(my_bundle_module): $(jni_shared_libraries)
678 $(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
679 $(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
680
681 ifneq ($(full_classes_jar),)
682 $(my_bundle_module): PRIVATE_DEX_FILE := $(built_dex)
683 # Use the jarjar processed archive as the initial package file.
684 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
685 $(my_bundle_module): $(built_dex)
686 else
687 $(my_bundle_module): PRIVATE_DEX_FILE :=
688 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE :=
689 endif # full_classes_jar
690
691 $(my_bundle_module): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP)
692 @echo "target Bundle: $(PRIVATE_MODULE) ($@)"
693 rm -rf $@.parts
694 mkdir -p $@.parts
695 $(ZIP2ZIP) -i $(PRIVATE_RES_PACKAGE) -o $@.parts/apk.zip AndroidManifest.xml:manifest/AndroidManifest.xml resources.pb "res/**/*" "assets/**/*"
696 ifneq ($(jni_shared_libraries),)
697 $(call create-jni-shared-libs-package,$@.parts/jni.zip)
698 endif
699 ifeq ($(full_classes_jar),)
700 # We don't build jar, need to add the Java resources here.
Colin Cross85fa3de2018-11-05 10:13:10 -0800701 $(if $(PRIVATE_EXTRA_JAR_ARGS),\
702 $(call create-java-resources-jar,$@.parts/res.zip) && \
703 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/" && \
704 mv -f $@.parts/res.zip.tmp $@.parts/res.zip)
Colin Cross35eb2e32018-11-01 20:34:08 +0000705 else # full_classes_jar
706 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
707 $(ZIP2ZIP) -i $@.parts/dex.zip -o $@.parts/dex.zip.tmp "classes*.dex:dex/"
708 mv -f $@.parts/dex.zip.tmp $@.parts/dex.zip
709 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
Colin Cross85fa3de2018-11-05 10:13:10 -0800710 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/"
711 mv -f $@.parts/res.zip.tmp $@.parts/res.zip
Colin Cross35eb2e32018-11-01 20:34:08 +0000712 endif # full_classes_jar
Colin Cross35eb2e32018-11-01 20:34:08 +0000713 $(MERGE_ZIPS) $@ $@.parts/*.zip
714 rm -rf $@.parts
715 ALL_MODULES.$(LOCAL_MODULE).BUNDLE := $(my_bundle_module)
716endif
717
Ying Wang36142f62014-05-21 16:13:33 -0700718###############################
Ying Wang8070b202014-12-01 17:46:56 -0800719## Build dpi-specific apks, if it's apps_only build.
720ifdef TARGET_BUILD_APPS
721ifdef LOCAL_DPI_VARIANTS
722$(foreach d, $(LOCAL_DPI_VARIANTS), \
723 $(eval my_dpi := $(d)) \
724 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
725endif
726endif
727
728###############################
Colin Cross6db5b0e2018-11-16 21:26:33 -0800729## Rule to build a jar containing dex files to dexpreopt without waiting for
730## the APK
Ying Wang36142f62014-05-21 16:13:33 -0700731ifdef LOCAL_DEX_PREOPT
Colin Cross6db5b0e2018-11-16 21:26:33 -0800732 $(my_dex_jar): PRIVATE_DEX_FILE := $(built_dex)
733 $(my_dex_jar): $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700734 $(hide) mkdir -p $(dir $@) && rm -f $@
Colin Crossc9e49762018-09-14 13:39:07 -0700735 $(call create-dex-jar,$@,$(PRIVATE_DEX_FILE))
Ying Wang36142f62014-05-21 16:13:33 -0700736endif
737
Ying Wang1425e2d2014-07-22 15:42:11 -0700738###############################
739## APK splits
740ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700741# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800742# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700743# Note that we explicily check the existence of the split apk and remove the
744# built base apk if the split apk isn't there.
745# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700746$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
747$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Dan Willemsenf72308a2017-05-15 23:38:04 -0700748$(built_apk_splits) : $(intermediates)/%.apk : $(LOCAL_BUILT_MODULE)
Ying Wang7f625aa2014-07-23 10:27:57 -0700749 $(hide) if [ ! -f $@ ]; then \
750 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
751 rm $<; exit 1; \
752 fi
753 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700754
755# Rules to install the splits
Colin Cross7a281582018-03-06 16:21:36 -0800756installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Dan Willemsenf72308a2017-05-15 23:38:04 -0700757$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(intermediates)/package_%.apk
Ying Wang7f625aa2014-07-23 10:27:57 -0700758 @echo "Install: $@"
759 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700760
761# Register the additional built and installed files.
762ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
763ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Dan Willemsenf72308a2017-05-15 23:38:04 -0700764 $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700765
766# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700767$(my_all_targets): $(installed_apk_splits)
Ying Wang16243612015-06-03 12:43:50 -0700768
769ifdef LOCAL_COMPATIBILITY_SUITE
Ying Wang16243612015-06-03 12:43:50 -0700770
Simran Basi6bea37c2017-02-16 18:04:10 -0800771$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
772 $(eval my_compat_dist_$(suite) := $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
773 $(foreach s,$(my_split_suffixes),\
Dan Willemsenf72308a2017-05-15 23:38:04 -0700774 $(intermediates)/package_$(s).apk:$(dir)/$(LOCAL_MODULE)_$(s).apk))))
Ying Wang16243612015-06-03 12:43:50 -0700775
Simran Basi6bea37c2017-02-16 18:04:10 -0800776$(call create-suite-dependencies)
777
Ying Wang16243612015-06-03 12:43:50 -0700778endif # LOCAL_COMPATIBILITY_SUITE
Ying Wang1425e2d2014-07-22 15:42:11 -0700779endif # LOCAL_PACKAGE_SPLITS
780
Colin Cross8e404122014-02-06 14:45:37 -0800781# Save information about this package
782PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
783PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
Colin Cross8e404122014-02-06 14:45:37 -0800784
785PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
786
Colin Cross8e404122014-02-06 14:45:37 -0800787endif # skip_definition
788
789# Reset internal variables.
790all_res_assets :=
Jaekyun Seok30706102017-02-02 00:44:58 +0900791
792ifdef enforce_rro_enabled
793 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
794 enforce_rro_use_res_lib := true
795 else
796 enforce_rro_use_res_lib := false
797 endif
798
799 ifdef LOCAL_MANIFEST_PACKAGE_NAME
800 enforce_rro_is_manifest_package_name := true
801 enforce_rro_manifest_package_info := $(LOCAL_MANIFEST_PACKAGE_NAME)
802 else
803 enforce_rro_is_manifest_package_name := false
804 enforce_rro_manifest_package_info := $(full_android_manifest)
805 endif
806
807$(call append_enforce_rro_sources, \
808 $(my_register_name), \
809 $(enforce_rro_is_manifest_package_name), \
810 $(enforce_rro_manifest_package_info), \
811 $(enforce_rro_use_res_lib), \
812 $(package_resource_overlays) \
813 )
Jaekyun Seok2a209992017-03-30 11:25:02 +0900814endif # enforce_rro_enabled