1# 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 28LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME)) 29ifeq ($(LOCAL_PACKAGE_NAME),) 30$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME) 31endif 32 33ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),) 34$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX) 35endif 36LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) 37 38ifneq ($(strip $(LOCAL_MODULE_STEM)$(LOCAL_BUILT_MODULE_STEM)),) 39$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_STEM or LOCAL_BUILT_MODULE_STEM) 40endif 41 42ifneq ($(strip $(LOCAL_MODULE)),) 43$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE) 44endif 45LOCAL_MODULE := $(LOCAL_PACKAGE_NAME) 46 47ifneq ($(strip $(LOCAL_MODULE_CLASS)),) 48$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS) 49endif 50LOCAL_MODULE_CLASS := APPS 51 52intermediates := $(call local-intermediates-dir) 53intermediates.COMMON := $(call local-intermediates-dir,COMMON) 54 55# Package LOCAL_MODULE_TAGS default to optional 56LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS)) 57ifeq ($(LOCAL_MODULE_TAGS),) 58LOCAL_MODULE_TAGS := optional 59endif 60 61ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),) 62# Force localization check if it's not tagged as tests. 63LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z 64endif 65 66need_compile_asset := 67ifeq (,$(LOCAL_ASSET_DIR)) 68LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets 69else 70need_compile_asset := true 71endif 72 73# LOCAL_RESOURCE_DIR may point to resource generated during the build 74need_compile_res := 75ifeq (,$(LOCAL_RESOURCE_DIR)) 76 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res 77else 78 need_compile_res := true 79 LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d))) 80endif 81 82# If LOCAL_MODULE matches a rule in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES, 83# override the manifest package name by the (first) rule matched 84override_manifest_name := $(strip $(word 1,\ 85 $(foreach rule,$(PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES),\ 86 $(eval _pkg_name_pat := $(call word-colon,1,$(rule)))\ 87 $(eval _manifest_name_pat := $(call word-colon,2,$(rule)))\ 88 $(if $(filter $(_pkg_name_pat),$(LOCAL_MODULE)),\ 89 $(patsubst $(_pkg_name_pat),$(_manifest_name_pat),$(LOCAL_MODULE))\ 90 )\ 91 )\ 92)) 93 94ifneq (,$(override_manifest_name)) 95# Note: this can override LOCAL_MANIFEST_PACKAGE_NAME value set in Android.mk 96LOCAL_MANIFEST_PACKAGE_NAME := $(override_manifest_name) 97endif 98 99include $(BUILD_SYSTEM)/force_aapt2.mk 100# validate that app contains a manifest file for aapt2 101ifeq (,$(strip $(LOCAL_MANIFEST_FILE)$(LOCAL_FULL_MANIFEST_FILE))) 102 ifeq (,$(wildcard $(LOCAL_PATH)/AndroidManifest.xml)) 103 $(call pretty-error,App missing manifest file which is required by aapt2. \ 104Provide a manifest file by either setting LOCAL_MANIFEST_FILE in Android.mk \ 105or via a AndroidManifest.xml in this directory) 106 endif 107endif 108 109# Process Support Library dependencies. 110include $(BUILD_SYSTEM)/support_libraries.mk 111 112# Determine whether auto-RRO is enabled for this package. 113enforce_rro_enabled := 114ifeq (,$(filter tests,$(LOCAL_MODULE_TAGS))) 115 ifneq (,$(filter *, $(PRODUCT_ENFORCE_RRO_TARGETS))) 116 # * means all system and system_ext APKs, so enable conditionally based on module path. 117 118 # Note that base_rules.mk has not yet been included, so it's likely that only 119 # one of LOCAL_MODULE_PATH and the LOCAL_X_MODULE flags has been set. 120 ifeq (,$(LOCAL_MODULE_PATH)) 121 non_rro_target_module := $(filter true,\ 122 $(LOCAL_ODM_MODULE) \ 123 $(LOCAL_OEM_MODULE) \ 124 $(LOCAL_PRODUCT_MODULE) \ 125 $(LOCAL_PROPRIETARY_MODULE) \ 126 $(LOCAL_VENDOR_MODULE)) 127 enforce_rro_enabled := $(if $(non_rro_target_module),,true) 128 else ifneq ($(filter $(TARGET_OUT)/%,$(LOCAL_MODULE_PATH)),) 129 enforce_rro_enabled := true 130 endif 131 else ifneq (,$(filter $(LOCAL_PACKAGE_NAME), $(PRODUCT_ENFORCE_RRO_TARGETS))) 132 enforce_rro_enabled := true 133 endif 134endif 135 136product_package_overlays := $(strip \ 137 $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \ 138 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR))))) 139device_package_overlays := $(strip \ 140 $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \ 141 $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR))))) 142 143static_resource_overlays := 144runtime_resource_overlays_product := 145runtime_resource_overlays_vendor := 146ifdef enforce_rro_enabled 147 ifneq ($(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS),) 148 # The PRODUCT_ exclusion variable applies to both inclusion variables.. 149 static_resource_overlays += $(filter $(addsuffix %,$(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS)),$(product_package_overlays)) 150 static_resource_overlays += $(filter $(addsuffix %,$(PRODUCT_ENFORCE_RRO_EXCLUDED_OVERLAYS)),$(device_package_overlays)) 151 endif 152 runtime_resource_overlays_product := $(filter-out $(static_resource_overlays),$(product_package_overlays)) 153 runtime_resource_overlays_vendor := $(filter-out $(static_resource_overlays),$(device_package_overlays)) 154else 155 static_resource_overlays := $(product_package_overlays) $(device_package_overlays) 156endif 157 158# Add the static overlays. Auto-RRO is created later, as it depends on 159# other logic in this file. 160LOCAL_RESOURCE_DIR := $(static_resource_overlays) $(LOCAL_RESOURCE_DIR) 161 162all_assets := $(strip \ 163 $(foreach dir, $(LOCAL_ASSET_DIR), \ 164 $(addprefix $(dir)/, \ 165 $(patsubst assets/%,%, \ 166 $(call find-subdir-assets, $(dir)) \ 167 ) \ 168 ) \ 169 )) 170 171ifneq ($(all_assets),) 172need_compile_asset := true 173endif 174 175my_res_package := 176# In aapt2 the last takes precedence. 177my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR)) 178my_res_dir := 179my_overlay_res_dirs := 180 181ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),) 182# If we are using static android libraries, every source file becomes an overlay. 183# This is to emulate old AAPT behavior which simulated library support. 184my_res_dir := 185my_overlay_res_dirs := $(my_resource_dirs) 186else 187# Without static libraries, the first directory is our directory, which can then be 188# overlaid by the rest. (First directory in my_resource_dirs is last directory in 189# $(LOCAL_RESOURCE_DIR) due to it being reversed. 190my_res_dir := $(firstword $(my_resource_dirs)) 191my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs)) 192endif 193 194my_overlay_resources := $(strip \ 195 $(foreach d,$(my_overlay_res_dirs),\ 196 $(addprefix $(d)/, \ 197 $(call find-subdir-assets,$(d))))) 198 199my_res_resources := $(if $(my_res_dir),$(strip \ 200 $(addprefix $(my_res_dir)/, \ 201 $(call find-subdir-assets,$(my_res_dir))))) 202 203all_resources := $(strip $(my_res_resources) $(my_overlay_resources)) 204 205# The linked resource package. 206my_res_package := $(intermediates.COMMON)/package-res.apk 207LOCAL_INTERMEDIATE_TARGETS += $(my_res_package) 208 209my_bundle_module := $(intermediates.COMMON)/base.zip 210LOCAL_INTERMEDIATE_TARGETS += $(my_bundle_module) 211 212# Always run aapt2, because we need to at least compile the AndroidManifest.xml. 213need_compile_res := true 214 215ifneq ($(all_resources),) 216 need_compile_res := true 217endif 218 219all_res_assets := $(strip $(all_assets) $(all_resources)) 220 221# If no assets or resources were found, clear the directory variables so 222# we don't try to build them. 223ifneq (true,$(need_compile_asset)) 224LOCAL_ASSET_DIR:= 225endif 226ifneq (true,$(need_compile_res)) 227LOCAL_RESOURCE_DIR:= 228R_file_stamp := 229else 230# Make sure that R_file_stamp inherits the proper PRIVATE vars. 231# If R.stamp moves, be sure to update the framework makefile, 232# which has intimate knowledge of its location. 233R_file_stamp := $(intermediates.COMMON)/src/R.stamp 234LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp) 235endif 236 237ifdef LOCAL_COMPRESSED_MODULE 238ifneq (true,$(LOCAL_COMPRESSED_MODULE)) 239$(call pretty-error, Unknown value for LOCAL_COMPRESSED_MODULE $(LOCAL_COMPRESSED_MODULE)) 240endif 241endif 242 243ifdef LOCAL_COMPRESSED_MODULE 244PACKAGES.$(LOCAL_PACKAGE_NAME).COMPRESSED := gz 245LOCAL_BUILT_MODULE_STEM := package.apk.gz 246LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk.gz 247else # !LOCAL_COMPRESSED_MODULE 248LOCAL_BUILT_MODULE_STEM := package.apk 249LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk 250endif 251 252LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED)) 253ifndef LOCAL_PROGUARD_ENABLED 254ifneq ($(DISABLE_PROGUARD),true) 255 LOCAL_PROGUARD_ENABLED :=full 256endif 257endif 258ifeq ($(LOCAL_PROGUARD_ENABLED),disabled) 259 # the package explicitly request to disable proguard. 260 LOCAL_PROGUARD_ENABLED := 261endif 262proguard_options_file := 263ifneq ($(LOCAL_PROGUARD_ENABLED),custom) 264ifeq ($(need_compile_res),true) 265 proguard_options_file := $(intermediates.COMMON)/proguard_options 266endif # need_compile_res 267endif # !custom 268LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS) 269LOCAL_PROGUARD_FLAGS_DEPS += $(proguard_options_file) 270 271ifeq (true,$(EMMA_INSTRUMENT)) 272ifndef LOCAL_EMMA_INSTRUMENT 273# No jacoco for test apks. 274ifeq (,$(LOCAL_INSTRUMENTATION_FOR)) 275LOCAL_EMMA_INSTRUMENT := true 276endif # No test apk 277endif # LOCAL_EMMA_INSTRUMENT is not set 278else 279LOCAL_EMMA_INSTRUMENT := false 280endif # EMMA_INSTRUMENT is true 281 282ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) 283ifeq (true,$(EMMA_INSTRUMENT_STATIC)) 284ifneq ($(LOCAL_SRC_FILES)$(LOCAL_SRCJARS)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) 285# Only add jacocoagent if the package contains some java code 286LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent 287# Exclude jacoco classes from proguard 288LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags 289LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags 290endif # Contains java code 291else 292ifdef LOCAL_SDK_VERSION 293ifdef TARGET_BUILD_APPS 294# In unbundled build, merge the coverage library into the apk. 295ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) 296# Only add jacocoagent if the package contains some java code 297LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent 298# Exclude jacoco classes from proguard 299LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags 300LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags 301endif # Contains java code 302endif # TARGET_BUILD_APPS 303endif # LOCAL_SDK_VERSION 304endif # EMMA_INSTRUMENT_STATIC 305endif # LOCAL_EMMA_INSTRUMENT 306 307rs_compatibility_jni_libs := 308 309# If the module is a compressed module, we don't pre-opt it because its final 310# installation location will be the data partition. 311ifdef LOCAL_COMPRESSED_MODULE 312LOCAL_DEX_PREOPT := false 313endif 314 315# Default to use uncompressed native libraries in APKs if minSdkVersion >= marshmallow 316ifndef LOCAL_USE_EMBEDDED_NATIVE_LIBS 317 LOCAL_USE_EMBEDDED_NATIVE_LIBS := $(call math_gt_or_eq, \ 318 $(patsubst $(PLATFORM_VERSION_CODENAME),100,$(call module-min-sdk-version)),23) 319endif 320 321include $(BUILD_SYSTEM)/android_manifest.mk 322 323resource_export_package := 324 325include $(BUILD_SYSTEM)/java_renderscript.mk 326 327include $(BUILD_SYSTEM)/aapt_flags.mk 328 329ifeq ($(need_compile_res),true) 330 331############################### 332## APK splits 333built_apk_splits := 334installed_apk_splits := 335my_apk_split_configs := 336 337ifdef LOCAL_PACKAGE_SPLITS 338ifdef LOCAL_COMPRESSED_MODULE 339$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs) 340endif # LOCAL_COMPRESSED_MODULE 341 342my_apk_split_configs := $(LOCAL_PACKAGE_SPLITS) 343my_split_suffixes := $(subst $(comma),_,$(my_apk_split_configs)) 344built_apk_splits := $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk) 345endif 346 347$(R_file_stamp) $(my_res_package): PRIVATE_AAPT_FLAGS := $(filter-out --legacy,$(LOCAL_AAPT_FLAGS)) 348$(R_file_stamp) $(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS := $(TARGET_AAPT_CHARACTERISTICS) 349$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME) 350$(R_file_stamp) $(my_res_package): PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR) 351 352############################### 353## AAPT2 354 355my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res 356ifneq (,$(filter-out current,$(renderscript_target_api))) 357 ifneq ($(call math_gt_or_eq,$(renderscript_target_api),21),true) 358 my_generated_res_zips := $(rs_generated_res_zip) 359 endif # renderscript_target_api < 21 360endif # renderscript_target_api is set 361my_asset_dirs := $(LOCAL_ASSET_DIR) 362my_full_asset_paths := $(all_assets) 363 364# Add AAPT2 link specific flags. 365ifndef LOCAL_AAPT_NAMESPACES 366 $(my_res_package): PRIVATE_AAPT_FLAGS += --no-static-lib-packages 367endif 368 369include $(BUILD_SYSTEM)/aapt2.mk 370 371endif # need_compile_res 372 373my_dex_jar := $(intermediates.COMMON)/dex.jar 374 375called_from_package_internal := true 376################################# 377include $(BUILD_SYSTEM)/java.mk 378################################# 379called_from_package_internal := 380 381ifeq ($(need_compile_res),true) 382 383# Other modules should depend on the BUILT module if 384# they want to use this module's R.java file. 385$(LOCAL_BUILT_MODULE): $(R_file_stamp) 386 387ifneq ($(full_classes_jar),) 388# The R.java file must exist by the time the java source 389# list is generated 390$(java_source_list_file): $(R_file_stamp) 391endif 392 393endif # need_compile_res 394 395LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION)) 396ifeq ($(LOCAL_SDK_RES_VERSION),) 397 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION) 398endif 399 400$(LOCAL_INTERMEDIATE_TARGETS): \ 401 PRIVATE_ANDROID_MANIFEST := $(full_android_manifest) 402 403framework_res_package_export := 404 405ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 406# Most packages should link against the resources defined by framework-res. 407# Even if they don't have their own resources, they may use framework 408# resources. 409ifeq ($(LOCAL_SDK_RES_VERSION),core_current) 410# core_current doesn't contain any framework resources. 411else ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_USE_PREBUILT_SDKS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),) 412# for released sdk versions, the platform resources were built into android.jar. 413framework_res_package_export := \ 414 $(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) 415else # LOCAL_SDK_RES_VERSION 416framework_res_package_export := \ 417 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk 418endif # LOCAL_SDK_RES_VERSION 419endif # LOCAL_NO_STANDARD_LIBRARIES 420 421all_library_res_package_exports := \ 422 $(framework_res_package_export) \ 423 $(foreach lib,$(LOCAL_RES_LIBRARIES),\ 424 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/package-export.apk) 425 426all_library_res_package_export_deps := \ 427 $(framework_res_package_export) \ 428 $(foreach lib,$(LOCAL_RES_LIBRARIES),\ 429 $(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp) 430$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps) 431$(LOCAL_INTERMEDIATE_TARGETS): \ 432 PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports) 433 434$(my_res_package) : $(all_library_res_package_export_deps) 435 436ifneq ($(full_classes_jar),) 437$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) 438# Use the jarjar processed arhive as the initial package file. 439$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar) 440$(LOCAL_BUILT_MODULE): $(built_dex) $(full_classes_pre_proguard_jar) 441else 442$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := 443$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := 444endif # full_classes_jar 445 446include $(BUILD_SYSTEM)/install_jni_libs.mk 447 448# Pick a key to sign the package with. If this package hasn't specified 449# an explicit certificate, use the default. 450# Secure release builds will have their packages signed after the fact, 451# so it's ok for these private keys to be in the clear. 452ifeq ($(LOCAL_CERTIFICATE),) 453 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE) 454endif 455 456ifeq ($(LOCAL_CERTIFICATE),EXTERNAL) 457 # The special value "EXTERNAL" means that we will sign it with the 458 # default devkey, apply predexopt, but then expect the final .apk 459 # (after dexopting) to be signed by an outside tool. 460 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE) 461 PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1 462endif 463 464# If this is not an absolute certificate, assign it to a generic one. 465ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./) 466 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE) 467endif 468include $(BUILD_SYSTEM)/app_certificate_validate.mk 469private_key := $(LOCAL_CERTIFICATE).pk8 470certificate := $(LOCAL_CERTIFICATE).x509.pem 471additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8) 472 473$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR) $(SIGNAPK_JNI_LIBRARY_PATH) 474$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key) 475$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate) 476 477PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key) 478PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate) 479 480$(LOCAL_BUILT_MODULE): $(additional_certificates) 481$(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates) 482 483$(LOCAL_BUILT_MODULE): $(LOCAL_CERTIFICATE_LINEAGE) 484$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE_LINEAGE := $(LOCAL_CERTIFICATE_LINEAGE) 485 486$(LOCAL_BUILT_MODULE): PRIVATE_ROTATION_MIN_SDK_VERSION := $(LOCAL_ROTATION_MIN_SDK_VERSION) 487 488# Set a actual_partition_tag (calculated in base_rules.mk) for the package. 489PACKAGES.$(LOCAL_PACKAGE_NAME).PARTITION := $(actual_partition_tag) 490 491# Define the rule to build the actual package. 492# PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>. 493$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis) 494# PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names. 495$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis) 496ifneq ($(TARGET_BUILD_APPS),) 497 # Include all resources for unbundled apps. 498 LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true 499endif 500ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true) 501 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := 502 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 503else 504 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG) 505ifdef LOCAL_PACKAGE_SPLITS 506 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := 507else 508 $(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG) 509endif 510endif 511 512# Run veridex on product, system_ext and vendor modules. 513# We skip it for unbundled app builds where we cannot build veridex. 514module_run_appcompat := 515ifeq (true,$(non_system_module)) 516ifeq (,$(TARGET_BUILD_APPS)) # ! unbundled app build 517ifneq ($(UNSAFE_DISABLE_HIDDENAPI_FLAGS),true) 518 module_run_appcompat := true 519endif 520endif 521endif 522 523ifeq ($(module_run_appcompat),true) 524$(LOCAL_BUILT_MODULE) : $(appcompat-files) 525$(LOCAL_BUILT_MODULE): PRIVATE_INSTALLED_MODULE := $(LOCAL_INSTALLED_MODULE) 526endif 527 528$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/resources 529$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries) 530$(LOCAL_BUILT_MODULE) : $(JAR_ARGS) $(SOONG_ZIP) $(MERGE_ZIPS) $(ZIP2ZIP) 531$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package) 532$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) 533ifdef LOCAL_COMPRESSED_MODULE 534$(LOCAL_BUILT_MODULE) : $(GZIP) 535endif 536ifeq (true, $(LOCAL_UNCOMPRESS_DEX)) 537$(LOCAL_BUILT_MODULE) : $(ZIP2ZIP) 538endif 539ifeq ($(full_classes_jar),) 540 # We don't build jar, need to add the Java resources here. 541 $(LOCAL_BUILT_MODULE): $(java_resource_sources) 542endif 543$(LOCAL_BUILT_MODULE): PRIVATE_USE_EMBEDDED_NATIVE_LIBS := $(LOCAL_USE_EMBEDDED_NATIVE_LIBS) 544$(LOCAL_BUILT_MODULE): 545 @echo "target Package: $(PRIVATE_MODULE) ($@)" 546 rm -rf $@.parts 547 mkdir -p $@.parts 548 cp -f $(PRIVATE_RES_PACKAGE) $@.parts/apk.zip 549ifneq ($(jni_shared_libraries),) 550 $(call create-jni-shared-libs-package,$@.parts/jni.zip,$(PRIVATE_USE_EMBEDDED_NATIVE_LIBS)) 551endif 552ifeq ($(full_classes_jar),) 553# We don't build jar, need to add the Java resources here. 554 $(if $(PRIVATE_EXTRA_JAR_ARGS),$(call create-java-resources-jar,$@.parts/res.zip)) 555else # full_classes_jar 556 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE)) 557 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE)) 558endif # full_classes_jar 559 $(MERGE_ZIPS) $@ $@.parts/*.zip 560 rm -rf $@.parts 561ifeq (true, $(LOCAL_UNCOMPRESS_DEX)) 562 @# No need to align, sign-package below will do it. 563 $(uncompress-dexs) 564endif 565# Run appcompat before signing. 566ifeq ($(module_run_appcompat),true) 567 $(appcompat-header) 568 $(run-appcompat) 569endif # module_run_appcompat 570 $(sign-package) 571ifdef LOCAL_COMPRESSED_MODULE 572 $(compress-package) 573endif # LOCAL_COMPRESSED_MODULE 574 575my_package_res_pb := $(intermediates.COMMON)/package-res.pb.apk 576$(my_package_res_pb): $(my_res_package) $(AAPT2) 577 $(AAPT2) convert --output-format proto $< -o $@ 578 579$(my_bundle_module): $(my_package_res_pb) 580$(my_bundle_module): PRIVATE_RES_PACKAGE := $(my_package_res_pb) 581 582$(my_bundle_module): $(jni_shared_libraries) 583$(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis) 584$(my_bundle_module): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis) 585 586ifneq ($(full_classes_jar),) 587 $(my_bundle_module): PRIVATE_DEX_FILE := $(built_dex) 588 # Use the jarjar processed archive as the initial package file. 589 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar) 590 $(my_bundle_module): $(built_dex) 591else 592 $(my_bundle_module): PRIVATE_DEX_FILE := 593 $(my_bundle_module): PRIVATE_SOURCE_ARCHIVE := 594 # We don't build jar, need to add the Java resources here. 595 $(my_bundle_module): $(java_resource_sources) 596endif # full_classes_jar 597 598$(my_bundle_module): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP) 599 @echo "target Bundle: $(PRIVATE_MODULE) ($@)" 600 rm -rf $@.parts 601 mkdir -p $@.parts 602 $(ZIP2ZIP) -i $(PRIVATE_RES_PACKAGE) -o $@.parts/apk.zip AndroidManifest.xml:manifest/AndroidManifest.xml resources.pb "res/**/*" "assets/**/*" 603 ifneq ($(jni_shared_libraries),) 604 $(call create-jni-shared-libs-package,$@.parts/jni.zip) 605 endif 606 ifeq ($(full_classes_jar),) 607 # We don't build jar, need to add the Java resources here. 608 $(if $(PRIVATE_EXTRA_JAR_ARGS),\ 609 $(call create-java-resources-jar,$@.parts/res.zip) && \ 610 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/" && \ 611 mv -f $@.parts/res.zip.tmp $@.parts/res.zip) 612 else # full_classes_jar 613 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE)) 614 $(ZIP2ZIP) -i $@.parts/dex.zip -o $@.parts/dex.zip.tmp "classes*.dex:dex/" 615 mv -f $@.parts/dex.zip.tmp $@.parts/dex.zip 616 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE)) 617 $(ZIP2ZIP) -i $@.parts/res.zip -o $@.parts/res.zip.tmp "**/*:root/" 618 mv -f $@.parts/res.zip.tmp $@.parts/res.zip 619 endif # full_classes_jar 620 $(MERGE_ZIPS) $@ $@.parts/*.zip 621 rm -rf $@.parts 622ALL_MODULES.$(my_register_name).BUNDLE := $(my_bundle_module) 623 624ifdef TARGET_BUILD_APPS 625 ifdef LOCAL_DPI_VARIANTS 626 $(call pretty-error,Building DPI-specific APKs is no longer supported) 627 endif 628endif 629 630############################### 631## Rule to build a jar containing dex files to dexpreopt without waiting for 632## the APK 633ifdef LOCAL_DEX_PREOPT 634 $(my_dex_jar): PRIVATE_DEX_FILE := $(built_dex) 635 $(my_dex_jar): $(built_dex) $(SOONG_ZIP) 636 $(hide) mkdir -p $(dir $@) && rm -f $@ 637 $(call create-dex-jar,$@,$(PRIVATE_DEX_FILE)) 638endif 639 640############################### 641## APK splits 642ifdef LOCAL_PACKAGE_SPLITS 643# The splits should have been built in the same command building the base apk. 644# This rule just runs signing. 645# Note that we explicily check the existence of the split apk and remove the 646# built base apk if the split apk isn't there. 647# That way the build system will rerun the aapt after the user changes the splitting parameters. 648$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key) 649$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate) 650$(built_apk_splits) : $(intermediates)/%.apk : $(LOCAL_BUILT_MODULE) 651 $(hide) if [ ! -f $@ ]; then \ 652 echo 'No $@ generated, check your apk splitting parameters.' 1>&2; \ 653 rm $<; exit 1; \ 654 fi 655 $(sign-package) 656 657# Rules to install the splits 658installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk) 659$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(intermediates)/package_%.apk 660 @echo "Install: $@" 661 $(copy-file-to-new-target) 662 663# Register the additional built and installed files. 664ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits) 665ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \ 666 $(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk) 667 668# Make sure to install the splits when you run "make <module_name>". 669$(my_all_targets): $(installed_apk_splits) 670 671ifdef LOCAL_COMPATIBILITY_SUITE 672 673$(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ 674 $(eval my_compat_dist_$(suite) := $(foreach dir, $(call compatibility_suite_dirs,$(suite)), \ 675 $(foreach s,$(my_split_suffixes),\ 676 $(call compat-copy-pair,$(intermediates)/package_$(s).apk,$(dir)/$(LOCAL_MODULE)_$(s).apk))))) 677 678$(call create-suite-dependencies) 679 680endif # LOCAL_COMPATIBILITY_SUITE 681endif # LOCAL_PACKAGE_SPLITS 682 683# Save information about this package 684PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES)) 685PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources) 686 687ifneq ($(LOCAL_MODULE_STEM),) 688 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE_STEM) 689else 690 PACKAGES.$(LOCAL_MODULE).STEM := $(LOCAL_MODULE) 691endif 692 693PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME) 694 695# Reset internal variables. 696all_res_assets := 697 698ifneq (,$(runtime_resource_overlays_product)$(runtime_resource_overlays_vendor)) 699 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES 700 enforce_rro_use_res_lib := true 701 else 702 enforce_rro_use_res_lib := false 703 endif 704 705 ifdef LOCAL_MANIFEST_PACKAGE_NAME 706 enforce_rro_is_manifest_package_name := true 707 enforce_rro_manifest_package_info := $(LOCAL_MANIFEST_PACKAGE_NAME) 708 else 709 enforce_rro_is_manifest_package_name := false 710 enforce_rro_manifest_package_info := $(full_android_manifest) 711 endif 712 713 ifdef runtime_resource_overlays_product 714 $(call append_enforce_rro_sources, \ 715 $(my_register_name), \ 716 $(enforce_rro_is_manifest_package_name), \ 717 $(enforce_rro_manifest_package_info), \ 718 $(enforce_rro_use_res_lib), \ 719 $(runtime_resource_overlays_product), \ 720 product \ 721 ) 722 endif 723 ifdef runtime_resource_overlays_vendor 724 $(call append_enforce_rro_sources, \ 725 $(my_register_name), \ 726 $(enforce_rro_is_manifest_package_name), \ 727 $(enforce_rro_manifest_package_info), \ 728 $(enforce_rro_use_res_lib), \ 729 $(runtime_resource_overlays_vendor), \ 730 vendor \ 731 ) 732 endif 733endif 734