blob: 69f411ce751b75da1f1d920a2c516edb7086c4da [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
44# Run veridex on product, product_services and vendor modules.
45# We skip it for unbundled app builds where we cannot build veridex.
46module_run_appcompat :=
47ifeq (true,$(non_system_module))
48ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build
49ifneq ($(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
105my_enforced_uses_libraries :=
106ifdef LOCAL_ENFORCE_USES_LIBRARIES
107 my_enforced_uses_libraries := $(intermediates.COMMON)/enforce_uses_libraries.timestamp
108 $(my_enforced_uses_libraries): PRIVATE_USES_LIBRARIES := $(LOCAL_USES_LIBRARIES)
109 $(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(LOCAL_OPTIONAL_USES_LIBRARIES)
110 $(my_enforced_uses_libraries): $(BUILD_SYSTEM)/verify_uses_libraries.sh $(AAPT)
111 $(my_enforced_uses_libraries): $(my_prebuilt_src_file)
112 @echo Verifying uses-libraries: $<
113 aapt_binary=$(AAPT) \
114 uses_library_names="$(strip $(PRIVATE_USES_LIBRARIES))" \
115 optional_uses_library_names="$(strip $(PRIVATE_OPTIONAL_USES_LIBRARIES))" \
116 $(BUILD_SYSTEM)/verify_uses_libraries.sh $<
117 touch $@
118 $(built_module) : $(my_enforced_uses_libraries)
119endif
120
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700121dex_preopt_profile_src_file := $(my_prebuilt_src_file)
122
123rs_compatibility_jni_libs :=
124include $(BUILD_SYSTEM)/install_jni_libs.mk
125
126ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
127 # The magic string "EXTERNAL" means this package will be signed with
128 # the default dev key throughout the build process, but we expect
129 # the final package to be signed with a different key.
130 #
131 # This can be used for packages where we don't have access to the
132 # keys, but want the package to be predexopt'ed.
133 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
134 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
135
136 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
137 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
138 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
139endif
140ifeq ($(LOCAL_CERTIFICATE),)
141 # It is now a build error to add a prebuilt .apk without
142 # specifying a key for it.
143 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
144else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
145 # The magic string "PRESIGNED" means this package is already checked
146 # signed with its release key.
147 #
148 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
149 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
150 # but the dexpreopt process will not try to re-sign the app.
151 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
152 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
153else
154 # If this is not an absolute certificate, assign it to a generic one.
155 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
156 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
157 endif
158
159 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
160 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
161 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
162
163 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
164 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
165 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
166endif
167
168include $(BUILD_SYSTEM)/app_certificate_validate.mk
169
170# Disable dex-preopt of prebuilts to save space, if requested.
171ifndef LOCAL_DEX_PREOPT
172ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
173LOCAL_DEX_PREOPT := false
174endif
175endif
176
177# If the module is a compressed module, we don't pre-opt it because its final
178# installation location will be the data partition.
179ifdef LOCAL_COMPRESSED_MODULE
180LOCAL_DEX_PREOPT := false
181endif
182
183my_dex_jar := $(my_prebuilt_src_file)
184
185#######################################
186# defines built_odex along with rule to install odex
187include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
188#######################################
189ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
190# There is a replacement for the prebuilt .apk we can install without any processing.
191$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED)
192 $(transform-prebuilt-to-target)
193
194else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
195# Sign and align non-presigned .apks.
196# The embedded prebuilt jni to uncompress.
197ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
198# For PRESIGNED apks we must uncompress every .so file:
199# even if the .so file isn't for the current TARGET_ARCH,
200# we can't strip the file.
201embedded_prebuilt_jni_libs :=
202endif
203ifndef embedded_prebuilt_jni_libs
204# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
205embedded_prebuilt_jni_libs :=
206endif
207$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
208
209ifdef LOCAL_COMPRESSED_MODULE
210$(built_module) : $(MINIGZIP)
211endif
212
213ifeq ($(module_run_appcompat),true)
214$(built_module) : $(appcompat-files)
215$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE)
216endif
217
218ifneq ($(BUILD_PLATFORM_ZIP),)
219$(built_module) : .KATI_IMPLICIT_OUTPUTS := $(dir $(LOCAL_BUILT_MODULE))package.dex.apk
220endif
221ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
222ifdef LOCAL_DEX_PREOPT
223$(built_module) : PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh
224$(built_module) : $(intermediates)/strip.sh
225$(built_module) : | $(DEXPREOPT_STRIP_DEPS)
226$(built_module) : .KATI_DEPFILE := $(built_module).d
227endif
228endif
Colin Crossa0d89b92019-04-16 15:38:02 -0700229ifeq ($(module_run_appcompat),true)
230$(built_module) : $(AAPT2)
231endif
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700232$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(ZIP2ZIP) $(SIGNAPK_JAR)
233 $(transform-prebuilt-to-target)
234 $(uncompress-prebuilt-embedded-jni-libs)
235ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
236 $(uncompress-dexs)
237endif # LOCAL_UNCOMPRESS_DEX
238ifdef LOCAL_DEX_PREOPT
239ifneq ($(BUILD_PLATFORM_ZIP),)
240 @# Keep a copy of apk with classes.dex unstripped
241 $(hide) cp -f $@ $(dir $@)package.dex.apk
242endif # BUILD_PLATFORM_ZIP
243endif # LOCAL_DEX_PREOPT
244ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
245 @# Only strip out files if we can re-sign the package.
246# Run appcompat before stripping the classes.dex file.
247ifeq ($(module_run_appcompat),true)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700248 $(call appcompat-header, aapt2)
Jaewoong Jung09bfe552019-03-18 14:25:00 -0700249 $(run-appcompat)
250endif # module_run_appcompat
251ifdef LOCAL_DEX_PREOPT
252 mv -f $@ $@.tmp
253 $(PRIVATE_STRIP_SCRIPT) $@.tmp $@
254endif # LOCAL_DEX_PREOPT
255 $(sign-package)
256 # No need for align-package because sign-package takes care of alignment
257else # LOCAL_CERTIFICATE == PRESIGNED
258 $(align-package)
259endif # LOCAL_CERTIFICATE
260ifdef LOCAL_COMPRESSED_MODULE
261 $(compress-package)
262endif # LOCAL_COMPRESSED_MODULE
263endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
264
265
266###############################
267## Install split apks.
268ifdef LOCAL_PACKAGE_SPLITS
269ifdef LOCAL_COMPRESSED_MODULE
270$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs)
271endif # LOCAL_COMPRESSED_MODULE
272
273# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
274built_apk_splits := $(addprefix $(intermediates)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
275installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
276
277# Rules to sign the split apks.
278my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
279ifneq (1,$(words $(my_src_dir)))
280$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
281endif
282my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
283
284$(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
285$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
286$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
287$(built_apk_splits) : $(intermediates)/%.apk : $(my_src_dir)/%.apk
288 $(copy-file-to-new-target)
289 $(sign-package)
290
291# Rules to install the split apks.
292$(installed_apk_splits) : $(my_module_path)/%.apk : $(intermediates)/%.apk
293 @echo "Install: $@"
294 $(copy-file-to-new-target)
295
296# Register the additional built and installed files.
297ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
298ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
299 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(intermediates)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
300
301# Make sure to install the splits when you run "make <module_name>".
302$(my_all_targets): $(installed_apk_splits)
303
304endif # LOCAL_PACKAGE_SPLITS
305