1 # dexpreopt_odex_install.mk is used to define odex creation rules for JARs and APKs 2 # This file depends on variables set in base_rules.mk 3 # Output variables: LOCAL_DEX_PREOPT, built_odex, dexpreopt_boot_jar_module 4 5 # Setting LOCAL_DEX_PREOPT based on WITH_DEXPREOPT, LOCAL_DEX_PREOPT, etc 6 LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT)) 7 ifneq (true,$(WITH_DEXPREOPT)) 8 LOCAL_DEX_PREOPT := 9 else # WITH_DEXPREOPT=true 10 ifeq (,$(TARGET_BUILD_APPS)) # TARGET_BUILD_APPS empty 11 ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined 12 ifneq ($(filter $(TARGET_OUT)/%,$(my_module_path)),) # Installed to system.img. 13 ifeq (,$(LOCAL_APK_LIBRARIES)) # LOCAL_APK_LIBRARIES empty 14 # If we have product-specific config for this module? 15 ifeq (disable,$(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG)) 16 LOCAL_DEX_PREOPT := false 17 else 18 LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT) 19 endif 20 else # LOCAL_APK_LIBRARIES not empty 21 LOCAL_DEX_PREOPT := nostripping 22 endif # LOCAL_APK_LIBRARIES not empty 23 endif # Installed to system.img. 24 endif # LOCAL_DEX_PREOPT undefined 25 endif # TARGET_BUILD_APPS empty 26 endif # WITH_DEXPREOPT=true 27 ifeq (false,$(LOCAL_DEX_PREOPT)) 28 LOCAL_DEX_PREOPT := 29 endif 30 ifdef LOCAL_UNINSTALLABLE_MODULE 31 LOCAL_DEX_PREOPT := 32 endif 33 ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file))) # contains no java code 34 LOCAL_DEX_PREOPT := 35 endif 36 # if WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true and module is not in boot class path skip 37 # Also preopt system server jars since selinux prevents system server from loading anything from 38 # /data. If we don't do this they will need to be extracted which is not favorable for RAM usage 39 # or performance. If my_preopt_for_extracted_apk is true, we ignore the only preopt boot image 40 # options. 41 ifneq (true,$(my_preopt_for_extracted_apk)) 42 ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY)) 43 ifeq ($(filter $(PRODUCT_SYSTEM_SERVER_JARS) $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),) 44 LOCAL_DEX_PREOPT := 45 endif 46 endif 47 endif 48 49 # if installing into system, and odex are being installed into system_other, don't strip 50 ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true) 51 ifeq ($(LOCAL_DEX_PREOPT),true) 52 ifneq ($(call install-on-system-other, $(my_module_path)),) 53 LOCAL_DEX_PREOPT := nostripping 54 endif 55 endif 56 endif 57 58 built_odex := 59 built_vdex := 60 built_art := 61 installed_odex := 62 installed_vdex := 63 installed_art := 64 built_installed_odex := 65 built_installed_vdex := 66 built_installed_art := 67 68 ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE)) 69 LOCAL_DEX_PREOPT_GENERATE_PROFILE := false 70 endif 71 72 ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE 73 # If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the 74 # profile class listing. TODO: Use product specific directory here. 75 my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR) 76 LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(my_classes_directory)/$(LOCAL_MODULE).prof.txt 77 ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING))) 78 # Profile listing exists, use it to generate the profile. 79 LOCAL_DEX_PREOPT_GENERATE_PROFILE := true 80 endif 81 endif 82 83 ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE)) 84 85 ifdef LOCAL_VENDOR_MODULE 86 $(call pretty-error, Internal error: profiles are not supported for vendor modules) 87 else 88 LOCAL_DEX_PREOPT_APP_IMAGE := true 89 endif 90 91 ifndef LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING 92 $(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)) 93 endif 94 ifeq (,$(dex_preopt_profile_src_file)) 95 $(call pretty-error, Internal error: dex_preopt_profile_src_file must be set) 96 endif 97 my_built_profile := $(dir $(LOCAL_BUILT_MODULE))/profile.prof 98 my_dex_location := $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE)) 99 # Remove compressed APK extension. 100 my_dex_location := $(patsubst %.gz,%,$(my_dex_location)) 101 $(my_built_profile): PRIVATE_BUILT_MODULE := $(dex_preopt_profile_src_file) 102 $(my_built_profile): PRIVATE_DEX_LOCATION := $(my_dex_location) 103 $(my_built_profile): PRIVATE_SOURCE_CLASSES := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING) 104 $(my_built_profile): $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING) 105 $(my_built_profile): $(PROFMAN) 106 $(my_built_profile): $(dex_preopt_profile_src_file) 107 $(my_built_profile): 108 $(hide) mkdir -p $(dir $@) 109 ANDROID_LOG_TAGS="*:e" $(PROFMAN) \ 110 --create-profile-from=$(PRIVATE_SOURCE_CLASSES) \ 111 --apk=$(PRIVATE_BUILT_MODULE) \ 112 --dex-location=$(PRIVATE_DEX_LOCATION) \ 113 --reference-profile-file=$@ 114 dex_preopt_profile_src_file:= 115 # Remove compressed APK extension. 116 my_installed_profile := $(patsubst %.gz,%,$(LOCAL_INSTALLED_MODULE)).prof 117 # my_installed_profile := $(LOCAL_INSTALLED_MODULE).prof 118 $(eval $(call copy-one-file,$(my_built_profile),$(my_installed_profile))) 119 build_installed_profile:=$(my_built_profile):$(my_installed_profile) 120 else 121 build_installed_profile:= 122 my_installed_profile := 123 endif 124 125 ifdef LOCAL_DEX_PREOPT 126 127 dexpreopt_boot_jar_module := $(filter $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)) 128 ifdef dexpreopt_boot_jar_module 129 # For libart, the boot jars' odex files are replaced by $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE). 130 # We use this installed_odex trick to get boot.art installed. 131 installed_odex := $(DEFAULT_DEX_PREOPT_INSTALLED_IMAGE) 132 # Append the odex for the 2nd arch if we have one. 133 installed_odex += $($(TARGET_2ND_ARCH_VAR_PREFIX)DEFAULT_DEX_PREOPT_INSTALLED_IMAGE) 134 else # boot jar 135 ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) 136 # For a Java library, by default we build odex for both 1st arch and 2nd arch. 137 # But it can be overridden with "LOCAL_MULTILIB := first". 138 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) 139 # For system server jars, we build for only "first". 140 my_module_multilib := first 141 else 142 my_module_multilib := $(LOCAL_MULTILIB) 143 endif 144 # ################################################# 145 # Odex for the 1st arch 146 my_2nd_arch_prefix := 147 include $(BUILD_SYSTEM)/setup_one_odex.mk 148 # ################################################# 149 # Odex for the 2nd arch 150 ifdef TARGET_2ND_ARCH 151 ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true) 152 ifneq (first,$(my_module_multilib)) 153 my_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX) 154 include $(BUILD_SYSTEM)/setup_one_odex.mk 155 endif # my_module_multilib is not first. 156 endif # TARGET_TRANSLATE_2ND_ARCH not true 157 endif # TARGET_2ND_ARCH 158 # ################################################# 159 else # must be APPS 160 # The preferred arch 161 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 162 include $(BUILD_SYSTEM)/setup_one_odex.mk 163 ifdef TARGET_2ND_ARCH 164 ifeq ($(LOCAL_MULTILIB),both) 165 # The non-preferred arch 166 my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX)) 167 include $(BUILD_SYSTEM)/setup_one_odex.mk 168 endif # LOCAL_MULTILIB is both 169 endif # TARGET_2ND_ARCH 170 endif # LOCAL_MODULE_CLASS 171 endif # boot jar 172 173 built_odex := $(strip $(built_odex)) 174 built_vdex := $(strip $(built_vdex)) 175 built_art := $(strip $(built_art)) 176 installed_odex := $(strip $(installed_odex)) 177 installed_vdex := $(strip $(installed_vdex)) 178 installed_art := $(strip $(installed_art)) 179 180 ifdef built_odex 181 ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE)) 182 $(built_odex): $(my_built_profile) 183 $(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := --profile-file=$(my_built_profile) 184 else 185 $(built_odex): PRIVATE_PROFILE_PREOPT_FLAGS := 186 endif 187 188 ifndef LOCAL_DEX_PREOPT_FLAGS 189 LOCAL_DEX_PREOPT_FLAGS := $(DEXPREOPT.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG) 190 ifndef LOCAL_DEX_PREOPT_FLAGS 191 LOCAL_DEX_PREOPT_FLAGS := $(PRODUCT_DEX_PREOPT_DEFAULT_FLAGS) 192 endif 193 endif 194 195 my_system_server_compiler_filter := $(PRODUCT_SYSTEM_SERVER_COMPILER_FILTER) 196 ifeq (,$(my_system_server_compiler_filter)) 197 my_system_server_compiler_filter := speed 198 endif 199 200 ifeq (,$(filter --compiler-filter=%, $(LOCAL_DEX_PREOPT_FLAGS))) 201 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) 202 # Jars of system server, use the product option if it is set, speed otherwise. 203 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=$(my_system_server_compiler_filter) 204 else 205 ifneq (,$(filter $(PRODUCT_DEXPREOPT_SPEED_APPS) $(PRODUCT_SYSTEM_SERVER_APPS),$(LOCAL_MODULE))) 206 # Apps loaded into system server, and apps the product default to being compiled with the 207 # 'speed' compiler filter. 208 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed 209 else 210 ifeq (true,$(LOCAL_DEX_PREOPT_GENERATE_PROFILE)) 211 # For non system server jars, use speed-profile when we have a profile. 212 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=speed-profile 213 else 214 # If no compiler filter is specified, default to 'quicken' to save on storage. 215 LOCAL_DEX_PREOPT_FLAGS += --compiler-filter=quicken 216 endif 217 endif 218 endif 219 endif 220 221 # PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO. 222 my_system_server_debug_info := $(PRODUCT_SYSTEM_SERVER_DEBUG_INFO) 223 ifeq (,$(filter eng, $(TARGET_BUILD_VARIANT))) 224 # Only enable for non-eng builds. 225 ifeq (,$(my_system_server_debug_info)) 226 my_system_server_debug_info := true 227 endif 228 endif 229 230 ifeq (true, $(my_system_server_debug_info)) 231 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) 232 LOCAL_DEX_PREOPT_FLAGS += --generate-mini-debug-info 233 endif 234 endif 235 236 $(built_odex): PRIVATE_DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) 237 $(built_vdex): $(built_odex) 238 $(built_art): $(built_odex) 239 endif 240 241 # Add the installed_odex to the list of installed files for this module. 242 ALL_MODULES.$(my_register_name).INSTALLED += $(installed_odex) 243 ALL_MODULES.$(my_register_name).INSTALLED += $(installed_vdex) 244 ALL_MODULES.$(my_register_name).INSTALLED += $(installed_art) 245 246 ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_odex) 247 ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_vdex) 248 ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(built_installed_art) 249 250 # Record dex-preopt config. 251 DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT) 252 DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB) 253 DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) 254 DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE) 255 DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE) 256 DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH) 257 DEXPREOPT.$(LOCAL_MODULE).INSTALLED := $(installed_odex) 258 DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE) 259 DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \ 260 $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE)) 261 262 263 # Make sure to install the .odex and .vdex when you run "make <module_name>" 264 $(my_all_targets): $(installed_odex) $(installed_vdex) $(installed_art) 265 266 endif # LOCAL_DEX_PREOPT 267 268 # Profile doesn't depend on LOCAL_DEX_PREOPT. 269 ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_profile) 270 ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(build_installed_profile) 271 272 $(my_all_targets): $(my_installed_profile) 273