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