1#################################### 2# dexpreopt support - typically used on user builds to run dexopt (for Dalvik) or dex2oat (for ART) ahead of time 3# 4#################################### 5 6# list of boot classpath jars for dexpreopt 7DEXPREOPT_BOOT_JARS := $(subst $(space),:,$(PRODUCT_BOOT_JARS)) 8DEXPREOPT_BOOT_JARS_MODULES := $(PRODUCT_BOOT_JARS) 9PRODUCT_BOOTCLASSPATH := $(subst $(space),:,$(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),/system/framework/$(m).jar)) 10 11PRODUCT_SYSTEM_SERVER_CLASSPATH := $(subst $(space),:,$(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),/system/framework/$(m).jar)) 12 13DEXPREOPT_BUILD_DIR := $(OUT_DIR) 14DEXPREOPT_PRODUCT_DIR_FULL_PATH := $(PRODUCT_OUT)/dex_bootjars 15DEXPREOPT_PRODUCT_DIR := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXPREOPT_PRODUCT_DIR_FULL_PATH)) 16DEXPREOPT_BOOT_JAR_DIR := system/framework 17DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREOPT_BOOT_JAR_DIR) 18 19# The default value for LOCAL_DEX_PREOPT 20DEX_PREOPT_DEFAULT ?= true 21 22# The default filter for which files go into the system_other image (if it is 23# being used). To bundle everything one should set this to '%' 24SYSTEM_OTHER_ODEX_FILTER ?= app/% priv-app/% 25 26# Method returning whether the install path $(1) should be for system_other. 27install-on-system-other = $(filter-out $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(basename $(notdir $(filter $(foreach f,$(SYSTEM_OTHER_ODEX_FILTER),$(TARGET_OUT)/$(f)),$(1))))) 28 29# The default values for pre-opting: always preopt PIC. 30# Conditional to building on linux, as dex2oat currently does not work on darwin. 31ifeq ($(HOST_OS),linux) 32 WITH_DEXPREOPT ?= true 33# For an eng build only pre-opt the boot image and system server. This gives reasonable performance 34# and still allows a simple workflow: building in frameworks/base and syncing. 35 ifeq (eng,$(TARGET_BUILD_VARIANT)) 36 WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY ?= true 37 endif 38# Add mini-debug-info to the boot classpath unless explicitly asked not to. 39 ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO)) 40 PRODUCT_DEX_PREOPT_BOOT_FLAGS += --generate-mini-debug-info 41 endif 42endif 43 44GLOBAL_DEXPREOPT_FLAGS := 45 46# $(1): the .jar or .apk to remove classes.dex 47define dexpreopt-remove-classes.dex 48$(hide) zip --quiet --delete $(1) classes.dex; \ 49dex_index=2; \ 50while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \ 51 let dex_index=dex_index+1; \ 52done 53endef 54 55# Special rules for building stripped boot jars that override java_library.mk rules 56 57# $(1): boot jar module name 58define _dexpreopt-boot-jar-remove-classes.dex 59_dbj_jar_no_dex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1)_nodex.jar 60_dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar 61 62$$(_dbj_jar_no_dex) : $$(_dbj_src_jar) 63 $$(call copy-file-to-target) 64ifneq ($(DEX_PREOPT_DEFAULT),nostripping) 65 $$(call dexpreopt-remove-classes.dex,$$@) 66endif 67 68_dbj_jar_no_dex := 69_dbj_src_jar := 70endef 71 72$(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),$(eval $(call _dexpreopt-boot-jar-remove-classes.dex,$(b)))) 73 74include $(BUILD_SYSTEM)/dex_preopt_libart.mk 75 76# Define dexpreopt-one-file based on current default runtime. 77# $(1): the input .jar or .apk file 78# $(2): the output .odex file 79define dexpreopt-one-file 80$(call dex2oat-one-file,$(1),$(2)) 81endef 82 83DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS := $(DEX2OAT_DEPENDENCY) 84DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) 85ifdef TARGET_2ND_ARCH 86$(TARGET_2ND_ARCH_VAR_PREFIX)DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) 87endif # TARGET_2ND_ARCH 88