1#################################### 2# dexpreopt support - typically used on user builds to run dexopt (for Dalvik) or dex2oat (for ART) ahead of time 3# 4#################################### 5 6ifneq ($(DALVIK_VM_LIB),) 7 8# list of boot classpath jars for dexpreopt 9DEXPREOPT_BOOT_JARS := $(subst $(space),:,$(PRODUCT_BOOT_JARS)) 10DEXPREOPT_BOOT_JARS_MODULES := $(PRODUCT_BOOT_JARS) 11PRODUCT_BOOTCLASSPATH := $(subst $(space),:,$(foreach m,$(DEXPREOPT_BOOT_JARS_MODULES),/system/framework/$(m).jar)) 12 13PRODUCT_SYSTEM_SERVER_CLASSPATH := $(subst $(space),:,$(foreach m,$(PRODUCT_SYSTEM_SERVER_JARS),/system/framework/$(m).jar)) 14 15DEXPREOPT_BUILD_DIR := $(OUT_DIR) 16DEXPREOPT_PRODUCT_DIR_FULL_PATH := $(PRODUCT_OUT)/dex_bootjars 17DEXPREOPT_PRODUCT_DIR := $(patsubst $(DEXPREOPT_BUILD_DIR)/%,%,$(DEXPREOPT_PRODUCT_DIR_FULL_PATH)) 18DEXPREOPT_BOOT_JAR_DIR := system/framework 19DEXPREOPT_BOOT_JAR_DIR_FULL_PATH := $(DEXPREOPT_PRODUCT_DIR_FULL_PATH)/$(DEXPREOPT_BOOT_JAR_DIR) 20 21# $(1): the .jar or .apk to remove classes.dex 22define dexpreopt-remove-classes.dex 23$(hide) zip --quiet --delete $(1) classes.dex; \ 24dex_index=2; \ 25while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \ 26 let dex_index=dex_index+1; \ 27done 28endef 29 30# Special rules for building stripped boot jars that override java_library.mk rules 31 32# $(1): boot jar module name 33define _dexpreopt-boot-jar-remove-classes.dex 34_dbj_jar_no_dex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(1)_nodex.jar 35_dbj_src_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,$(1),,COMMON)/javalib.jar 36 37$$(_dbj_jar_no_dex) : $$(_dbj_src_jar) | $(ACP) $(AAPT) 38 $$(call copy-file-to-target) 39ifneq ($(DEX_PREOPT_DEFAULT),nostripping) 40 $$(call dexpreopt-remove-classes.dex,$$@) 41endif 42 43_dbj_jar_no_dex := 44_dbj_src_jar := 45endef 46 47$(foreach b,$(DEXPREOPT_BOOT_JARS_MODULES),$(eval $(call _dexpreopt-boot-jar-remove-classes.dex,$(b)))) 48 49# Conditionally include Dalvik support. 50ifeq ($(DALVIK_VM_LIB),libdvm.so) 51include $(BUILD_SYSTEM)/dex_preopt_libdvm.mk 52endif 53 54# Unconditionally include ART support because its used run dex2oat on the host for tests. 55include $(BUILD_SYSTEM)/dex_preopt_libart.mk 56 57# Define dexpreopt-one-file based on current default runtime. 58# $(1): the input .jar or .apk file 59# $(2): the output .odex file 60ifeq ($(DALVIK_VM_LIB),libdvm.so) 61define dexpreopt-one-file 62$(call dexopt-one-file,$(1),$(2)) 63endef 64 65DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS := $(DEXOPT_DEPENDENCY) 66DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $(DEXPREOPT_BOOT_ODEXS) 67else 68define dexpreopt-one-file 69$(call dex2oat-one-file,$(1),$(2)) 70endef 71 72DEXPREOPT_ONE_FILE_DEPENDENCY_TOOLS := $(DEX2OATD_DEPENDENCY) 73DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $(DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) 74ifdef TARGET_2ND_ARCH 75$(TARGET_2ND_ARCH_VAR_PREFIX)DEXPREOPT_ONE_FILE_DEPENDENCY_BUILT_BOOT_PREOPT := $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_BUILT_IMAGE_FILENAME) 76endif # TARGET_2ND_ARCH 77endif # DALVIK_VM_LIB 78else 79$(warning No DALVIK_VM_LIB, disable dexpreopt.) 80WITH_DEXPREOPT := false 81endif # DALVIK_VM_LIB is defined. 82