blob: 0998481f20a8c8f7c01292bf8237659a0dc951b5 [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
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000112# Determine whether auto-RRO is enabled for this package.
113enforce_rro_enabled :=
114ifeq ($(PRODUCT_ENFORCE_RRO_TARGETS),*)
115 # * means all system APKs, so enable conditionally based on module path.
116
117 # Note that base_rules.mk has not yet been included, so it's likely that only
118 # one of LOCAL_MODULE_PATH and the LOCAL_X_MODULE flags has been set.
119 ifeq (,$(LOCAL_MODULE_PATH))
120 non_system_module := $(filter true,\
121 $(LOCAL_ODM_MODULE) \
122 $(LOCAL_OEM_MODULE) \
123 $(LOCAL_PRODUCT_MODULE) \
124 $(LOCAL_PRODUCT_SERVICES_MODULE) \
125 $(LOCAL_PROPRIETARY_MODULE) \
126 $(LOCAL_VENDOR_MODULE))
127 enforce_rro_enabled := $(if $(non_system_module),,true)
128 else ifneq ($(filter $(TARGET_OUT)/%,$(LOCAL_MODULE_PATH)),)
129 enforce_rro_enabled := true
130 endif
131else ifneq (,$(filter $(LOCAL_PACKAGE_NAME), $(PRODUCT_ENFORCE_RRO_TARGETS)))
132 enforce_rro_enabled := true
133endif
134
135all_package_resource_overlays := $(strip \
Colin Cross8e404122014-02-06 14:45:37 -0800136 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
137 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
138 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
139 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))))
140
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000141static_resource_overlays :=
142runtime_resource_overlays :=
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900143ifdef enforce_rro_enabled
144 ifneq ($(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS),)
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000145 static_resource_overlays += $(filter $(addsuffix %,$(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS)),$(all_package_resource_overlays))
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900146 endif
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000147 runtime_resource_overlays := $(filter-out $(static_resource_overlays),$(all_package_resource_overlays))
Jaekyun Seokccee95e2017-09-01 17:23:25 +0900148else
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000149 static_resource_overlays := $(all_package_resource_overlays)
Jaekyun Seok30706102017-02-02 00:44:58 +0900150endif
Colin Cross8e404122014-02-06 14:45:37 -0800151
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000152# Add the static overlays. Auto-RRO is created later, as it depends on
153# other logic in this file.
154LOCAL_RESOURCE_DIR := $(static_resource_overlays) $(LOCAL_RESOURCE_DIR)
155
Colin Cross2c321442014-02-12 13:06:30 -0800156all_assets := $(strip \
157 $(foreach dir, $(LOCAL_ASSET_DIR), \
158 $(addprefix $(dir)/, \
159 $(patsubst assets/%,%, \
160 $(call find-subdir-assets, $(dir)) \
161 ) \
162 ) \
163 ))
Colin Cross8e404122014-02-06 14:45:37 -0800164
Ying Wang4cb04992014-07-29 10:34:30 -0700165ifneq ($(all_assets),)
166need_compile_asset := true
167endif
168
Dan Willemsenbb6393c2017-11-17 15:39:52 -0800169ifdef LOCAL_AAPT2_ONLY
170LOCAL_USE_AAPT2 := true
171endif
172
Adam Lesinskie758f932016-02-26 11:13:43 -0800173my_res_package :=
Colin Cross20299032018-05-09 13:29:51 -0700174ifeq ($(LOCAL_USE_AAPT2),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800175# In aapt2 the last takes precedence.
176my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
Adam Lesinskie758f932016-02-26 11:13:43 -0800177my_res_dir :=
178my_overlay_res_dirs :=
179
Colin Cross71c5b952018-05-23 13:35:53 -0700180ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),)
Adam Lesinskie758f932016-02-26 11:13:43 -0800181# If we are using static android libraries, every source file becomes an overlay.
182# This is to emulate old AAPT behavior which simulated library support.
183my_res_dir :=
184my_overlay_res_dirs := $(my_resource_dirs)
185else
186# Without static libraries, the first directory is our directory, which can then be
187# overlaid by the rest. (First directory in my_resource_dirs is last directory in
188# $(LOCAL_RESOURCE_DIR) due to it being reversed.
189my_res_dir := $(firstword $(my_resource_dirs))
190my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs))
191endif
192
Ying Wangdd71c852015-12-04 13:59:18 -0800193my_overlay_resources := $(strip \
Adam Lesinskie758f932016-02-26 11:13:43 -0800194 $(foreach d,$(my_overlay_res_dirs),\
Ying Wangdd71c852015-12-04 13:59:18 -0800195 $(addprefix $(d)/, \
196 $(call find-subdir-assets,$(d)))))
197
Colin Crossfe109632016-11-29 11:12:56 -0800198my_res_resources := $(if $(my_res_dir),$(strip \
Ying Wangdd71c852015-12-04 13:59:18 -0800199 $(addprefix $(my_res_dir)/, \
Colin Crossfe109632016-11-29 11:12:56 -0800200 $(call find-subdir-assets,$(my_res_dir)))))
Ying Wangdd71c852015-12-04 13:59:18 -0800201
202all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
203
204# The linked resource package.
205my_res_package := $(intermediates)/package-res.apk
206LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
207
Colin Cross35eb2e32018-11-01 20:34:08 +0000208ifeq ($(LOCAL_USE_AAPT2),true)
209 my_bundle_module := $(intermediates)/base.zip
210 LOCAL_INTERMEDIATE_TARGETS += $(my_bundle_module)
211endif
212
Ying Wange5853972016-03-01 12:06:47 -0800213# Always run aapt2, because we need to at least compile the AndroidManifest.xml.
Ying Wangdd71c852015-12-04 13:59:18 -0800214need_compile_res := true
215
Ying Wange295c3d2016-02-24 14:11:55 -0800216else # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800217all_resources := $(strip \
218 $(foreach dir, $(LOCAL_RESOURCE_DIR), \
219 $(addprefix $(dir)/, \
220 $(patsubst res/%,%, \
221 $(call find-subdir-assets,$(dir)) \
222 ) \
223 ) \
224 ))
225
Adam Lesinski4c452052016-08-12 12:57:17 -0700226ifdef LOCAL_PACKAGE_SPLITS
227LOCAL_AAPT_FLAGS += $(addprefix --split ,$(LOCAL_PACKAGE_SPLITS))
228endif
229
Ying Wange295c3d2016-02-24 14:11:55 -0800230endif # LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800231
Ying Wang61291922014-06-25 13:23:58 -0700232ifneq ($(all_resources),)
233 need_compile_res := true
234endif
235
Colin Cross8e404122014-02-06 14:45:37 -0800236all_res_assets := $(strip $(all_assets) $(all_resources))
237
Colin Cross8e404122014-02-06 14:45:37 -0800238# If no assets or resources were found, clear the directory variables so
239# we don't try to build them.
Ying Wang4cb04992014-07-29 10:34:30 -0700240ifneq (true,$(need_compile_asset))
Colin Cross8e404122014-02-06 14:45:37 -0800241LOCAL_ASSET_DIR:=
242endif
Ying Wang61291922014-06-25 13:23:58 -0700243ifneq (true,$(need_compile_res))
Colin Cross8e404122014-02-06 14:45:37 -0800244LOCAL_RESOURCE_DIR:=
245R_file_stamp :=
246else
247# Make sure that R_file_stamp inherits the proper PRIVATE vars.
248# If R.stamp moves, be sure to update the framework makefile,
249# which has intimate knowledge of its location.
Ying Wang98ae7982014-12-18 14:53:52 -0800250R_file_stamp := $(intermediates.COMMON)/src/R.stamp
Colin Cross8e404122014-02-06 14:45:37 -0800251LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
252endif
253
Narayan Kamath7c205102017-08-07 12:31:17 +0100254ifdef LOCAL_COMPRESSED_MODULE
255ifneq (true,$(LOCAL_COMPRESSED_MODULE))
256$(call pretty-error, Unknown value for LOCAL_COMPRESSED_MODULE $(LOCAL_COMPRESSED_MODULE))
257endif
258endif
259
260ifdef LOCAL_COMPRESSED_MODULE
Narayan Kamath6a4bd692017-08-14 10:53:50 +0100261PACKAGES.$(LOCAL_PACKAGE_NAME).COMPRESSED := gz
Narayan Kamath7c205102017-08-07 12:31:17 +0100262LOCAL_BUILT_MODULE_STEM := package.apk.gz
263LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk.gz
264else # !LOCAL_COMPRESSED_MODULE
Colin Cross8e404122014-02-06 14:45:37 -0800265LOCAL_BUILT_MODULE_STEM := package.apk
Ying Wangaf9757e2014-07-17 21:24:42 -0700266LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
Narayan Kamath7c205102017-08-07 12:31:17 +0100267endif
Colin Cross8e404122014-02-06 14:45:37 -0800268
269LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
270ifndef LOCAL_PROGUARD_ENABLED
271ifneq ($(DISABLE_PROGUARD),true)
272 LOCAL_PROGUARD_ENABLED :=full
273endif
274endif
275ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
276 # the package explicitly request to disable proguard.
277 LOCAL_PROGUARD_ENABLED :=
278endif
279proguard_options_file :=
280ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
Ying Wang61291922014-06-25 13:23:58 -0700281ifeq ($(need_compile_res),true)
Ying Wang98ae7982014-12-18 14:53:52 -0800282 proguard_options_file := $(intermediates.COMMON)/proguard_options
Ying Wang61291922014-06-25 13:23:58 -0700283endif # need_compile_res
Colin Cross8e404122014-02-06 14:45:37 -0800284endif # !custom
285LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
286
287ifeq (true,$(EMMA_INSTRUMENT))
288ifndef LOCAL_EMMA_INSTRUMENT
Jeff Gastonaaae43c2017-04-11 16:36:46 -0700289# No jacoco for test apks.
Ying Wang324ffb22015-11-06 11:22:28 -0800290ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
Colin Cross8e404122014-02-06 14:45:37 -0800291LOCAL_EMMA_INSTRUMENT := true
292endif # No test apk
293endif # LOCAL_EMMA_INSTRUMENT is not set
294else
295LOCAL_EMMA_INSTRUMENT := false
296endif # EMMA_INSTRUMENT is true
297
298ifeq (true,$(LOCAL_EMMA_INSTRUMENT))
299ifeq (true,$(EMMA_INSTRUMENT_STATIC))
Colin Cross11e2d552018-03-07 15:44:54 -0800300ifneq ($(LOCAL_SRC_FILES)$(LOCAL_SRCJARS)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
Colin Cross79e2f732016-12-21 14:29:13 -0800301# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100302LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Colin Crossdc4a6b82018-01-03 12:39:11 -0800303# Exclude jacoco classes from proguard
304LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800305endif # Contains java code
306else
Colin Cross8e404122014-02-06 14:45:37 -0800307ifdef LOCAL_SDK_VERSION
308ifdef TARGET_BUILD_APPS
Sebastien Hertz2319e562016-03-31 16:48:26 +0200309# In unbundled build, merge the coverage library into the apk.
Colin Cross79e2f732016-12-21 14:29:13 -0800310ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),)
311# Only add jacocoagent if the package contains some java code
Sebastien Hertzdfce8ad2015-11-19 17:53:00 +0100312LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent
Sebastien Hertz2319e562016-03-31 16:48:26 +0200313# Exclude jacoco classes from proguard
314LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
Colin Cross79e2f732016-12-21 14:29:13 -0800315endif # Contains java code
Colin Crosse673deb2017-09-27 14:28:41 -0700316endif # TARGET_BUILD_APPS
Colin Cross8e404122014-02-06 14:45:37 -0800317endif # LOCAL_SDK_VERSION
Colin Cross79e2f732016-12-21 14:29:13 -0800318endif # EMMA_INSTRUMENT_STATIC
Colin Cross8e404122014-02-06 14:45:37 -0800319endif # LOCAL_EMMA_INSTRUMENT
320
321rs_compatibility_jni_libs :=
322
Narayan Kamath7c205102017-08-07 12:31:17 +0100323# If the module is a compressed module, we don't pre-opt it because its final
324# installation location will be the data partition.
325ifdef LOCAL_COMPRESSED_MODULE
326LOCAL_DEX_PREOPT := false
327endif
328
Colin Crossead7b662019-02-06 16:36:32 -0800329# Default to use uncompressed native libraries in APKs if minSdkVersion >= marshmallow
330ifndef LOCAL_USE_EMBEDDED_NATIVE_LIBS
331 LOCAL_USE_EMBEDDED_NATIVE_LIBS := $(call math_gt_or_eq, \
332 $(patsubst $(PLATFORM_VERSION_CODENAME),100,$(call module-min-sdk-version)),23)
333endif
334
Ying Wange9dd9f22014-10-29 15:48:32 -0700335include $(BUILD_SYSTEM)/android_manifest.mk
336
Colin Cross7a281582018-03-06 16:21:36 -0800337resource_export_package :=
338
339include $(BUILD_SYSTEM)/java_renderscript.mk
340
341include $(BUILD_SYSTEM)/aapt_flags.mk
342
343ifeq ($(need_compile_res),true)
344
345###############################
346## APK splits
347built_apk_splits :=
348installed_apk_splits :=
349my_apk_split_configs :=
350
351ifdef LOCAL_PACKAGE_SPLITS
352ifdef LOCAL_COMPRESSED_MODULE
353$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs)
354endif # LOCAL_COMPRESSED_MODULE
355
356my_apk_split_configs := $(LOCAL_PACKAGE_SPLITS)
357my_split_suffixes := $(subst $(comma),_,$(my_apk_split_configs))
358built_apk_splits := $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk)
359endif
360
361$(R_file_stamp) $(my_res_package): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
362$(R_file_stamp) $(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
363$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
364$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
365
366###############################
367## AAPT/AAPT2
368
Colin Cross20299032018-05-09 13:29:51 -0700369ifeq ($(LOCAL_USE_AAPT2),true)
Colin Cross7a281582018-03-06 16:21:36 -0800370 my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res
Colin Cross532ae3b2018-05-15 15:15:38 -0700371 ifneq (,$(filter-out current,$(renderscript_target_api)))
Colin Cross7a281582018-03-06 16:21:36 -0800372 ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true)
373 my_generated_res_zips := $(rs_generated_res_zip)
374 endif # renderscript_target_api < 21
375 endif # renderscript_target_api is set
376 my_asset_dirs := $(LOCAL_ASSET_DIR)
377 my_full_asset_paths := $(all_assets)
378
379 # Add AAPT2 link specific flags.
380 $(my_res_package): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
381 ifndef LOCAL_AAPT_NAMESPACES
382 $(my_res_package): PRIVATE_AAPT_FLAGS += --no-static-lib-packages
383 endif
384
385 include $(BUILD_SYSTEM)/aapt2.mk
386else # LOCAL_USE_AAPT2
387
Colin Crossf6d68cf2018-03-08 16:49:16 -0800388 my_srcjar := $(intermediates.COMMON)/aapt.srcjar
389 LOCAL_SRCJARS += $(my_srcjar)
390 $(R_file_stamp): PRIVATE_SRCJAR := $(my_srcjar)
391 $(R_file_stamp): PRIVATE_JAVA_GEN_DIR := $(intermediates.COMMON)/aapt
392 $(R_file_stamp): .KATI_IMPLICIT_OUTPUTS := $(my_srcjar)
Colin Cross7a281582018-03-06 16:21:36 -0800393 # Since we don't know where the real R.java file is going to end up,
394 # we need to use another file to stand in its place. We'll just
395 # copy the generated file to src/R.stamp, which means it will
396 # have the same contents and timestamp as the actual file.
397 #
398 # At the same time, this will copy the R.java file to a central
399 # 'R' directory to make it easier to add the files to an IDE.
400 #
401
402 $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
403 $(intermediates.COMMON)/public_resources.xml
404 $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
405 $(R_file_stamp): PRIVATE_RESOURCE_LIST := $(all_res_assets)
Colin Crossf6d68cf2018-03-08 16:49:16 -0800406 $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(rs_generated_res_zip) $(AAPT) $(SOONG_ZIP) | $(ACP)
Colin Cross7a281582018-03-06 16:21:36 -0800407 @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
408 @rm -rf $@ && mkdir -p $(dir $@)
409 $(create-resource-java-files)
Colin Crossf6d68cf2018-03-08 16:49:16 -0800410 $(call find-generated-R.java,$(PRIVATE_JAVA_GEN_DIR),$@)
Colin Cross7a281582018-03-06 16:21:36 -0800411
412 $(proguard_options_file): $(R_file_stamp)
413
414 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
415 # Put this module's resources into a PRODUCT-agnositc package that
416 # other packages can use to build their own PRODUCT-agnostic R.java (etc.)
417 # files.
418 resource_export_package := $(intermediates.COMMON)/package-export.apk
419 $(R_file_stamp): $(resource_export_package)
420
Colin Crossc9e49762018-09-14 13:39:07 -0700421 # create-assets-package looks at PRODUCT_AAPT_CONFIG, but this target
Colin Cross7a281582018-03-06 16:21:36 -0800422 # can't know anything about PRODUCT. Clear it out just for this target.
423 $(resource_export_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
424 $(resource_export_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
425 $(resource_export_package): PRIVATE_RESOURCE_LIST := $(all_res_assets)
Colin Cross14658062018-05-15 16:04:47 -0700426 $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(rs_generated_res_zip) $(AAPT)
Colin Cross7a281582018-03-06 16:21:36 -0800427 @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
Colin Crossc9e49762018-09-14 13:39:07 -0700428 $(call create-assets-package,$@)
Colin Cross7a281582018-03-06 16:21:36 -0800429 endif
430
431endif # LOCAL_USE_AAPT2
432
433endif # need_compile_res
434
Colin Cross6db5b0e2018-11-16 21:26:33 -0800435my_dex_jar := $(intermediates.COMMON)/dex.jar
436
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100437called_from_package_internal := true
Colin Cross8e404122014-02-06 14:45:37 -0800438#################################
439include $(BUILD_SYSTEM)/java.mk
440#################################
Narayan Kamathbbcdc072017-08-22 15:47:08 +0100441called_from_package_internal :=
Colin Cross8e404122014-02-06 14:45:37 -0800442
Colin Cross7a281582018-03-06 16:21:36 -0800443ifeq ($(need_compile_res),true)
444
445# Other modules should depend on the BUILT module if
446# they want to use this module's R.java file.
447$(LOCAL_BUILT_MODULE): $(R_file_stamp)
448
449# The R.java file must exist by the time the java source
450# list is generated
451$(java_source_list_file): $(R_file_stamp)
452
453endif # need_compile_res
454
Colin Cross8e404122014-02-06 14:45:37 -0800455LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
456ifeq ($(LOCAL_SDK_RES_VERSION),)
457 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
458endif
459
Colin Cross8e404122014-02-06 14:45:37 -0800460$(LOCAL_INTERMEDIATE_TARGETS): \
461 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
Colin Cross8e404122014-02-06 14:45:37 -0800462
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800463framework_res_package_export :=
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800464
465ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
Colin Cross8e404122014-02-06 14:45:37 -0800466# Most packages should link against the resources defined by framework-res.
467# Even if they don't have their own resources, they may use framework
468# resources.
Dan Willemsenc51b7b02018-02-16 13:31:17 -0800469ifeq ($(LOCAL_SDK_RES_VERSION),core_current)
470# core_current doesn't contain any framework resources.
Colin Cross8e0ff1c2018-12-18 22:43:16 -0800471else 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 -0800472# for released sdk versions, the platform resources were built into android.jar.
473framework_res_package_export := \
Anton Hansson66d47b82018-04-27 14:11:17 +0100474 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION))
Colin Cross8e404122014-02-06 14:45:37 -0800475else # LOCAL_SDK_RES_VERSION
476framework_res_package_export := \
477 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
Colin Cross8e404122014-02-06 14:45:37 -0800478endif # LOCAL_SDK_RES_VERSION
Adam Lesinski6b6283a2018-02-14 16:18:12 -0800479endif # LOCAL_NO_STANDARD_LIBRARIES
480
Adam Lesinskide057c32014-03-13 18:48:27 -0700481all_library_res_package_exports := \
482 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700483 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700484 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk)
485
486all_library_res_package_export_deps := \
Colin Cross6e136922018-02-20 14:31:33 -0800487 $(framework_res_package_export) \
Adam Lesinski5eebe0f2014-03-25 15:45:34 -0700488 $(foreach lib,$(LOCAL_RES_LIBRARIES),\
Adam Lesinskide057c32014-03-13 18:48:27 -0700489 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
Ying Wangb5745642014-06-19 16:07:30 -0700490$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
Colin Cross8e404122014-02-06 14:45:37 -0800491$(LOCAL_INTERMEDIATE_TARGETS): \
Adam Lesinskide057c32014-03-13 18:48:27 -0700492 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
Ying Wangdd71c852015-12-04 13:59:18 -0800493
Colin Cross20299032018-05-09 13:29:51 -0700494ifeq ($(LOCAL_USE_AAPT2),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800495$(my_res_package) : $(all_library_res_package_export_deps)
496endif
Colin Cross8e404122014-02-06 14:45:37 -0800497
Colin Cross7a281582018-03-06 16:21:36 -0800498# These four are set above for $(R_stamp_file) and $(my_res_package), but
499# $(LOCAL_BUILT_MODULE) is not set before java.mk, so they have to be set again
500# here.
501$(LOCAL_BUILT_MODULE): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS)
502$(LOCAL_BUILT_MODULE): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS)
503$(LOCAL_BUILT_MODULE): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
504$(LOCAL_BUILT_MODULE): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
505
Colin Cross8e404122014-02-06 14:45:37 -0800506ifneq ($(full_classes_jar),)
507$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
Colin Cross79e2f732016-12-21 14:29:13 -0800508# Use the jarjar processed arhive as the initial package file.
Colin Crossffbf0a62017-03-29 12:58:15 -0700509$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
Colin Cross8e404122014-02-06 14:45:37 -0800510$(LOCAL_BUILT_MODULE): $(built_dex)
Ying Wang33360dd2015-01-14 14:23:56 -0800511else
512$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
Colin Cross79e2f732016-12-21 14:29:13 -0800513$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE :=
Colin Cross8e404122014-02-06 14:45:37 -0800514endif # full_classes_jar
515
Ying Wang96bcad42014-04-17 13:38:04 -0700516include $(BUILD_SYSTEM)/install_jni_libs.mk
Colin Cross8e404122014-02-06 14:45:37 -0800517
518# Pick a key to sign the package with. If this package hasn't specified
519# an explicit certificate, use the default.
520# Secure release builds will have their packages signed after the fact,
521# so it's ok for these private keys to be in the clear.
522ifeq ($(LOCAL_CERTIFICATE),)
523 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
524endif
525
526ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
527 # The special value "EXTERNAL" means that we will sign it with the
528 # default devkey, apply predexopt, but then expect the final .apk
529 # (after dexopting) to be signed by an outside tool.
530 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
531 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
532endif
533
534# If this is not an absolute certificate, assign it to a generic one.
535ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
536 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
537endif
Jeongik Chab2c4bb72018-12-17 14:45:15 +0900538include $(BUILD_SYSTEM)/app_certificate_validate.mk
Colin Cross8e404122014-02-06 14:45:37 -0800539private_key := $(LOCAL_CERTIFICATE).pk8
540certificate := $(LOCAL_CERTIFICATE).x509.pem
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900541additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
Colin Cross8e404122014-02-06 14:45:37 -0800542
543$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
544$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
545$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
546
547PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
548PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
549
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900550$(LOCAL_BUILT_MODULE): $(additional_certificates)
551$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
Colin Cross8e404122014-02-06 14:45:37 -0800552
553# Define the rule to build the actual package.
Ying Wang8e20ef62014-06-24 20:01:52 -0700554# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
555$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
556# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
557$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
Colin Cross8e404122014-02-06 14:45:37 -0800558ifneq ($(TARGET_BUILD_APPS),)
559 # Include all resources for unbundled apps.
560 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
561endif
562ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
Adam Lesinskie758f932016-02-26 11:13:43 -0800563 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
564 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Colin Cross8e404122014-02-06 14:45:37 -0800565else
Adam Lesinskie758f932016-02-26 11:13:43 -0800566 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
Ying Wang934008f2014-07-30 13:40:14 -0700567ifdef LOCAL_PACKAGE_SPLITS
Adam Lesinskie758f932016-02-26 11:13:43 -0800568 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
Ying Wang934008f2014-07-30 13:40:14 -0700569else
Adam Lesinskie758f932016-02-26 11:13:43 -0800570 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG)
Colin Cross8e404122014-02-06 14:45:37 -0800571endif
Ying Wang934008f2014-07-30 13:40:14 -0700572endif
Colin Cross303567c2017-08-03 03:17:34 +0000573
Dario Freni924af7d2018-08-17 00:56:14 +0100574# Run veridex on product, product_services and vendor modules.
David Brazdil825770e2018-07-31 11:31:30 +0100575# We skip it for unbundled app builds where we cannot build veridex.
576module_run_appcompat :=
Jeongik Cha83c50322019-01-18 15:09:09 +0900577ifeq (true,$(non_system_module))
David Brazdil825770e2018-07-31 11:31:30 +0100578ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build
Adrian Roos21028b72019-01-15 18:30:51 +0100579ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
David Brazdil825770e2018-07-31 11:31:30 +0100580 module_run_appcompat := true
581endif
582endif
Adrian Roos21028b72019-01-15 18:30:51 +0100583endif
David Brazdil825770e2018-07-31 11:31:30 +0100584
585ifeq ($(module_run_appcompat),true)
Dan Willemsenb73ccb72018-09-17 14:36:37 -0700586$(LOCAL_BUILT_MODULE) : $(appcompat-files)
Dario Freni716e9b62018-07-31 15:29:13 +0100587$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE)
Dario Freni1ecc9252018-07-13 16:44:28 +0100588endif
589
Colin Cross303567c2017-08-03 03:17:34 +0000590$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/resources
Ying Wangdd71c852015-12-04 13:59:18 -0800591$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
Colin Crossc9e49762018-09-14 13:39:07 -0700592$(LOCAL_BUILT_MODULE) : $(JAR_ARGS) $(SOONG_ZIP) $(MERGE_ZIPS) $(ZIP2ZIP)
Colin Cross20299032018-05-09 13:29:51 -0700593ifeq ($(LOCAL_USE_AAPT2),true)
Ying Wangdd71c852015-12-04 13:59:18 -0800594$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
595$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
596else
Dan Willemsenf439c332017-10-02 14:22:02 -0700597$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_LIST := $(all_res_assets)
Nicolas Geoffraya95fbd12017-09-19 13:10:31 +0100598$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT) $(ZIPALIGN)
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000599endif # LOCAL_USE_AAPT2
Narayan Kamath7c205102017-08-07 12:31:17 +0100600ifdef LOCAL_COMPRESSED_MODULE
601$(LOCAL_BUILT_MODULE) : $(MINIGZIP)
602endif
Colin Crossdac94ff2018-10-07 21:32:07 -0700603ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
604$(LOCAL_BUILT_MODULE) : $(ZIP2ZIP)
605endif
Colin Cross53c8f972018-09-28 16:19:42 -0700606ifneq ($(BUILD_PLATFORM_ZIP),)
607$(LOCAL_BUILT_MODULE) : .KATI_IMPLICIT_OUTPUTS := $(dir $(LOCAL_BUILT_MODULE))package.dex.apk
608endif
Colin Cross6db5b0e2018-11-16 21:26:33 -0800609ifdef LOCAL_DEX_PREOPT
610$(LOCAL_BUILT_MODULE) : PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh
611$(LOCAL_BUILT_MODULE) : $(intermediates)/strip.sh
Colin Crossded0aec2019-01-17 16:22:04 -0800612$(LOCAL_BUILT_MODULE) : | $(DEXPREOPT_STRIP_DEPS)
Colin Cross6db5b0e2018-11-16 21:26:33 -0800613$(LOCAL_BUILT_MODULE): .KATI_DEPFILE := $(LOCAL_BUILT_MODULE).d
614endif
Colin Crossead7b662019-02-06 16:36:32 -0800615$(LOCAL_BUILT_MODULE): PRIVATE_USE_EMBEDDED_NATIVE_LIBS := $(LOCAL_USE_EMBEDDED_NATIVE_LIBS)
Colin Cross53c8f972018-09-28 16:19:42 -0700616$(LOCAL_BUILT_MODULE):
Colin Cross8e404122014-02-06 14:45:37 -0800617 @echo "target Package: $(PRIVATE_MODULE) ($@)"
Colin Crossc9e49762018-09-14 13:39:07 -0700618 rm -rf $@.parts
619 mkdir -p $@.parts
Colin Cross20299032018-05-09 13:29:51 -0700620ifeq ($(LOCAL_USE_AAPT2),true)
Colin Cross53c8f972018-09-28 16:19:42 -0700621 cp -f $(PRIVATE_RES_PACKAGE) $@.parts/apk.zip
Ying Wang81ef4712016-03-31 10:10:42 -0700622else # ! LOCAL_USE_AAPT2
Colin Crossc9e49762018-09-14 13:39:07 -0700623 $(call create-assets-package,$@.parts/apk.zip)
Ying Wange295c3d2016-02-24 14:11:55 -0800624endif # LOCAL_USE_AAPT2
Colin Cross8e404122014-02-06 14:45:37 -0800625ifneq ($(jni_shared_libraries),)
Colin Crossead7b662019-02-06 16:36:32 -0800626 $(call create-jni-shared-libs-package,$@.parts/jni.zip,$(PRIVATE_USE_EMBEDDED_NATIVE_LIBS))
Colin Cross8e404122014-02-06 14:45:37 -0800627endif
Ying Wang8b27d182015-03-27 11:07:17 -0700628ifeq ($(full_classes_jar),)
629# We don't build jar, need to add the Java resources here.
Colin Crossc9e49762018-09-14 13:39:07 -0700630 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call create-java-resources-jar,$@.parts/res.zip))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800631else # full_classes_jar
Colin Crossc9e49762018-09-14 13:39:07 -0700632 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
633 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
Ying Wang3a61eeb2016-03-11 10:32:01 -0800634endif # full_classes_jar
Colin Crossc9e49762018-09-14 13:39:07 -0700635 $(MERGE_ZIPS) $@ $@.parts/*.zip
636 rm -rf $@.parts
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000637ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
638 @# No need to align, sign-package below will do it.
639 $(uncompress-dexs)
640endif
Dario Freni1ecc9252018-07-13 16:44:28 +0100641# Run appcompat before stripping the classes.dex file.
David Brazdil825770e2018-07-31 11:31:30 +0100642ifeq ($(module_run_appcompat),true)
Dario Freni716e9b62018-07-31 15:29:13 +0100643ifeq ($(LOCAL_USE_AAPT2),true)
644 $(call appcompat-header, aapt2)
645else
646 $(appcompat-header)
647endif
Dario Freni1ecc9252018-07-13 16:44:28 +0100648 $(run-appcompat)
David Brazdil825770e2018-07-31 11:31:30 +0100649endif # module_run_appcompat
Colin Cross8e404122014-02-06 14:45:37 -0800650ifdef LOCAL_DEX_PREOPT
Ying Wang3a61eeb2016-03-11 10:32:01 -0800651ifneq ($(BUILD_PLATFORM_ZIP),)
652 @# Keep a copy of apk with classes.dex unstripped
653 $(hide) cp -f $@ $(dir $@)package.dex.apk
654endif # BUILD_PLATFORM_ZIP
Dan Willemsen07b73572019-01-07 13:58:37 -0800655 mv -f $@ $@.tmp
656 $(PRIVATE_STRIP_SCRIPT) $@.tmp $@
Nicolas Geoffray3972a472018-01-09 11:46:30 +0000657endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700658 $(sign-package)
Narayan Kamath7c205102017-08-07 12:31:17 +0100659ifdef LOCAL_COMPRESSED_MODULE
660 $(compress-package)
661endif # LOCAL_COMPRESSED_MODULE
Colin Cross8e404122014-02-06 14:45:37 -0800662
Colin Cross35eb2e32018-11-01 20:34:08 +0000663ifeq ($(LOCAL_USE_AAPT2),true)
664 my_package_res_pb := $(intermediates)/package-res.pb.apk
665 $(my_package_res_pb): $(my_res_package) $(AAPT2)
666 $(AAPT2) convert --output-format proto $< -o $@
667
668 $(my_bundle_module): $(my_package_res_pb)
669 $(my_bundle_module): PRIVATE_RES_PACKAGE := $(my_package_res_pb)
670
671 $(my_bundle_module): $(jni_shared_libraries)
672 $(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
673 $(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
674
675 ifneq ($(full_classes_jar),)
676 $(my_bundle_module): PRIVATE_DEX_FILE := $(built_dex)
677 # Use the jarjar processed archive as the initial package file.
678 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
679 $(my_bundle_module): $(built_dex)
680 else
681 $(my_bundle_module): PRIVATE_DEX_FILE :=
682 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE :=
683 endif # full_classes_jar
684
685 $(my_bundle_module): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP)
686 @echo "target Bundle: $(PRIVATE_MODULE) ($@)"
687 rm -rf $@.parts
688 mkdir -p $@.parts
689 $(ZIP2ZIP) -i $(PRIVATE_RES_PACKAGE) -o $@.parts/apk.zip AndroidManifest.xml:manifest/AndroidManifest.xml resources.pb "res/**/*" "assets/**/*"
690 ifneq ($(jni_shared_libraries),)
691 $(call create-jni-shared-libs-package,$@.parts/jni.zip)
692 endif
693 ifeq ($(full_classes_jar),)
694 # We don't build jar, need to add the Java resources here.
Colin Cross85fa3de2018-11-05 10:13:10 -0800695 $(if $(PRIVATE_EXTRA_JAR_ARGS),\
696 $(call create-java-resources-jar,$@.parts/res.zip) && \
697 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/" && \
698 mv -f $@.parts/res.zip.tmp $@.parts/res.zip)
Colin Cross35eb2e32018-11-01 20:34:08 +0000699 else # full_classes_jar
700 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
701 $(ZIP2ZIP) -i $@.parts/dex.zip -o $@.parts/dex.zip.tmp "classes*.dex:dex/"
702 mv -f $@.parts/dex.zip.tmp $@.parts/dex.zip
703 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
Colin Cross85fa3de2018-11-05 10:13:10 -0800704 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/"
705 mv -f $@.parts/res.zip.tmp $@.parts/res.zip
Colin Cross35eb2e32018-11-01 20:34:08 +0000706 endif # full_classes_jar
Colin Cross35eb2e32018-11-01 20:34:08 +0000707 $(MERGE_ZIPS) $@ $@.parts/*.zip
708 rm -rf $@.parts
709 ALL_MODULES.$(LOCAL_MODULE).BUNDLE := $(my_bundle_module)
710endif
711
Ying Wang36142f62014-05-21 16:13:33 -0700712###############################
Ying Wang8070b202014-12-01 17:46:56 -0800713## Build dpi-specific apks, if it's apps_only build.
714ifdef TARGET_BUILD_APPS
715ifdef LOCAL_DPI_VARIANTS
716$(foreach d, $(LOCAL_DPI_VARIANTS), \
717 $(eval my_dpi := $(d)) \
718 $(eval include $(BUILD_SYSTEM)/dpi_specific_apk.mk))
719endif
720endif
721
722###############################
Colin Cross6db5b0e2018-11-16 21:26:33 -0800723## Rule to build a jar containing dex files to dexpreopt without waiting for
724## the APK
Ying Wang36142f62014-05-21 16:13:33 -0700725ifdef LOCAL_DEX_PREOPT
Colin Cross6db5b0e2018-11-16 21:26:33 -0800726 $(my_dex_jar): PRIVATE_DEX_FILE := $(built_dex)
727 $(my_dex_jar): $(built_dex)
Ying Wang994c2262014-05-28 13:34:59 -0700728 $(hide) mkdir -p $(dir $@) && rm -f $@
Colin Crossc9e49762018-09-14 13:39:07 -0700729 $(call create-dex-jar,$@,$(PRIVATE_DEX_FILE))
Ying Wang36142f62014-05-21 16:13:33 -0700730endif
731
Ying Wang1425e2d2014-07-22 15:42:11 -0700732###############################
733## APK splits
734ifdef LOCAL_PACKAGE_SPLITS
Ying Wang7f625aa2014-07-23 10:27:57 -0700735# The splits should have been built in the same command building the base apk.
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800736# This rule just runs signing.
Ying Wang7f625aa2014-07-23 10:27:57 -0700737# Note that we explicily check the existence of the split apk and remove the
738# built base apk if the split apk isn't there.
739# That way the build system will rerun the aapt after the user changes the splitting parameters.
Ying Wang1425e2d2014-07-22 15:42:11 -0700740$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
741$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
Dan Willemsenf72308a2017-05-15 23:38:04 -0700742$(built_apk_splits) : $(intermediates)/%.apk : $(LOCAL_BUILT_MODULE)
Ying Wang7f625aa2014-07-23 10:27:57 -0700743 $(hide) if [ ! -f $@ ]; then \
744 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \
745 rm $<; exit 1; \
746 fi
747 $(sign-package)
Ying Wang1425e2d2014-07-22 15:42:11 -0700748
749# Rules to install the splits
Colin Cross7a281582018-03-06 16:21:36 -0800750installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Dan Willemsenf72308a2017-05-15 23:38:04 -0700751$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(intermediates)/package_%.apk
Ying Wang7f625aa2014-07-23 10:27:57 -0700752 @echo "Install: $@"
753 $(copy-file-to-new-target)
Ying Wang1425e2d2014-07-22 15:42:11 -0700754
755# Register the additional built and installed files.
756ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
757ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Dan Willemsenf72308a2017-05-15 23:38:04 -0700758 $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
Ying Wang1425e2d2014-07-22 15:42:11 -0700759
760# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700761$(my_all_targets): $(installed_apk_splits)
Ying Wang16243612015-06-03 12:43:50 -0700762
763ifdef LOCAL_COMPATIBILITY_SUITE
Ying Wang16243612015-06-03 12:43:50 -0700764
Simran Basi6bea37c2017-02-16 18:04:10 -0800765$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \
766 $(eval my_compat_dist_$(suite) := $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \
767 $(foreach s,$(my_split_suffixes),\
Dan Willemsenf72308a2017-05-15 23:38:04 -0700768 $(intermediates)/package_$(s).apk:$(dir)/$(LOCAL_MODULE)_$(s).apk))))
Ying Wang16243612015-06-03 12:43:50 -0700769
Simran Basi6bea37c2017-02-16 18:04:10 -0800770$(call create-suite-dependencies)
771
Ying Wang16243612015-06-03 12:43:50 -0700772endif # LOCAL_COMPATIBILITY_SUITE
Ying Wang1425e2d2014-07-22 15:42:11 -0700773endif # LOCAL_PACKAGE_SPLITS
774
Colin Cross8e404122014-02-06 14:45:37 -0800775# Save information about this package
776PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
777PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
Colin Cross8e404122014-02-06 14:45:37 -0800778
779PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
780
Colin Cross8e404122014-02-06 14:45:37 -0800781endif # skip_definition
782
783# Reset internal variables.
784all_res_assets :=
Jaekyun Seok30706102017-02-02 00:44:58 +0900785
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000786ifdef runtime_resource_overlays
Jaekyun Seok30706102017-02-02 00:44:58 +0900787 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
788 enforce_rro_use_res_lib := true
789 else
790 enforce_rro_use_res_lib := false
791 endif
792
793 ifdef LOCAL_MANIFEST_PACKAGE_NAME
794 enforce_rro_is_manifest_package_name := true
795 enforce_rro_manifest_package_info := $(LOCAL_MANIFEST_PACKAGE_NAME)
796 else
797 enforce_rro_is_manifest_package_name := false
798 enforce_rro_manifest_package_info := $(full_android_manifest)
799 endif
800
Anton Hanssonb7ee86f2019-03-14 19:48:17 +0000801 $(call append_enforce_rro_sources, \
802 $(my_register_name), \
803 $(enforce_rro_is_manifest_package_name), \
804 $(enforce_rro_manifest_package_info), \
805 $(enforce_rro_use_res_lib), \
806 $(runtime_resource_overlays) \
807 )
808endif