Support to build with AAPT2

To build with AAPT2, set "USE_AAPT2=true".
TODO: Support split apks and generated resources from other than renderscript.

Bug: 25958912
Change-Id: I19b1a038824ce5b2a3d3ffadbce3173c845193fc
This commit is contained in:
Ying Wang 2015-12-04 13:59:18 -08:00 committed by Adam Lesinski
parent b7a9e8ed90
commit dd71c85a45
8 changed files with 299 additions and 43 deletions

76
core/aapt2.mk Normal file
View File

@ -0,0 +1,76 @@
######################################
# Compile resource with AAPT2
# Input variables:
# full_android_manifest,
# my_res_resources, my_overlay_resources, my_aapt_characteristics,
# my_compiled_res_base_dir, rs_generated_res_dir, my_res_package,
# R_file_stamp, proguard_options_file
# Output variables:
# my_res_resources_flat, my_overlay_resources_flat,
# my_generated_resources_flata
#
######################################
# Compile all the resource files.
my_res_resources_flat := \
$(foreach r, $(my_res_resources),\
$(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\
$(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\
$(o))
my_overlay_resources_flat := \
$(foreach r, $(my_overlay_resources),\
$(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\
$(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\
$(o))
my_generated_resources_flata :=
# Compile generated resources
ifneq ($(rs_generated_res_dir),)
rs_gen_resource_flata := $(my_compiled_res_base_dir)/renderscript_gen_res.flata
$(rs_gen_resource_flata): PRIVATE_SOURCE_RES_DIR := $(rs_generated_res_dir)
$(rs_gen_resource_flata) : $(RenderScript_file_stamp)
@echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_DIR)"
$(call aapt2-compile-one-resource-dir)
my_generated_resources_flata += $(rs_gen_resource_flata)
endif
$(my_res_resources_flat) $(my_overlay_resources_flat) $(my_generated_resources_flata): \
PRIVATE_AAPT2_CFLAGS := $(addprefix --product ,$(my_aapt_characteristics))
# Link the static library resource packages.
my_static_library_resources := $(foreach l, $(LOCAL_STATIC_JAVA_LIBRARIES),\
$(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/library-res.flata)
$(my_res_package): PRIVATE_RES_FLAT := $(my_res_resources_flat)
$(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_overlay_resources_flat) $(my_generated_resources_flata) $(my_static_library_resources)
$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
$(my_res_package) : $(full_android_manifest)
$(my_res_package) : $(my_res_resources_flat) $(my_overlay_resources_flat) \
$(my_generated_resources_flata) $(my_static_library_resources) \
$(AAPT2)
@echo "AAPT2 link $@"
$(call aapt2-link)
$(R_file_stamp) : $(my_res_package) | $(ACP)
@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
@rm -rf $@ && mkdir -p $(dir $@)
$(call find-generated-R.java)
$(proguard_options_file) : $(my_res_package)
resource_export_package :=
ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
# Put this module's resources into a PRODUCT-agnositc package that
# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
# files.
resource_export_package := $(intermediates.COMMON)/package-export.apk
$(R_file_stamp) : $(resource_export_package)
$(resource_export_package) : $(my_res_package) | $(ACP)
@echo "target Export Resources: $(PRIVATE_MODULE) $(@)"
$(copy-file-to-new-target)
endif

View File

@ -22,9 +22,12 @@ my_full_libs_manifest_deps += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),
my_full_libs_manifest_files += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/aar/AndroidManifest.xml)
# With USE_AAPT2, we'll link in the built resource from the AAR.
ifndef USE_AAPT2
LOCAL_RESOURCE_DIR += $(foreach lib, $(LOCAL_STATIC_JAVA_AAR_LIBRARIES),\
$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/aar/res)
endif
endif # USE_AAPT2
endif # LOCAL_STATIC_JAVA_AAR_LIBRARIES
# Set up rules to merge library manifest files
ifdef my_full_libs_manifest_files

View File

@ -403,6 +403,7 @@ endif
ACP := $(HOST_OUT_EXECUTABLES)/acp
AIDL := $(HOST_OUT_EXECUTABLES)/aidl
AAPT := $(HOST_OUT_EXECUTABLES)/aapt
AAPT2 := $(HOST_OUT_EXECUTABLES)/aapt2
ZIPALIGN := $(HOST_OUT_EXECUTABLES)/zipalign
SIGNAPK_JAR := $(HOST_OUT_JAVA_LIBRARIES)/signapk$(COMMON_JAVA_PACKAGE_SUFFIX)
SIGNAPK_JNI_LIBRARY_PATH := $(HOST_OUT_SHARED_LIBRARIES)
@ -422,6 +423,7 @@ prebuilt_sdk_tools_bin := $(prebuilt_sdk_tools)/$(HOST_OS)/bin
ACP := $(prebuilt_sdk_tools_bin)/acp
AIDL := $(prebuilt_sdk_tools_bin)/aidl
AAPT := $(prebuilt_sdk_tools_bin)/aapt
AAPT2 := $(prebuilt_sdk_tools_bin)/aapt2
ZIPALIGN := $(prebuilt_sdk_tools_bin)/zipalign
SIGNAPK_JAR := $(prebuilt_sdk_tools)/lib/signapk$(COMMON_JAVA_PACKAGE_SUFFIX)
# Use 64-bit libraries unconditionally because 32-bit JVMs are no longer supported

View File

@ -1726,6 +1726,78 @@ $(hide) $(AAPT) package $(PRIVATE_AAPT_FLAGS) -m \
--skip-symbols-without-default-localization
endef
# Search for generated R.java/Manifest.java, copy the found R.java as $@.
# Also copy them to a central 'R' directory to make it easier to add the files to an IDE.
define find-generated-R.java
$(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
-name Manifest.java 2> /dev/null`; do \
dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
$(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
done;
$(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
-name R.java 2> /dev/null`; do \
dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
$(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
|| exit 31; \
$(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \
done;
@# Ensure that the target file is always created, i.e. also in case we did not
@# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding.
$(hide) touch $@
endef
###########################################################
# AAPT2 compilation and link
###########################################################
define aapt2-compile-one-resource-file
@mkdir -p $(dir $@)
$(hide) $(AAPT2) compile -o $(dir $@) $(PRIVATE_AAPT2_CFLAGS) --legacy $<
endef
define aapt2-compile-one-resource-dir
@mkdir -p $(dir $@)
$(hide) $(AAPT2) compile -o $@ --dir $(PRIVATE_SOURCE_RES_DIR) \
$(PRIVATE_AAPT2_CFLAGS) --legacy
endef
# Set up rule to compile one resource file with aapt2.
# Must be called with $(eval).
# $(1): the source file
# $(2): the output file
define aapt2-compile-one-resource-file-rule
$(2) : $(1) $(AAPT2)
@echo "AAPT2 compile $$@ <- $$<"
$$(call aapt2-compile-one-resource-file)
endef
# Convert input resource file path to output file path.
# values-[config]/<file>.xml -> values-[config]_<file>.arsc.flat;
# For other resource file, just replace the last "/" with "_" and
# add .flat extension.
#
# $(1): the input resource file path
# $(2): the base dir of the output file path
# Returns: the compiled output file path
define aapt2-compiled-resource-out-file
$(eval _p_w := $(strip $(subst /,$(space),$(dir $(1)))))$(2)/$(subst $(space),/,$(_p_w))_$(if $(filter values%,$(lastword $(_p_w))),$(patsubst %.xml,%.arsc,$(notdir $(1))),$(notdir $(1))).flat
endef
define aapt2-link
$(hide) $(AAPT2) link -o $@ \
$(PRIVATE_AAPT_FLAGS) \
$(addprefix --manifest ,$(PRIVATE_ANDROID_MANIFEST)) \
$(addprefix -I ,$(PRIVATE_AAPT_INCLUDES)) \
$(addprefix --java ,$(PRIVATE_SOURCE_INTERMEDIATES_DIR)) \
$(addprefix --proguard ,$(PRIVATE_PROGUARD_OPTIONS_FILE)) \
$(addprefix --min-sdk-version ,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
$(addprefix --target-sdk-version ,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
$(addprefix -R , $(PRIVATE_OVERLAY_FLAT)) \
$(PRIVATE_RES_FLAT)
endef
###########################################################
xlint_unchecked := -Xlint:unchecked
# emit-line, <word list>, <output file>

View File

@ -145,6 +145,7 @@ renderscript_sources := $(filter %.rs %.fs,$(LOCAL_SRC_FILES))
# Because names of the java files from RenderScript are unknown until the
# .rs file(s) are compiled, we have to depend on a timestamp file.
RenderScript_file_stamp :=
rs_generated_res_dir :=
rs_compatibility_jni_libs :=
ifneq ($(renderscript_sources),)
renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources))
@ -277,7 +278,8 @@ endif
LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp)
# Make sure the generated resource will be added to the apk.
LOCAL_RESOURCE_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript/res $(LOCAL_RESOURCE_DIR)
rs_generated_res_dir := $(renderscript_intermediate.COMMON)/res
LOCAL_RESOURCE_DIR := $(rs_generated_res_dir) $(LOCAL_RESOURCE_DIR)
endif

View File

@ -57,6 +57,9 @@ $(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
endif
LOCAL_MODULE_CLASS := APPS
intermediates := $(call local-intermediates-dir)
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
#################################
include $(BUILD_SYSTEM)/configure_local_jack.mk
#################################
@ -112,6 +115,32 @@ ifneq ($(all_assets),)
need_compile_asset := true
endif
ifdef USE_AAPT2
# In aapt2 the last takes precedence.
my_resource_dirs := $(call reverse-list,$(LOCAL_RESOURCE_DIR))
my_res_resources :=
my_overlay_resources :=
# Treat all but the first directory as overlays.
my_overlay_resources := $(strip \
$(foreach d,$(wordlist 2,999,$(my_resource_dirs)),\
$(addprefix $(d)/, \
$(call find-subdir-assets,$(d)))))
my_res_dir := $(firstword $(my_resource_dirs))
my_res_resources := $(strip \
$(addprefix $(my_res_dir)/, \
$(call find-subdir-assets,$(my_res_dir))))
all_resources := $(strip $(my_res_resources) $(my_overlay_resources))
# The linked resource package.
my_res_package := $(intermediates)/package-res.apk
LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
# Always run aapt2
need_compile_res := true
else # USE_AAPT2
all_resources := $(strip \
$(foreach dir, $(LOCAL_RESOURCE_DIR), \
$(addprefix $(dir)/, \
@ -121,13 +150,14 @@ all_resources := $(strip \
) \
))
endif # USE_AAPT2
ifneq ($(all_resources),)
need_compile_res := true
endif
all_res_assets := $(strip $(all_assets) $(all_resources))
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
# If no assets or resources were found, clear the directory variables so
# we don't try to build them.
@ -272,6 +302,11 @@ $(built_dex_intermediate) : $(data_binding_stamp)
endif # LOCAL_DATA_BINDING
ifeq ($(need_compile_res),true)
ifdef USE_AAPT2
my_aapt_characteristics := $(TARGET_AAPT_CHARACTERISTICS)
my_compiled_res_base_dir := $(intermediates)/flat-res
include $(BUILD_SYSTEM)/aapt2.mk
else # USE_AAPT2
# Since we don't know where the real R.java file is going to end up,
# we need to use another file to stand in its place. We'll just
@ -289,23 +324,7 @@ $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(RenderScript_file_
@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
@rm -rf $@ && mkdir -p $(dir $@)
$(create-resource-java-files)
$(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
-name Manifest.java 2> /dev/null`; do \
dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_MANIFEST_FILE`; \
mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
$(ACP) -fp $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
done;
$(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
-name R.java 2> /dev/null`; do \
dir=`awk '/package/{gsub(/\./,"/",$$2);gsub(/;/,"",$$2);print $$2;exit}' $$GENERATED_R_FILE`; \
mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
$(ACP) -fp $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
|| exit 31; \
$(ACP) -fp $$GENERATED_R_FILE $@ || exit 32; \
done;
@# Ensure that the target file is always created, i.e. also in case we did not
@# enter the GENERATED_R_FILE-loop above. This avoids unnecessary rebuilding.
$(hide) touch $@
$(call find-generated-R.java)
$(proguard_options_file): $(R_file_stamp)
@ -327,6 +346,8 @@ $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(RenderS
$(add-assets-to-package)
endif
endif # USE_AAPT2
# 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)
@ -384,10 +405,13 @@ all_library_res_package_export_deps := \
$(framework_res_package_export_deps) \
$(foreach lib,$(LOCAL_RES_LIBRARIES),\
$(call intermediates-dir-for,APPS,$(lib),,COMMON)/src/R.stamp)
$(resource_export_package) $(R_file_stamp) $(LOCAL_BUILT_MODULE): $(all_library_res_package_export_deps)
$(LOCAL_INTERMEDIATE_TARGETS): \
PRIVATE_AAPT_INCLUDES := $(all_library_res_package_exports)
ifdef USE_AAPT2
$(my_res_package) : $(all_library_res_package_export_deps)
endif
endif # LOCAL_NO_STANDARD_LIBRARIES
ifneq ($(full_classes_jar),)
@ -436,7 +460,6 @@ $(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(foreach c,\
$(LOCAL_ADDITIONAL_CERTIFICATES), $(c).x509.pem $(c).pk8)
# Define the rule to build the actual package.
$(LOCAL_BUILT_MODULE): $(AAPT)
# 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.
@ -457,8 +480,24 @@ else
endif
endif
$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS)
$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
$(LOCAL_BUILT_MODULE) : $(jni_shared_libraries)
ifdef USE_AAPT2
$(LOCAL_BUILT_MODULE): PRIVATE_RES_PACKAGE := $(my_res_package)
$(LOCAL_BUILT_MODULE) : $(my_res_package) $(AAPT2) | $(ACP)
else
$(LOCAL_BUILT_MODULE) : $(all_res_assets) $(full_android_manifest) $(AAPT)
endif
@echo "target Package: $(PRIVATE_MODULE) ($@)"
ifdef USE_AAPT2
ifdef LOCAL_JACK_ENABLED
$(call copy-file-to-new-target)
else
@# TODO: implement merge-two-packages.
$(if $(PRIVATE_SOURCE_ARCHIVE),\
$(call merge-two-packages,$(PRIVATE_RES_PACKAGE) $(PRIVATE_SOURCE_ARCHIVE),$@),
$(call copy-file-to-new-target))
endif
else # USE_AAPT2
ifdef LOCAL_JACK_ENABLED
$(create-empty-package)
else
@ -467,6 +506,7 @@ else
$(create-empty-package))
endif
$(add-assets-to-package)
endif # USE_AAPT2
ifneq ($(jni_shared_libraries),)
$(add-jni-shared-libs-to-package)
endif

View File

@ -296,11 +296,12 @@ common_javalib_jar := $(intermediates.COMMON)/javalib.jar
$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
ifneq ($(filter %.aar, $(my_prebuilt_src_file)),)
my_src_aar := $(filter %.aar, $(my_prebuilt_src_file))
ifneq ($(my_src_aar),)
# This is .aar file, archive of classes.jar and Android resources.
my_src_jar := $(intermediates.COMMON)/aar/classes.jar
$(my_src_jar) : $(my_prebuilt_src_file)
$(my_src_jar) : $(my_src_aar)
$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
$(hide) unzip -qo -d $(dir $@) $<
# Make sure the extracted classes.jar has a new timestamp.
@ -318,6 +319,26 @@ $(common_javalib_jar) : $(common_classes_jar) | $(ACP)
$(call define-jar-to-toc-rule, $(common_classes_jar))
ifdef USE_AAPT2
my_library_resources := $(intermediates.COMMON)/library-res.flata
ifneq ($(my_src_aar),)
# Compile the AAR resources to a .flata.
$(my_library_resources): PRIVATE_SOURCE_RES_DIR := $(intermediates.COMMON)/aar/res
$(my_library_resources) : $(my_src_jar)
@echo "AAPT2 compile AAR $@ <- $(PRIVATE_SOURCE_RES_DIR)"
$(call aapt2-compile-one-resource-dir)
else # $(my_src_aar)
# Create an empty packag for prebuilt static Java library.
# TODO: support compiled resources inside a prebuilt static Java library.
$(my_library_resources): PRIVATE_RES_DIR := $(intermediates.COMMON)/flat-res/res
$(my_library_resources) :
@echo "Create empty library resources $@"
@rm -rf $@ && mkdir -p $(dir $@) $(PRIVATE_RES_DIR)
$(hide) cd $(dir $(PRIVATE_RES_DIR)) && zip -qrX $(abspath $@) $(notdir $(PRIVATE_RES_DIR))
endif # $(my_src_aar)
# Make sure my_library_resources is created when you run mm/mmm.
$(built_module) : $(my_library_resources)
endif # USE_AAPT2
# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
$(built_module) : $(common_javalib_jar)
endif # TARGET JAVA_LIBRARIES

View File

@ -27,6 +27,13 @@ LOCAL_MODULE_CLASS := JAVA_LIBRARIES
include $(BUILD_SYSTEM)/configure_local_jack.mk
#################################
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
my_res_package :=
# A zip file that apps can link with aapt2
# We need my_library_resources as dependency even if a library doesn't have resource.
my_library_resources := $(intermediates.COMMON)/library-res.flata
# Hack to build static Java library with Android resource
# See bug 5714516
all_resources :=
@ -34,6 +41,7 @@ need_compile_res :=
# A static Java library needs to explicily set LOCAL_RESOURCE_DIR.
ifdef LOCAL_RESOURCE_DIR
need_compile_res := true
all_resources := $(strip \
$(foreach dir, $(LOCAL_RESOURCE_DIR), \
$(addprefix $(dir)/, \
@ -56,7 +64,6 @@ endif
proguard_options_file :=
intermediates.COMMON := $(call local-intermediates-dir,COMMON)
ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
proguard_options_file := $(intermediates.COMMON)/proguard_options
endif
@ -70,6 +77,18 @@ endif
LOCAL_JACK_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_JACK_PROGUARD_FLAGS)
endif # LOCAL_JACK_ENABLED
R_file_stamp := $(intermediates.COMMON)/src/R.stamp
LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
ifdef USE_AAPT2
# For library we treat all the resource equal with no overlay.
my_res_resources := $(all_resources)
my_overlay_resources :=
# For libraries put everything in the COMMON intermediate directory.
my_res_package := $(intermediates.COMMON)/package-res.apk
LOCAL_INTERMEDIATE_TARGETS += $(my_res_package)
endif # USE_AAPT2
endif # LOCAL_RESOURCE_DIR
all_res_assets := $(all_resources)
@ -77,8 +96,6 @@ all_res_assets := $(all_resources)
include $(BUILD_SYSTEM)/java_library.mk
ifeq (true,$(need_compile_res))
R_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/R.stamp
include $(BUILD_SYSTEM)/android_manifest.mk
LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
@ -102,29 +119,41 @@ framework_res_package_export_deps := \
endif
endif
$(R_file_stamp): PRIVATE_MODULE := $(LOCAL_MODULE)
# add --non-constant-id to prevent inlining constants.
# AAR needs text symbol file R.txt.
$(R_file_stamp): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR)
$(R_file_stamp): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
$(R_file_stamp): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
$(R_file_stamp): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
$(R_file_stamp): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
$(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
ifdef USE_AAPT2
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-final-ids
else
$(R_file_stamp): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) --non-constant-id --output-text-symbols $(LOCAL_INTERMEDIATE_SOURCE_DIR)
endif
$(R_file_stamp): PRIVATE_ASSET_DIR :=
$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
$(R_file_stamp): PRIVATE_MANIFEST_PACKAGE_NAME :=
$(R_file_stamp): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_PUBLICS_OUTPUT := $(intermediates.COMMON)/public_resources.xml
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION)))
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION)
else
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK)
endif
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_PACKAGE_NAME :=
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MANIFEST_INSTRUMENTATION_FOR :=
ifdef USE_AAPT2
# For libraries don't use any product specific flags.
my_aapt_characteristics :=
# One more level with name res so we can zip up the flat resources that can be linked by apps.
my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res/res
include $(BUILD_SYSTEM)/aapt2.mk
$(my_res_package) : $(framework_res_package_export_deps)
else
$(R_file_stamp) : $(all_resources) $(full_android_manifest) $(AAPT) $(framework_res_package_export_deps)
@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
$(create-resource-java-files)
$(hide) find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name R.java | xargs cat > $@
endif # USE_AAPT2
$(LOCAL_BUILT_MODULE): $(R_file_stamp)
ifdef LOCAL_JACK_ENABLED
@ -153,9 +182,20 @@ $(built_aar) : $(LOCAL_BUILT_MODULE)
# Register the aar file.
ALL_MODULES.$(LOCAL_MODULE).AAR := $(built_aar)
endif # need_compile_res
ifdef USE_AAPT2
# If a static Java library has no resources, create empty package apps can depend on.
$(my_library_resources): PRIVATE_RES_DIR := $(intermediates.COMMON)/flat-res/res
$(my_library_resources) : $(my_res_package)
@echo "Package static library resources $@"
@rm -rf $@ && mkdir -p $(dir $@) $(PRIVATE_RES_DIR)
$(hide) cd $(dir $(PRIVATE_RES_DIR)) && zip -qrX $(abspath $@) $(notdir $(PRIVATE_RES_DIR))
# Make sure my_library_resources is created when you run mm/mmm.
$(LOCAL_BUILT_MODULE) : $(my_library_resources)
endif # USE_AAPT2
# Reset internal variables.
all_res_assets :=
LOCAL_IS_STATIC_JAVA_LIBRARY :=