Home | History | Annotate | Download | only in core
      1 ######################################
      2 # Compile resource with AAPT2
      3 # Input variables:
      4 # - full_android_manifest
      5 # - my_res_resources
      6 # - my_overlay_resources
      7 # - my_compiled_res_base_dir
      8 # - my_asset_dirs
      9 # - my_full_asset_paths
     10 # - my_res_package
     11 # - R_file_stamp
     12 # - proguard_options_file
     13 # - my_generated_res_dirs: Resources generated during the build process and we have to compile them in a single run of aapt2.
     14 # - my_generated_res_dirs_deps: the dependency to use for my_generated_res_dirs.
     15 # - my_apk_split_configs: The configurations for which to generate splits.
     16 # - built_apk_splits: The paths where AAPT should generate the splits.
     17 #
     18 # Output variables:
     19 # - my_res_resources_flat
     20 # - my_overlay_resources_flat
     21 # - my_generated_resources_flata
     22 #
     23 ######################################
     24 
     25 # Compile all the resource files.
     26 my_res_resources_flat := \
     27   $(foreach r, $(my_res_resources),\
     28     $(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\
     29     $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\
     30     $(o))
     31 
     32 my_overlay_resources_flat := \
     33   $(foreach r, $(my_overlay_resources),\
     34     $(eval o := $(call aapt2-compiled-resource-out-file,$(r),$(my_compiled_res_base_dir)))\
     35     $(eval $(call aapt2-compile-one-resource-file-rule,$(r),$(o)))\
     36     $(o))
     37 
     38 my_generated_resources_flata :=
     39 # Compile generated resources
     40 ifneq ($(my_generated_res_dirs),)
     41 my_generated_resources_flata := $(my_compiled_res_base_dir)/gen_res.flata
     42 $(my_generated_resources_flata): PRIVATE_SOURCE_RES_DIRS := $(my_generated_res_dirs)
     43 $(my_generated_resources_flata) : $(my_generated_res_dirs_deps)
     44 	@echo "AAPT2 compile $@ <- $(PRIVATE_SOURCE_RES_DIRS)"
     45 	$(call aapt2-compile-resource-dirs)
     46 
     47 my_generated_resources_flata += $(my_generated_resources_flata)
     48 endif
     49 
     50 $(my_res_resources_flat) $(my_overlay_resources_flat) $(my_generated_resources_flata): \
     51   PRIVATE_AAPT2_CFLAGS := $(PRODUCT_AAPT2_CFLAGS)
     52 
     53 my_static_library_resources := $(foreach l, $(call reverse-list,$(LOCAL_STATIC_ANDROID_LIBRARIES)),\
     54   $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk)
     55 my_shared_library_resources := $(foreach l, $(LOCAL_SHARED_ANDROID_LIBRARIES),\
     56   $(call intermediates-dir-for,JAVA_LIBRARIES,$(l),,COMMON)/package-res.apk)
     57 
     58 ifneq ($(my_static_library_resources),)
     59 $(my_res_package): PRIVATE_AAPT_FLAGS += --auto-add-overlay
     60 endif
     61 
     62 ifneq ($(my_apk_split_configs),)
     63 # Join the Split APK paths with their configuration, separated by a ':'.
     64 $(my_res_package): PRIVATE_AAPT_FLAGS += $(addprefix --split ,$(join $(built_apk_splits),$(addprefix :,$(my_apk_split_configs))))
     65 endif
     66 
     67 $(my_res_package): PRIVATE_RES_FLAT := $(my_res_resources_flat)
     68 $(my_res_package): PRIVATE_OVERLAY_FLAT := $(my_static_library_resources) $(my_generated_resources_flata) $(my_overlay_resources_flat)
     69 $(my_res_package): PRIVATE_SHARED_ANDROID_LIBRARIES := $(my_shared_library_resources)
     70 $(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
     71 $(my_res_package): PRIVATE_ASSET_DIRS := $(my_asset_dirs)
     72 $(my_res_package): $(full_android_manifest) $(my_static_library_resources) $(my_shared_library_resources)
     73 $(my_res_package): $(my_full_asset_paths)
     74 $(my_res_package): $(my_res_resources_flat) $(my_overlay_resources_flat) \
     75   $(my_generated_resources_flata) $(my_static_library_resources) \
     76   $(AAPT2)
     77 	@echo "AAPT2 link $@"
     78 	$(call aapt2-link)
     79 
     80 ifdef R_file_stamp
     81 $(R_file_stamp) : $(my_res_package) | $(ACP)
     82 	@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
     83 	@rm -rf $@ && mkdir -p $(dir $@)
     84 	$(call find-generated-R.java)
     85 endif
     86 
     87 ifdef proguard_options_file
     88 $(proguard_options_file) : $(my_res_package)
     89 endif
     90 
     91 resource_export_package :=
     92 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
     93 # Put this module's resources into a PRODUCT-agnositc package that
     94 # other packages can use to build their own PRODUCT-agnostic R.java (etc.)
     95 # files.
     96 resource_export_package := $(intermediates.COMMON)/package-export.apk
     97 $(R_file_stamp) : $(resource_export_package)
     98 
     99 $(resource_export_package) : $(my_res_package) | $(ACP)
    100 	@echo "target Export Resources: $(PRIVATE_MODULE) $(@)"
    101 	$(copy-file-to-new-target)
    102 
    103 endif
    104