# # Copyright (C) 2008 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #
########################################################### ## Standard rules for building an application package. ## ## Additional inputs from base_rules.make: ## LOCAL_PACKAGE_NAME: The name of the package; the directory ## will be called this. ## ## MODULE, MODULE_PATH, and MODULE_SUFFIX will ## be set for you. ###########################################################
ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX) endif
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
ifneq ($(strip $(LOCAL_MODULE_STEM)$(LOCAL_BUILT_MODULE_STEM)),)
$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_STEM or LOCAL_BUILT_MODULE_STEM) endif
ifneq ($(strip $(LOCAL_MODULE)),)
$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE) endif
LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS) endif
LOCAL_MODULE_CLASS := APPS
# LOCAL_RESOURCE_DIR may point to resource generated during the build
need_compile_res := ifeq (,$(LOCAL_RESOURCE_DIR))
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res else
need_compile_res := true
LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(callclean-path,$(d))) endif
# If LOCAL_MODULE matches a rule in PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES, # override the manifest package name by the (first) rule matched
override_manifest_name := $(strip $(word 1,\
$(foreach rule,$(PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES),\
$(eval _pkg_name_pat := $(call word-colon,1,$(rule)))\
$(eval _manifest_name_pat := $(call word-colon,2,$(rule)))\
$(if $(filter $(_pkg_name_pat),$(LOCAL_MODULE)),\
$(patsubst $(_pkg_name_pat),$(_manifest_name_pat),$(LOCAL_MODULE))\
)\
)\
))
ifneq (,$(override_manifest_name)) # Note: this can override LOCAL_MANIFEST_PACKAGE_NAME value set in Android.mk
LOCAL_MANIFEST_PACKAGE_NAME := $(override_manifest_name) endif
include $(BUILD_SYSTEM)/force_aapt2.mk # validate that app contains a manifest file for aapt2 ifeq (,$(strip $(LOCAL_MANIFEST_FILE)$(LOCAL_FULL_MANIFEST_FILE))) ifeq (,$(wildcard $(LOCAL_PATH)/AndroidManifest.xml))
$(call pretty-error,App missing manifest file which is required by aapt2. \
Provide a manifest file by either setting LOCAL_MANIFEST_FILE in Android.mk \
or via a AndroidManifest.xml in this directory) endif endif
# Process Support Library dependencies. include $(BUILD_SYSTEM)/support_libraries.mk
# Determine whether auto-RRO is enabled for this package.
enforce_rro_enabled := ifeq (,$(filter tests,$(LOCAL_MODULE_TAGS))) ifneq (,$(filter *, $(PRODUCT_ENFORCE_RRO_TARGETS))) # * means all system and system_ext APKs, so enable conditionally based on module path.
# Note that base_rules.mk has not yet been included, so it's likely that only # one of LOCAL_MODULE_PATH and the LOCAL_X_MODULE flags has been set. ifeq (,$(LOCAL_MODULE_PATH))
non_rro_target_module := $(filter true,\
$(LOCAL_ODM_MODULE) \
$(LOCAL_OEM_MODULE) \
$(LOCAL_PRODUCT_MODULE) \
$(LOCAL_PROPRIETARY_MODULE) \
$(LOCAL_VENDOR_MODULE))
enforce_rro_enabled := $(if $(non_rro_target_module),,true) elseifneq ($(filter $(TARGET_OUT)/%,$(LOCAL_MODULE_PATH)),)
enforce_rro_enabled := true endif elseifneq (,$(filter $(LOCAL_PACKAGE_NAME), $(PRODUCT_ENFORCE_RRO_TARGETS)))
enforce_rro_enabled := true endif endif
# Add the static overlays. Auto-RRO is created later, as it depends on # other logic in this file.
LOCAL_RESOURCE_DIR := $(static_resource_overlays) $(LOCAL_RESOURCE_DIR)
my_res_package := # In aapt2 the last takes precedence.
my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
my_res_dir :=
my_overlay_res_dirs :=
ifneq ($(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) $(LOCAL_STATIC_JAVA_AAR_LIBRARIES)),) # If we are using static android libraries, every source file becomes an overlay. # This is to emulate old AAPT behavior which simulated library support.
my_res_dir :=
my_overlay_res_dirs := $(my_resource_dirs) else # Without static libraries, the first directory is our directory, which can then be # overlaid by the rest. (First directory in my_resource_dirs is last directory in # $(LOCAL_RESOURCE_DIR) due to it being reversed.
my_res_dir := $(firstword $(my_resource_dirs))
my_overlay_res_dirs := $(wordlist 2,999,$(my_resource_dirs)) endif
# If no assets or resources were found, clear the directory variables so # we don't try to build them. ifneq (true,$(need_compile_asset))
LOCAL_ASSET_DIR:= endif ifneq (true,$(need_compile_res))
LOCAL_RESOURCE_DIR:=
R_file_stamp := else # Make sure that R_file_stamp inherits the proper PRIVATE vars. # If R.stamp moves, be sure to update the framework makefile, # which has intimate knowledge of its location.
R_file_stamp := $(intermediates.COMMON)/src/R.stamp
LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp) endif
ifdef LOCAL_COMPRESSED_MODULE ifneq (true,$(LOCAL_COMPRESSED_MODULE))
$(call pretty-error, Unknown value for LOCAL_COMPRESSED_MODULE $(LOCAL_COMPRESSED_MODULE)) endif endif
ifeq (true,$(EMMA_INSTRUMENT))
ifndef LOCAL_EMMA_INSTRUMENT # No jacoco for test apks. ifeq (,$(LOCAL_INSTRUMENTATION_FOR))
LOCAL_EMMA_INSTRUMENT := true endif# No test apk endif# LOCAL_EMMA_INSTRUMENT is not set else
LOCAL_EMMA_INSTRUMENT := false endif# EMMA_INSTRUMENT is true
ifeq (true,$(LOCAL_EMMA_INSTRUMENT)) ifeq (true,$(EMMA_INSTRUMENT_STATIC)) ifneq ($(LOCAL_SRC_FILES)$(LOCAL_SRCJARS)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) # Only add jacocoagent if the package contains some java code
LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent # Exclude jacoco classes from proguard
LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags endif# Contains java code else
ifdef LOCAL_SDK_VERSION
ifdef TARGET_BUILD_APPS # In unbundled build, merge the coverage library into the apk. ifneq ($(LOCAL_SRC_FILES)$(LOCAL_STATIC_JAVA_LIBRARIES)$(LOCAL_SOURCE_FILES_ALL_GENERATED),) # Only add jacocoagent if the package contains some java code
LOCAL_STATIC_JAVA_LIBRARIES += jacocoagent # Exclude jacoco classes from proguard
LOCAL_PROGUARD_FLAGS += -include $(BUILD_SYSTEM)/proguard.jacoco.flags
LOCAL_PROGUARD_FLAGS_DEPS += $(BUILD_SYSTEM)/proguard.jacoco.flags endif# Contains java code endif# TARGET_BUILD_APPS endif# LOCAL_SDK_VERSION endif# EMMA_INSTRUMENT_STATIC endif# LOCAL_EMMA_INSTRUMENT
rs_compatibility_jni_libs :=
# If the module is a compressed module, we don't pre-opt it because its final # installation location will be the data partition.
ifdef LOCAL_COMPRESSED_MODULE
LOCAL_DEX_PREOPT := false endif
# Default to use uncompressed native libraries in APKs if minSdkVersion >= marshmallow
ifndef LOCAL_USE_EMBEDDED_NATIVE_LIBS
LOCAL_USE_EMBEDDED_NATIVE_LIBS := $(call math_gt_or_eq, \
$(patsubst $(PLATFORM_VERSION_CODENAME),100,$(call module-min-sdk-version)),23) endif
ifdef LOCAL_PACKAGE_SPLITS
ifdef LOCAL_COMPRESSED_MODULE
$(error $(LOCAL_MODULE): LOCAL_COMPRESSED_MODULE is not currently supported for split installs) endif# LOCAL_COMPRESSED_MODULE
# Add AAPT2 link specific flags.
ifndef LOCAL_AAPT_NAMESPACES
$(my_res_package): PRIVATE_AAPT_FLAGS += --no-static-lib-packages endif
include $(BUILD_SYSTEM)/aapt2.mk
endif# need_compile_res
my_dex_jar := $(intermediates.COMMON)/dex.jar
called_from_package_internal := true ################################# include $(BUILD_SYSTEM)/java.mk #################################
called_from_package_internal :=
ifeq ($(need_compile_res),true)
# Other modules should depend on the BUILT module if # they want to use this module's R.java file.
$(LOCAL_BUILT_MODULE): $(R_file_stamp)
ifneq ($(full_classes_jar),) # The R.java file must exist by the time the java source # list is generated
$(java_source_list_file): $(R_file_stamp) endif
ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) # Most packages should link against the resources defined by framework-res. # Even if they don't have their own resources, they may use framework # resources. ifeq ($(LOCAL_SDK_RES_VERSION),core_current) # core_current doesn't contain any framework resources. elseifneq ($(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))),) # for released sdk versions, the platform resources were built into android.jar.
framework_res_package_export := \
$(call resolve-prebuilt-sdk-jar-path,$(LOCAL_SDK_RES_VERSION)) else# LOCAL_SDK_RES_VERSION
framework_res_package_export := \
$(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk endif# LOCAL_SDK_RES_VERSION endif# LOCAL_NO_STANDARD_LIBRARIES
ifneq ($(full_classes_jar),)
$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) # Use the jarjar processed arhive as the initial package file.
$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_pre_proguard_jar)
$(LOCAL_BUILT_MODULE): $(built_dex) $(full_classes_pre_proguard_jar) else
$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE :=
$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := endif# full_classes_jar
include $(BUILD_SYSTEM)/install_jni_libs.mk
# Pick a key to sign the package with. If this package hasn't specified # an explicit certificate, use the default. # Secure release builds will have their packages signed after the fact, # so it's ok for these private keys to be in the clear. ifeq ($(LOCAL_CERTIFICATE),)
LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE) endif
ifeq ($(LOCAL_CERTIFICATE),EXTERNAL) # The special value "EXTERNAL" means that we will sign it with the # default devkey, apply predexopt, but then expect the final .apk # (after dexopting) to be signed by an outside tool.
LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1 endif
# If this is not an absolute certificate, assign it to a generic one. ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE) endif include $(BUILD_SYSTEM)/app_certificate_validate.mk
private_key := $(LOCAL_CERTIFICATE).pk8
certificate := $(LOCAL_CERTIFICATE).x509.pem
additional_certificates := $(foreach c,$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
# Set a actual_partition_tag (calculated in base_rules.mk) for the package.
PACKAGES.$(LOCAL_PACKAGE_NAME).PARTITION := $(actual_partition_tag)
# Define the rule to build the actual package. # PRIVATE_JNI_SHARED_LIBRARIES is a list of <abi>:<path_of_built_lib>.
$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis) # PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis) ifneq ($(TARGET_BUILD_APPS),) # Include all resources for unbundled apps.
LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true endif ifeq ($(LOCAL_AAPT_INCLUDE_ALL_RESOURCES),true)
$(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG :=
$(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := else
$(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_CONFIG := $(PRODUCT_AAPT_CONFIG)
ifdef LOCAL_PACKAGE_SPLITS
$(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := else
$(my_res_package) $(LOCAL_BUILT_MODULE): PRIVATE_PRODUCT_AAPT_PREF_CONFIG := $(PRODUCT_AAPT_PREF_CONFIG) endif endif
$(LOCAL_BUILT_MODULE): PRIVATE_RESOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/resources
$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
$(LOCAL_BUILT_MODULE) : $(JAR_ARGS) $(SOONG_ZIP) $(MERGE_ZIPS) $(ZIP2ZIP)
$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2)
ifdef LOCAL_COMPRESSED_MODULE
$(LOCAL_BUILT_MODULE) : $(GZIP) endif ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
$(LOCAL_BUILT_MODULE) : $(ZIP2ZIP) endif ifeq ($(full_classes_jar),) # We don't build jar, need to add the Java resources here.
$(LOCAL_BUILT_MODULE): $(java_resource_sources) endif
$(LOCAL_BUILT_MODULE): PRIVATE_USE_EMBEDDED_NATIVE_LIBS := $(LOCAL_USE_EMBEDDED_NATIVE_LIBS)
$(LOCAL_BUILT_MODULE):
@echo"target Package: $(PRIVATE_MODULE) ($@)" rm -rf $@.parts
mkdir -p $@.parts cp -f $(PRIVATE_RES_PACKAGE) $@.parts/apk.zip ifneq ($(jni_shared_libraries),)
$(call create-jni-shared-libs-package,$@.parts/jni.zip,$(PRIVATE_USE_EMBEDDED_NATIVE_LIBS)) endif ifeq ($(full_classes_jar),) # We don't build jar, need to add the Java resources here.
$(if $(PRIVATE_EXTRA_JAR_ARGS),$(call create-java-resources-jar,$@.parts/res.zip)) else# full_classes_jar
$(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
$(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE)) endif# full_classes_jar
$(MERGE_ZIPS) $@ $@.parts/*.zip rm -rf $@.parts ifeq (true, $(LOCAL_UNCOMPRESS_DEX))
@# No need to align, sign-package below will do it.
$(uncompress-dexs) endif
$(sign-package)
ifdef LOCAL_COMPRESSED_MODULE
$(compress-package) endif# LOCAL_COMPRESSED_MODULE
ifdef TARGET_BUILD_APPS
ifdef LOCAL_DPI_VARIANTS
$(call pretty-error,Building DPI-specific APKs is no longer supported) endif endif
############################### ## Rule to build a jar containing dex files to dexpreopt without waiting for ## the APK
ifdef LOCAL_DEX_PREOPT
$(my_dex_jar): PRIVATE_DEX_FILE := $(built_dex)
$(my_dex_jar): $(built_dex) $(SOONG_ZIP)
$(hide) mkdir -p $(dir $@) && rm -f $@
$(call create-dex-jar,$@,$(PRIVATE_DEX_FILE)) endif
############################### ## APK splits
ifdef LOCAL_PACKAGE_SPLITS # The splits should have been built in the same command building the base apk. # This rule just runs signing. # Note that we explicily check the existence of the split apk and remove the # built base apk if the split apk isn't there. # That way the build system will rerun the aapt after the user changes the splitting parameters.
$(built_apk_splits): PRIVATE_PRIVATE_KEY := $(private_key)
$(built_apk_splits): PRIVATE_CERTIFICATE := $(certificate)
$(built_apk_splits) : $(intermediates)/%.apk : $(LOCAL_BUILT_MODULE)
$(hide) if [ ! -f $@ ]; then \ echo'No $@ generated, check your apk splitting parameters.'1>&2; \ rm $<; exit 1; \ fi
$(sign-package)
# Rules to install the splits
installed_apk_splits := $(foreach s,$(my_split_suffixes),$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
$(installed_apk_splits) : $(my_module_path)/$(LOCAL_MODULE)_%.apk : $(intermediates)/package_%.apk
@echo"Install: $@"
$(copy-file-to-new-target)
# Register the additional built and installed files.
ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
$(foreach s,$(my_split_suffixes),$(intermediates)/package_$(s).apk:$(my_module_path)/$(LOCAL_MODULE)_$(s).apk)
# Make sure to install the splits when you run "make <module_name>".
$(my_all_targets): $(installed_apk_splits)
# Save information about this package
PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.