blob: 829a6407e1284ce42727ec0d37e6250951d451da [file] [log] [blame]
Jaewoong Jung09bfe552019-03-18 14:25:00 -07001#
2# Copyright (C) 2019 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# Internal build rules for APPS prebuilt modules
19############################################################
20
21ifneq (APPS,$(LOCAL_MODULE_CLASS))
22$(call pretty-error,app_prebuilt_internal.mk is for APPS modules only)
23endif
24
25ifdef LOCAL_COMPRESSED_MODULE
26 ifneq (true,$(LOCAL_COMPRESSED_MODULE))
27 $(call pretty-error, Unknown value for LOCAL_COMPRESSED_MODULE $(LOCAL_COMPRESSED_MODULE))
28 endif
29 LOCAL_BUILT_MODULE_STEM := package.apk.gz
30 ifndef LOCAL_INSTALLED_MODULE_STEM
31 PACKAGES.$(LOCAL_MODULE).COMPRESSED := gz
32 LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk.gz
33 endif
34else # LOCAL_COMPRESSED_MODULE
35 LOCAL_BUILT_MODULE_STEM := package.apk
36 ifndef LOCAL_INSTALLED_MODULE_STEM
37 LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
38 endif
39endif # LOCAL_COMPRESSED_MODULE
40
41include $(BUILD_SYSTEM)/base_rules.mk
42built_module := $(LOCAL_BUILT_MODULE)
43
Justin Yun6151e3f2019-06-25 15:58:13 +090044# Run veridex on product, system_ext and vendor modules.
Jaewoong Jung09bfe552019-03-18 14:25:00 -070045# We skip it for unbundled app builds where we cannot build veridex.
46module_run_appcompat :=
47ifeq (true,$(non_system_module))
Dan Willemsena3f66322020-05-28 15:46:33 -070048ifeq (,$(TARGET_BUILD_APPS)) # ! unbundled app build
Jaewoong Jung09bfe552019-03-18 14:25:00 -070049ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true)
50 module_run_appcompat := true
51endif
52endif
53endif
54
55PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
56
57my_extract_apk := $(strip $(LOCAL_EXTRACT_APK))
58
59# Select dpi-specific source
60ifdef LOCAL_DPI_VARIANTS
61my_dpi := $(firstword $(filter $(LOCAL_DPI_VARIANTS),$(PRODUCT_AAPT_PREF_CONFIG) $(PRODUCT_AAPT_PREBUILT_DPI)))
62ifdef my_dpi
63ifdef LOCAL_DPI_FILE_STEM
64my_prebuilt_dpi_file_stem := $(LOCAL_DPI_FILE_STEM)
65else
66my_prebuilt_dpi_file_stem := $(LOCAL_MODULE)_%.apk
67endif
68my_prebuilt_src_file := $(dir $(my_prebuilt_src_file))$(subst %,$(my_dpi),$(my_prebuilt_dpi_file_stem))
69
70ifneq ($(strip $(LOCAL_EXTRACT_DPI_APK)),)
71my_extract_apk := $(subst %,$(my_dpi),$(LOCAL_EXTRACT_DPI_APK))
72endif # LOCAL_EXTRACT_DPI_APK
73endif # my_dpi
74endif # LOCAL_DPI_VARIANTS
75
76ifdef my_extract_apk
77my_extracted_apk := $(intermediates)/extracted.apk
78
79$(my_extracted_apk): PRIVATE_EXTRACT := $(my_extract_apk)
80$(my_extracted_apk): $(my_prebuilt_src_file)
81 @echo Extract APK: $@
82 $(hide) mkdir -p $(dir $@) && rm -f $@
83 $(hide) unzip -p $< $(PRIVATE_EXTRACT) >$@
84
85my_prebuilt_src_file := $(my_extracted_apk)
86my_extracted_apk :=
87my_extract_apk :=
88ifeq ($(PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK),true)
89# If the product property is set, always preopt for extracted modules to prevent executing out of
90# the APK.
91my_preopt_for_extracted_apk := true
92endif
93endif
94
Colin Cross56199af2019-05-22 10:25:59 -070095# Verify LOCAL_USES_LIBRARIES/LOCAL_OPTIONAL_USES_LIBRARIES
96# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or
97# LOCAL_OPTIONAL_USES_LIBRARIES are specified.
98# Will change the default to true unconditionally in the future.
99ifndef LOCAL_ENFORCE_USES_LIBRARIES
100 ifneq (,$(strip $(LOCAL_USES_LIBRARIES)$(LOCAL_OPTIONAL_USES_LIBRARIES)))
101 LOCAL_ENFORCE_USES_LIBRARIES := true
102 endif
103endif
104
Ulya Trafimovich6f06f9e2021-03-04 12:07:44 +0000105# Disable verify_uses_libraries check if dexpreopt is globally disabled.
106# Without dexpreopt the check is not necessary, and although it is good to have,
107# it is difficult to maintain on non-linux build platforms where dexpreopt is
108# generally disabled (the check may fail due to various unrelated reasons, such
109# as a failure to get manifest from an APK).
110ifneq ($(WITH_DEXPREOPT),true)
111 LOCAL_ENFORCE_USES_LIBRARIES :=
112endif
113
Colin Cross56199af2019-05-22 10:25:59 -0700114my_enforced_uses_libraries :=
115ifdef LOCAL_ENFORCE_USES_LIBRARIES
Ulya Trafimovicha2404512021-03-03 16:24:18 +0000116 my_verify_script := build/soong/scripts/manifest_check.py
117 my_uses_libs := $(patsubst %,--uses-library %,$(LOCAL_USES_LIBRARIES))
118 my_optional_uses_libs := $(patsubst %,--optional-uses-library %, \
119 $(LOCAL_OPTIONAL_USES_LIBRARIES))
120 my_relax_check := $(if $(filter true,$(RELAX_USES_LIBRARY_CHECK)), \
121 --enforce-uses-libraries-relax,)
Ulya Trafimovich5a09c202021-02-17 16:05:21 +0000122 my_enforced_uses_libraries := $(intermediates.COMMON)/enforce_uses_libraries.status
Ulya Trafimovicha2404512021-03-03 16:24:18 +0000123 $(my_enforced_uses_libraries): PRIVATE_USES_LIBRARIES := $(my_uses_libs)
124 $(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(my_optional_uses_libs)
125 $(my_enforced_uses_libraries): PRIVATE_RELAX_CHECK := $(my_relax_check)
Ulya Trafimovich78d96e82021-03-17 23:17:52 +0000126 $(my_enforced_uses_libraries): $(AAPT)
Ulya Trafimovicha2404512021-03-03 16:24:18 +0000127 $(my_enforced_uses_libraries): $(my_verify_script)
Colin Cross56199af2019-05-22 10:25:59 -0700128 $(my_enforced_uses_libraries): $(my_prebuilt_src_file)
129 @echo Verifying uses-libraries: $<
Ulya Trafimovich5a09c202021-02-17 16:05:21 +0000130 rm -f $@
Ulya Trafimovicha2404512021-03-03 16:24:18 +0000131 $(my_verify_script) \
132 --enforce-uses-libraries \
133 --enforce-uses-libraries-status $@ \
134 --aapt $(AAPT) \
135 $(PRIVATE_USES_LIBRARIES) \
136 $(PRIVATE_OPTIONAL_USES_LIBRARIES) \
137 $(PRIVATE_RELAX_CHECK) \
138 $<
Colin Cross56199af2019-05-22 10:25:59 -0700139 $(built_module) : $(my_enforced_uses_libraries)
140endif
141
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700142dex_preopt_profile_src_file := $(my_prebuilt_src_file)
143
144rs_compatibility_jni_libs :=
145include $(BUILD_SYSTEM)/install_jni_libs.mk
146
147ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
148 # The magic string "EXTERNAL" means this package will be signed with
149 # the default dev key throughout the build process, but we expect
150 # the final package to be signed with a different key.
151 #
152 # This can be used for packages where we don't have access to the
153 # keys, but want the package to be predexopt'ed.
154 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
155 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
156
157 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
158 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
159 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
160endif
161ifeq ($(LOCAL_CERTIFICATE),)
162 # It is now a build error to add a prebuilt .apk without
163 # specifying a key for it.
164 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
165else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
166 # The magic string "PRESIGNED" means this package is already checked
167 # signed with its release key.
168 #
169 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
170 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
171 # but the dexpreopt process will not try to re-sign the app.
172 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
173 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
174else
175 # If this is not an absolute certificate, assign it to a generic one.
176 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
177 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
178 endif
179
180 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
181 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
182 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
183
184 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
185 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
186 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
Jaewoong Jung95445e62020-04-02 13:01:08 -0700187
188 additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
189 $(built_module): $(additional_certificates)
190 $(built_module): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
191
192 $(built_module): $(LOCAL_CERTIFICATE_LINEAGE)
193 $(built_module): PRIVATE_CERTIFICATE_LINEAGE := $(LOCAL_CERTIFICATE_LINEAGE)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700194endif
195
Jiyong Park9314d8c2020-05-03 10:51:14 +0900196ifneq ($(LOCAL_MODULE_STEM),)
197 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE_STEM)
198else
199 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE)
200endif
201
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700202include $(BUILD_SYSTEM)/app_certificate_validate.mk
203
Bill Peckham19c3feb2020-03-20 18:31:43 -0700204# Set a actual_partition_tag (calculated in base_rules.mk) for the package.
205PACKAGES.$(LOCAL_MODULE).PARTITION := $(actual_partition_tag)
206
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700207# Disable dex-preopt of prebuilts to save space, if requested.
208ifndef LOCAL_DEX_PREOPT
209ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
210LOCAL_DEX_PREOPT := false
211endif
212endif
213
214# If the module is a compressed module, we don't pre-opt it because its final
215# installation location will be the data partition.
216ifdef LOCAL_COMPRESSED_MODULE
217LOCAL_DEX_PREOPT := false
218endif
219
220my_dex_jar := $(my_prebuilt_src_file)
221
222#######################################
223# defines built_odex along with rule to install odex
224include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
225#######################################
226ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
227# There is a replacement for the prebuilt .apk we can install without any processing.
228$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED)
229 $(transform-prebuilt-to-target)
230
231else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
232# Sign and align non-presigned .apks.
233# The embedded prebuilt jni to uncompress.
234ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
235# For PRESIGNED apks we must uncompress every .so file:
236# even if the .so file isn't for the current TARGET_ARCH,
237# we can't strip the file.
238embedded_prebuilt_jni_libs :=
239endif
240ifndef embedded_prebuilt_jni_libs
241# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
242embedded_prebuilt_jni_libs :=
243endif
244$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
245
246ifdef LOCAL_COMPRESSED_MODULE
247$(built_module) : $(MINIGZIP)
248endif
249
250ifeq ($(module_run_appcompat),true)
251$(built_module) : $(appcompat-files)
252$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE)
253endif
254
Colin Crossa0d89b92019-04-16 15:38:02 -0700255ifeq ($(module_run_appcompat),true)
256$(built_module) : $(AAPT2)
257endif
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700258$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(ZIP2ZIP) $(SIGNAPK_JAR)
259 $(transform-prebuilt-to-target)
260 $(uncompress-prebuilt-embedded-jni-libs)
Jaewoong Jungc18ebaf2021-02-18 15:06:08 -0800261 $(remove-unwanted-prebuilt-embedded-jni-libs)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700262ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
263 $(uncompress-dexs)
264endif # LOCAL_UNCOMPRESS_DEX
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700265ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700266ifeq ($(module_run_appcompat),true)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700267 $(call appcompat-header, aapt2)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700268 $(run-appcompat)
269endif # module_run_appcompat
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700270 $(sign-package)
271 # No need for align-package because sign-package takes care of alignment
272else # LOCAL_CERTIFICATE == PRESIGNED
273 $(align-package)
274endif # LOCAL_CERTIFICATE
275ifdef LOCAL_COMPRESSED_MODULE
276 $(compress-package)
277endif # LOCAL_COMPRESSED_MODULE
278endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
279
280
281###############################
282## Install split apks.
283ifdef LOCAL_PACKAGE_SPLITS
284ifdef LOCAL_COMPRESSED_MODULE
285$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs)
286endif # LOCAL_COMPRESSED_MODULE
287
288# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
289built_apk_splits := $(addprefix $(intermediates)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
290installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
291
292# Rules to sign the split apks.
293my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
294ifneq (1,$(words $(my_src_dir)))
295$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
296endif
297my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
298
299$(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
300$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
301$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
302$(built_apk_splits) : $(intermediates)/%.apk : $(my_src_dir)/%.apk
303 $(copy-file-to-new-target)
304 $(sign-package)
305
306# Rules to install the split apks.
307$(installed_apk_splits) : $(my_module_path)/%.apk : $(intermediates)/%.apk
308 @echo "Install: $@"
309 $(copy-file-to-new-target)
310
311# Register the additional built and installed files.
312ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
313ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
314 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(intermediates)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
315
316# Make sure to install the splits when you run "make <module_name>".
317$(my_all_targets): $(installed_apk_splits)
318
319endif # LOCAL_PACKAGE_SPLITS
320