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