1 # 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 21 ifneq (APPS,$(LOCAL_MODULE_CLASS)) 22 $(call pretty-error,app_prebuilt_internal.mk is for APPS modules only) 23 endif 24 25 ifdef 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 34 else # 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 39 endif # LOCAL_COMPRESSED_MODULE 40 41 include $(BUILD_SYSTEM)/base_rules.mk 42 built_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. 46 module_run_appcompat := 47 ifeq (true,$(non_system_module)) 48 ifeq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK))) # ! unbundled app build 49 ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true) 50 module_run_appcompat := true 51 endif 52 endif 53 endif 54 55 PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES)) 56 57 my_extract_apk := $(strip $(LOCAL_EXTRACT_APK)) 58 59 # Select dpi-specific source 60 ifdef LOCAL_DPI_VARIANTS 61 my_dpi := $(firstword $(filter $(LOCAL_DPI_VARIANTS),$(PRODUCT_AAPT_PREF_CONFIG) $(PRODUCT_AAPT_PREBUILT_DPI))) 62 ifdef my_dpi 63 ifdef LOCAL_DPI_FILE_STEM 64 my_prebuilt_dpi_file_stem := $(LOCAL_DPI_FILE_STEM) 65 else 66 my_prebuilt_dpi_file_stem := $(LOCAL_MODULE)_%.apk 67 endif 68 my_prebuilt_src_file := $(dir $(my_prebuilt_src_file))$(subst %,$(my_dpi),$(my_prebuilt_dpi_file_stem)) 69 70 ifneq ($(strip $(LOCAL_EXTRACT_DPI_APK)),) 71 my_extract_apk := $(subst %,$(my_dpi),$(LOCAL_EXTRACT_DPI_APK)) 72 endif # LOCAL_EXTRACT_DPI_APK 73 endif # my_dpi 74 endif # LOCAL_DPI_VARIANTS 75 76 ifdef my_extract_apk 77 my_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 85 my_prebuilt_src_file := $(my_extracted_apk) 86 my_extracted_apk := 87 my_extract_apk := 88 ifeq ($(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. 91 my_preopt_for_extracted_apk := true 92 endif 93 endif 94 95 dex_preopt_profile_src_file := $(my_prebuilt_src_file) 96 97 rs_compatibility_jni_libs := 98 include $(BUILD_SYSTEM)/install_jni_libs.mk 99 100 ifeq ($(LOCAL_CERTIFICATE),EXTERNAL) 101 # The magic string "EXTERNAL" means this package will be signed with 102 # the default dev key throughout the build process, but we expect 103 # the final package to be signed with a different key. 104 # 105 # This can be used for packages where we don't have access to the 106 # keys, but want the package to be predexopt'ed. 107 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE) 108 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1 109 110 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem 111 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8 112 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem 113 endif 114 ifeq ($(LOCAL_CERTIFICATE),) 115 # It is now a build error to add a prebuilt .apk without 116 # specifying a key for it. 117 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)") 118 else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED) 119 # The magic string "PRESIGNED" means this package is already checked 120 # signed with its release key. 121 # 122 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be 123 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED") 124 # but the dexpreopt process will not try to re-sign the app. 125 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED 126 PACKAGES := $(PACKAGES) $(LOCAL_MODULE) 127 else 128 # If this is not an absolute certificate, assign it to a generic one. 129 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./) 130 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE) 131 endif 132 133 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8 134 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem 135 PACKAGES := $(PACKAGES) $(LOCAL_MODULE) 136 137 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem 138 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8 139 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem 140 endif 141 142 include $(BUILD_SYSTEM)/app_certificate_validate.mk 143 144 # Disable dex-preopt of prebuilts to save space, if requested. 145 ifndef LOCAL_DEX_PREOPT 146 ifeq ($(DONT_DEXPREOPT_PREBUILTS),true) 147 LOCAL_DEX_PREOPT := false 148 endif 149 endif 150 151 # If the module is a compressed module, we don't pre-opt it because its final 152 # installation location will be the data partition. 153 ifdef LOCAL_COMPRESSED_MODULE 154 LOCAL_DEX_PREOPT := false 155 endif 156 157 my_dex_jar := $(my_prebuilt_src_file) 158 159 ####################################### 160 # defines built_odex along with rule to install odex 161 include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk 162 ####################################### 163 ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),) 164 # There is a replacement for the prebuilt .apk we can install without any processing. 165 $(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED) 166 $(transform-prebuilt-to-target) 167 168 else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED 169 # Sign and align non-presigned .apks. 170 # The embedded prebuilt jni to uncompress. 171 ifeq ($(LOCAL_CERTIFICATE),PRESIGNED) 172 # For PRESIGNED apks we must uncompress every .so file: 173 # even if the .so file isn't for the current TARGET_ARCH, 174 # we can't strip the file. 175 embedded_prebuilt_jni_libs := 176 endif 177 ifndef embedded_prebuilt_jni_libs 178 # No LOCAL_PREBUILT_JNI_LIBS, uncompress all. 179 embedded_prebuilt_jni_libs := 180 endif 181 $(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs) 182 183 ifdef LOCAL_COMPRESSED_MODULE 184 $(built_module) : $(MINIGZIP) 185 endif 186 187 ifeq ($(module_run_appcompat),true) 188 $(built_module) : $(appcompat-files) 189 $(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE) 190 endif 191 192 ifneq ($(BUILD_PLATFORM_ZIP),) 193 $(built_module) : .KATI_IMPLICIT_OUTPUTS := $(dir $(LOCAL_BUILT_MODULE))package.dex.apk 194 endif 195 ifneq ($(LOCAL_CERTIFICATE),PRESIGNED) 196 ifdef LOCAL_DEX_PREOPT 197 $(built_module) : PRIVATE_STRIP_SCRIPT := $(intermediates)/strip.sh 198 $(built_module) : $(intermediates)/strip.sh 199 $(built_module) : | $(DEXPREOPT_STRIP_DEPS) 200 $(built_module) : .KATI_DEPFILE := $(built_module).d 201 endif 202 endif 203 ifeq ($(module_run_appcompat),true) 204 $(built_module) : $(AAPT2) 205 endif 206 $(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(ZIP2ZIP) $(SIGNAPK_JAR) 207 $(transform-prebuilt-to-target) 208 $(uncompress-prebuilt-embedded-jni-libs) 209 ifeq (true, $(LOCAL_UNCOMPRESS_DEX)) 210 $(uncompress-dexs) 211 endif # LOCAL_UNCOMPRESS_DEX 212 ifdef LOCAL_DEX_PREOPT 213 ifneq ($(BUILD_PLATFORM_ZIP),) 214 @# Keep a copy of apk with classes.dex unstripped 215 $(hide) cp -f $@ $(dir $@)package.dex.apk 216 endif # BUILD_PLATFORM_ZIP 217 endif # LOCAL_DEX_PREOPT 218 ifneq ($(LOCAL_CERTIFICATE),PRESIGNED) 219 @# Only strip out files if we can re-sign the package. 220 # Run appcompat before stripping the classes.dex file. 221 ifeq ($(module_run_appcompat),true) 222 $(call appcompat-header, aapt2) 223 $(run-appcompat) 224 endif # module_run_appcompat 225 ifdef LOCAL_DEX_PREOPT 226 mv -f $@ $@.tmp 227 $(PRIVATE_STRIP_SCRIPT) $@.tmp $@ 228 endif # LOCAL_DEX_PREOPT 229 $(sign-package) 230 # No need for align-package because sign-package takes care of alignment 231 else # LOCAL_CERTIFICATE == PRESIGNED 232 $(align-package) 233 endif # LOCAL_CERTIFICATE 234 ifdef LOCAL_COMPRESSED_MODULE 235 $(compress-package) 236 endif # LOCAL_COMPRESSED_MODULE 237 endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED 238 239 240 ############################### 241 ## Install split apks. 242 ifdef LOCAL_PACKAGE_SPLITS 243 ifdef LOCAL_COMPRESSED_MODULE 244 $(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs) 245 endif # LOCAL_COMPRESSED_MODULE 246 247 # LOCAL_PACKAGE_SPLITS is a list of apks to be installed. 248 built_apk_splits := $(addprefix $(intermediates)/,$(notdir $(LOCAL_PACKAGE_SPLITS))) 249 installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS))) 250 251 # Rules to sign the split apks. 252 my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS))) 253 ifneq (1,$(words $(my_src_dir))) 254 $(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS)) 255 endif 256 my_src_dir := $(LOCAL_PATH)/$(my_src_dir) 257 258 $(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem 259 $(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8 260 $(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem 261 $(built_apk_splits) : $(intermediates)/%.apk : $(my_src_dir)/%.apk 262 $(copy-file-to-new-target) 263 $(sign-package) 264 265 # Rules to install the split apks. 266 $(installed_apk_splits) : $(my_module_path)/%.apk : $(intermediates)/%.apk 267 @echo "Install: $@" 268 $(copy-file-to-new-target) 269 270 # Register the additional built and installed files. 271 ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits) 272 ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \ 273 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(intermediates)/$(notdir $(s)):$(my_module_path)/$(notdir $(s))) 274 275 # Make sure to install the splits when you run "make <module_name>". 276 $(my_all_targets): $(installed_apk_splits) 277 278 endif # LOCAL_PACKAGE_SPLITS 279 280