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, LOCAL_UNCOMPRESS_DEX 4 5ifeq (true,$(LOCAL_USE_EMBEDDED_DEX)) 6 LOCAL_UNCOMPRESS_DEX := true 7else 8 LOCAL_UNCOMPRESS_DEX := 9endif 10 11# We explicitly uncompress APKs of privileged apps, and used by 12# privileged apps 13ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS)) 14 ifeq (true,$(LOCAL_PRIVILEGED_MODULE)) 15 LOCAL_UNCOMPRESS_DEX := true 16 endif 17 18 ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE))) 19 LOCAL_UNCOMPRESS_DEX := true 20 endif 21endif # DONT_UNCOMPRESS_PRIV_APPS_DEXS 22 23# Setting LOCAL_DEX_PREOPT based on WITH_DEXPREOPT, LOCAL_DEX_PREOPT, etc 24LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT)) 25ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined 26 LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT) 27endif 28 29ifeq (false,$(LOCAL_DEX_PREOPT)) 30 LOCAL_DEX_PREOPT := 31endif 32 33# Only enable preopt for non tests. 34ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests)) 35 LOCAL_DEX_PREOPT := 36endif 37 38# If we have product-specific config for this module? 39ifneq (,$(filter $(LOCAL_MODULE),$(DEXPREOPT_DISABLED_MODULES))) 40 LOCAL_DEX_PREOPT := 41endif 42 43# Disable preopt for TARGET_BUILD_APPS 44ifneq (,$(TARGET_BUILD_APPS)) 45 LOCAL_DEX_PREOPT := 46endif 47 48# Disable preopt if not WITH_DEXPREOPT 49ifneq (true,$(WITH_DEXPREOPT)) 50 LOCAL_DEX_PREOPT := 51endif 52 53ifdef LOCAL_UNINSTALLABLE_MODULE 54 LOCAL_DEX_PREOPT := 55endif 56 57ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file)$(LOCAL_SOONG_DEX_JAR))) # contains no java code 58 LOCAL_DEX_PREOPT := 59endif 60 61# Don't preopt system server jars that are updatable. 62ifneq (,$(filter %:$(LOCAL_MODULE), $(PRODUCT_UPDATABLE_SYSTEM_SERVER_JARS))) 63 LOCAL_DEX_PREOPT := 64endif 65 66# if WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY=true and module is not in boot class path skip 67# Also preopt system server jars since selinux prevents system server from loading anything from 68# /data. If we don't do this they will need to be extracted which is not favorable for RAM usage 69# or performance. If my_preopt_for_extracted_apk is true, we ignore the only preopt boot image 70# options. 71ifneq (true,$(my_preopt_for_extracted_apk)) 72 ifeq (true,$(WITH_DEXPREOPT_BOOT_IMG_AND_SYSTEM_SERVER_ONLY)) 73 ifeq ($(filter $(PRODUCT_SYSTEM_SERVER_JARS) $(DEXPREOPT_BOOT_JARS_MODULES),$(LOCAL_MODULE)),) 74 LOCAL_DEX_PREOPT := 75 endif 76 endif 77endif 78 79my_process_profile := 80my_profile_is_text_listing := 81 82ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE)) 83 LOCAL_DEX_PREOPT_GENERATE_PROFILE := false 84endif 85 86ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE 87 # If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the 88 # profile class listing. TODO: Use product specific directory here. 89 my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR) 90 LOCAL_DEX_PREOPT_PROFILE := $(my_classes_directory)/$(LOCAL_MODULE).prof 91 92 ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE))) 93 my_process_profile := true 94 my_profile_is_text_listing := 95 endif 96else 97 my_process_profile := $(LOCAL_DEX_PREOPT_GENERATE_PROFILE) 98 my_profile_is_text_listing := true 99 LOCAL_DEX_PREOPT_PROFILE := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING) 100endif 101 102ifeq (true,$(my_process_profile)) 103 ifndef LOCAL_DEX_PREOPT_PROFILE 104 $(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE)) 105 endif 106 ifeq (,$(dex_preopt_profile_src_file)) 107 $(call pretty-error, Internal error: dex_preopt_profile_src_file must be set) 108 endif 109endif 110 111my_dexpreopt_archs := 112my_dexpreopt_images := 113my_dexpreopt_images_deps := 114my_dexpreopt_image_locations := 115my_dexpreopt_infix := boot 116ifeq (true, $(DEXPREOPT_USE_ART_IMAGE)) 117 my_dexpreopt_infix := art 118endif 119 120ifdef LOCAL_DEX_PREOPT 121 ifeq (,$(filter PRESIGNED,$(LOCAL_CERTIFICATE))) 122 # Store uncompressed dex files preopted in /system 123 ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true) 124 ifeq ($(call install-on-system-other, $(my_module_path)),) 125 LOCAL_UNCOMPRESS_DEX := true 126 endif # install-on-system-other 127 else # BOARD_USES_SYSTEM_OTHER_ODEX 128 LOCAL_UNCOMPRESS_DEX := true 129 endif 130 endif 131 132 ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) 133 my_module_multilib := $(LOCAL_MULTILIB) 134 # If the module is not an SDK library and it's a system server jar, only preopt the primary arch. 135 ifeq (,$(filter $(JAVA_SDK_LIBRARIES),$(LOCAL_MODULE))) 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 endif 142 endif 143 144 # Only preopt primary arch for translated arch since there is only an image there. 145 ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) 146 my_module_multilib := first 147 endif 148 149 # ################################################# 150 # Odex for the 1st arch 151 my_dexpreopt_archs += $(TARGET_ARCH) 152 my_dexpreopt_images += $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_ARCH)) 153 my_dexpreopt_images_deps += $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_ARCH)) 154 # Odex for the 2nd arch 155 ifdef TARGET_2ND_ARCH 156 ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true) 157 ifneq (first,$(my_module_multilib)) 158 my_dexpreopt_archs += $(TARGET_2ND_ARCH) 159 my_dexpreopt_images += $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_2ND_ARCH)) 160 my_dexpreopt_images_deps += $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_2ND_ARCH)) 161 endif # my_module_multilib is not first. 162 endif # TARGET_TRANSLATE_2ND_ARCH not true 163 endif # TARGET_2ND_ARCH 164 # ################################################# 165 else # must be APPS 166 # The preferred arch 167 # Save the module multilib since setup_one_odex modifies it. 168 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 169 my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH) 170 my_dexpreopt_images += \ 171 $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 172 my_dexpreopt_images_deps += \ 173 $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 174 ifdef TARGET_2ND_ARCH 175 ifeq ($(my_module_multilib),both) 176 # The non-preferred arch 177 my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX)) 178 my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH) 179 my_dexpreopt_images += \ 180 $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 181 my_dexpreopt_images_deps += \ 182 $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 183 endif # LOCAL_MULTILIB is both 184 endif # TARGET_2ND_ARCH 185 endif # LOCAL_MODULE_CLASS 186 187 my_dexpreopt_image_locations += $(DEXPREOPT_IMAGE_LOCATIONS_$(my_dexpreopt_infix)) 188 189 my_filtered_optional_uses_libraries := $(filter-out $(INTERNAL_PLATFORM_MISSING_USES_LIBRARIES), \ 190 $(LOCAL_OPTIONAL_USES_LIBRARIES)) 191 192 # dexpreopt needs the paths to the dex jars of these libraries in order to 193 # construct class loader context for dex2oat. 194 my_extra_dexpreopt_libs := \ 195 org.apache.http.legacy \ 196 android.hidl.base-V1.0-java \ 197 android.hidl.manager-V1.0-java \ 198 android.test.base \ 199 200 my_dexpreopt_libs := $(sort \ 201 $(LOCAL_USES_LIBRARIES) \ 202 $(my_filtered_optional_uses_libraries) \ 203 $(my_extra_dexpreopt_libs) \ 204 ) 205 206 # Record dex-preopt config. 207 DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT) 208 DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB) 209 DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) 210 DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE) 211 DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE) 212 DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH) 213 DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE) 214 DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \ 215 $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE)) 216 217 $(call json_start) 218 219 # DexPath is not set: it will be filled in by dexpreopt_gen. 220 221 $(call add_json_str, Name, $(LOCAL_MODULE)) 222 $(call add_json_str, DexLocation, $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))) 223 $(call add_json_str, BuildPath, $(LOCAL_BUILT_MODULE)) 224 $(call add_json_str, ManifestPath, $(full_android_manifest)) 225 $(call add_json_str, ExtrasOutputPath, $$2) 226 $(call add_json_bool, Privileged, $(filter true,$(LOCAL_PRIVILEGED_MODULE))) 227 $(call add_json_bool, UncompressedDex, $(filter true,$(LOCAL_UNCOMPRESS_DEX))) 228 $(call add_json_bool, HasApkLibraries, $(LOCAL_APK_LIBRARIES)) 229 $(call add_json_list, PreoptFlags, $(LOCAL_DEX_PREOPT_FLAGS)) 230 $(call add_json_str, ProfileClassListing, $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE))) 231 $(call add_json_bool, ProfileIsTextListing, $(my_profile_is_text_listing)) 232 $(call add_json_bool, EnforceUsesLibraries, $(LOCAL_ENFORCE_USES_LIBRARIES)) 233 $(call add_json_list, OptionalUsesLibraries, $(my_filtered_optional_uses_libraries)) 234 $(call add_json_list, UsesLibraries, $(LOCAL_USES_LIBRARIES)) 235 $(call add_json_map, LibraryPaths) 236 $(foreach lib,$(my_dexpreopt_libs),\ 237 $(call add_json_map, $(lib)) \ 238 $(eval file := $(filter %/$(lib).jar, $(call module-installed-files,$(lib)))) \ 239 $(call add_json_str, Host, $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar) \ 240 $(call add_json_str, Device, $(call install-path-to-on-device-path,$(file))) \ 241 $(call end_json_map)) 242 $(call end_json_map) 243 $(call add_json_list, Archs, $(my_dexpreopt_archs)) 244 $(call add_json_list, DexPreoptImages, $(my_dexpreopt_images)) 245 $(call add_json_list, DexPreoptImageLocations, $(my_dexpreopt_image_locations)) 246 $(call add_json_list, PreoptBootClassPathDexFiles, $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)) 247 $(call add_json_list, PreoptBootClassPathDexLocations,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS)) 248 $(call add_json_bool, PreoptExtractedApk, $(my_preopt_for_extracted_apk)) 249 $(call add_json_bool, NoCreateAppImage, $(filter false,$(LOCAL_DEX_PREOPT_APP_IMAGE))) 250 $(call add_json_bool, ForceCreateAppImage, $(filter true,$(LOCAL_DEX_PREOPT_APP_IMAGE))) 251 $(call add_json_bool, PresignedPrebuilt, $(filter PRESIGNED,$(LOCAL_CERTIFICATE))) 252 253 $(call json_end) 254 255 my_dexpreopt_config := $(intermediates)/dexpreopt.config 256 my_dexpreopt_script := $(intermediates)/dexpreopt.sh 257 my_dexpreopt_zip := $(intermediates)/dexpreopt.zip 258 259 $(my_dexpreopt_config): PRIVATE_MODULE := $(LOCAL_MODULE) 260 $(my_dexpreopt_config): PRIVATE_CONTENTS := $(json_contents) 261 $(my_dexpreopt_config): 262 @echo "$(PRIVATE_MODULE) dexpreopt.config" 263 echo -e -n '$(subst $(newline),\n,$(subst ','\'',$(subst \,\\,$(PRIVATE_CONTENTS))))' > $@ 264 265 .KATI_RESTAT: $(my_dexpreopt_script) 266 $(my_dexpreopt_script): PRIVATE_MODULE := $(LOCAL_MODULE) 267 $(my_dexpreopt_script): PRIVATE_GLOBAL_SOONG_CONFIG := $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE) 268 $(my_dexpreopt_script): PRIVATE_GLOBAL_CONFIG := $(DEX_PREOPT_CONFIG_FOR_MAKE) 269 $(my_dexpreopt_script): PRIVATE_MODULE_CONFIG := $(my_dexpreopt_config) 270 $(my_dexpreopt_script): $(DEXPREOPT_GEN) 271 $(my_dexpreopt_script): $(my_dexpreopt_config) $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE) $(DEX_PREOPT_CONFIG_FOR_MAKE) 272 @echo "$(PRIVATE_MODULE) dexpreopt gen" 273 $(DEXPREOPT_GEN) \ 274 -global_soong $(PRIVATE_GLOBAL_SOONG_CONFIG) \ 275 -global $(PRIVATE_GLOBAL_CONFIG) \ 276 -module $(PRIVATE_MODULE_CONFIG) \ 277 -dexpreopt_script $@ \ 278 -out_dir $(OUT_DIR) 279 280 my_dexpreopt_deps := $(my_dex_jar) 281 my_dexpreopt_deps += $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE)) 282 my_dexpreopt_deps += \ 283 $(foreach lib, $(my_dexpreopt_libs), \ 284 $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar) 285 my_dexpreopt_deps += $(my_dexpreopt_images_deps) 286 my_dexpreopt_deps += $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES) 287 288 $(my_dexpreopt_zip): PRIVATE_MODULE := $(LOCAL_MODULE) 289 $(my_dexpreopt_zip): $(my_dexpreopt_deps) 290 $(my_dexpreopt_zip): | $(DEXPREOPT_GEN_DEPS) 291 $(my_dexpreopt_zip): .KATI_DEPFILE := $(my_dexpreopt_zip).d 292 $(my_dexpreopt_zip): PRIVATE_DEX := $(my_dex_jar) 293 $(my_dexpreopt_zip): PRIVATE_SCRIPT := $(my_dexpreopt_script) 294 $(my_dexpreopt_zip): $(my_dexpreopt_script) 295 @echo "$(PRIVATE_MODULE) dexpreopt" 296 bash $(PRIVATE_SCRIPT) $(PRIVATE_DEX) $@ 297 298 ifdef LOCAL_POST_INSTALL_CMD 299 # Add a shell command separator 300 LOCAL_POST_INSTALL_CMD += && 301 endif 302 303 LOCAL_POST_INSTALL_CMD += \ 304 for i in $$(zipinfo -1 $(my_dexpreopt_zip)); \ 305 do mkdir -p $(PRODUCT_OUT)/$$(dirname $$i); \ 306 done && \ 307 ( unzip -qoDD -d $(PRODUCT_OUT) $(my_dexpreopt_zip) 2>&1 | grep -v "zipfile is empty"; exit $${PIPESTATUS[0]} ) || \ 308 ( code=$$?; if [ $$code -ne 0 -a $$code -ne 1 ]; then exit $$code; fi ) 309 310 $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := $(LOCAL_POST_INSTALL_CMD) 311 $(LOCAL_INSTALLED_MODULE): $(my_dexpreopt_zip) 312 313 $(my_all_targets): $(my_dexpreopt_zip) 314 315 my_dexpreopt_config := 316 my_dexpreopt_script := 317 my_dexpreopt_zip := 318endif # LOCAL_DEX_PREOPT 319