blob: d47930c84eaaffb113285c8201da1d89cab37a1c [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 Trafimovich5a09c202021-02-17 16:05:21 +0000116 my_enforced_uses_libraries := $(intermediates.COMMON)/enforce_uses_libraries.status
Colin Cross56199af2019-05-22 10:25:59 -0700117 $(my_enforced_uses_libraries): PRIVATE_USES_LIBRARIES := $(LOCAL_USES_LIBRARIES)
118 $(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(LOCAL_OPTIONAL_USES_LIBRARIES)
Ulya Trafimovich5a09c202021-02-17 16:05:21 +0000119 $(my_enforced_uses_libraries): PRIVATE_RELAX_CHECK := $(RELAX_USES_LIBRARY_CHECK)
Colin Cross56199af2019-05-22 10:25:59 -0700120 $(my_enforced_uses_libraries): $(BUILD_SYSTEM)/verify_uses_libraries.sh $(AAPT)
121 $(my_enforced_uses_libraries): $(my_prebuilt_src_file)
122 @echo Verifying uses-libraries: $<
Ulya Trafimovich5a09c202021-02-17 16:05:21 +0000123 rm -f $@
Colin Cross56199af2019-05-22 10:25:59 -0700124 aapt_binary=$(AAPT) \
125 uses_library_names="$(strip $(PRIVATE_USES_LIBRARIES))" \
126 optional_uses_library_names="$(strip $(PRIVATE_OPTIONAL_USES_LIBRARIES))" \
Ulya Trafimovich5a09c202021-02-17 16:05:21 +0000127 relax_check="$(strip $(PRIVATE_RELAX_CHECK))" \
128 $(BUILD_SYSTEM)/verify_uses_libraries.sh $< $@
Colin Cross56199af2019-05-22 10:25:59 -0700129 $(built_module) : $(my_enforced_uses_libraries)
130endif
131
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700132dex_preopt_profile_src_file := $(my_prebuilt_src_file)
133
134rs_compatibility_jni_libs :=
135include $(BUILD_SYSTEM)/install_jni_libs.mk
136
137ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
138 # The magic string "EXTERNAL" means this package will be signed with
139 # the default dev key throughout the build process, but we expect
140 # the final package to be signed with a different key.
141 #
142 # This can be used for packages where we don't have access to the
143 # keys, but want the package to be predexopt'ed.
144 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
145 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
146
147 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
148 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
149 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
150endif
151ifeq ($(LOCAL_CERTIFICATE),)
152 # It is now a build error to add a prebuilt .apk without
153 # specifying a key for it.
154 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
155else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
156 # The magic string "PRESIGNED" means this package is already checked
157 # signed with its release key.
158 #
159 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
160 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
161 # but the dexpreopt process will not try to re-sign the app.
162 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
163 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
164else
165 # If this is not an absolute certificate, assign it to a generic one.
166 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
167 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
168 endif
169
170 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
171 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
172 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
173
174 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
175 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
176 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
Jaewoong Jung95445e62020-04-02 13:01:08 -0700177
178 additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
179 $(built_module): $(additional_certificates)
180 $(built_module): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates)
181
182 $(built_module): $(LOCAL_CERTIFICATE_LINEAGE)
183 $(built_module): PRIVATE_CERTIFICATE_LINEAGE := $(LOCAL_CERTIFICATE_LINEAGE)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700184endif
185
Jiyong Park9314d8c2020-05-03 10:51:14 +0900186ifneq ($(LOCAL_MODULE_STEM),)
187 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE_STEM)
188else
189 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE)
190endif
191
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700192include $(BUILD_SYSTEM)/app_certificate_validate.mk
193
Bill Peckham19c3feb2020-03-20 18:31:43 -0700194# Set a actual_partition_tag (calculated in base_rules.mk) for the package.
195PACKAGES.$(LOCAL_MODULE).PARTITION := $(actual_partition_tag)
196
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700197# Disable dex-preopt of prebuilts to save space, if requested.
198ifndef LOCAL_DEX_PREOPT
199ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
200LOCAL_DEX_PREOPT := false
201endif
202endif
203
204# If the module is a compressed module, we don't pre-opt it because its final
205# installation location will be the data partition.
206ifdef LOCAL_COMPRESSED_MODULE
207LOCAL_DEX_PREOPT := false
208endif
209
210my_dex_jar := $(my_prebuilt_src_file)
211
212#######################################
213# defines built_odex along with rule to install odex
214include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
215#######################################
216ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
217# There is a replacement for the prebuilt .apk we can install without any processing.
218$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED)
219 $(transform-prebuilt-to-target)
220
221else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
222# Sign and align non-presigned .apks.
223# The embedded prebuilt jni to uncompress.
224ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
225# For PRESIGNED apks we must uncompress every .so file:
226# even if the .so file isn't for the current TARGET_ARCH,
227# we can't strip the file.
228embedded_prebuilt_jni_libs :=
229endif
230ifndef embedded_prebuilt_jni_libs
231# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
232embedded_prebuilt_jni_libs :=
233endif
234$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
235
236ifdef LOCAL_COMPRESSED_MODULE
237$(built_module) : $(MINIGZIP)
238endif
239
240ifeq ($(module_run_appcompat),true)
241$(built_module) : $(appcompat-files)
242$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE)
243endif
244
Colin Crossa0d89b92019-04-16 15:38:02 -0700245ifeq ($(module_run_appcompat),true)
246$(built_module) : $(AAPT2)
247endif
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700248$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(ZIP2ZIP) $(SIGNAPK_JAR)
249 $(transform-prebuilt-to-target)
250 $(uncompress-prebuilt-embedded-jni-libs)
Jaewoong Jungc18ebaf2021-02-18 15:06:08 -0800251 $(remove-unwanted-prebuilt-embedded-jni-libs)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700252ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
253 $(uncompress-dexs)
254endif # LOCAL_UNCOMPRESS_DEX
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700255ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700256ifeq ($(module_run_appcompat),true)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700257 $(call appcompat-header, aapt2)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700258 $(run-appcompat)
259endif # module_run_appcompat
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700260 $(sign-package)
261 # No need for align-package because sign-package takes care of alignment
262else # LOCAL_CERTIFICATE == PRESIGNED
263 $(align-package)
264endif # LOCAL_CERTIFICATE
265ifdef LOCAL_COMPRESSED_MODULE
266 $(compress-package)
267endif # LOCAL_COMPRESSED_MODULE
268endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
269
270
271###############################
272## Install split apks.
273ifdef LOCAL_PACKAGE_SPLITS
274ifdef LOCAL_COMPRESSED_MODULE
275$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs)
276endif # LOCAL_COMPRESSED_MODULE
277
278# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
279built_apk_splits := $(addprefix $(intermediates)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
280installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
281
282# Rules to sign the split apks.
283my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
284ifneq (1,$(words $(my_src_dir)))
285$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
286endif
287my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
288
289$(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
290$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
291$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
292$(built_apk_splits) : $(intermediates)/%.apk : $(my_src_dir)/%.apk
293 $(copy-file-to-new-target)
294 $(sign-package)
295
296# Rules to install the split apks.
297$(installed_apk_splits) : $(my_module_path)/%.apk : $(intermediates)/%.apk
298 @echo "Install: $@"
299 $(copy-file-to-new-target)
300
301# Register the additional built and installed files.
302ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
303ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
304 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(intermediates)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
305
306# Make sure to install the splits when you run "make <module_name>".
307$(my_all_targets): $(installed_apk_splits)
308
309endif # LOCAL_PACKAGE_SPLITS
310