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# Input variables: my_manifest_or_apk 4# Output variables: LOCAL_DEX_PREOPT, LOCAL_UNCOMPRESS_DEX 5 6ifeq (true,$(LOCAL_USE_EMBEDDED_DEX)) 7 LOCAL_UNCOMPRESS_DEX := true 8else 9 LOCAL_UNCOMPRESS_DEX := 10endif 11 12# We explicitly uncompress APKs of privileged apps, and used by 13# privileged apps 14ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS)) 15 ifeq (true,$(LOCAL_PRIVILEGED_MODULE)) 16 LOCAL_UNCOMPRESS_DEX := true 17 endif 18 19 ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE))) 20 LOCAL_UNCOMPRESS_DEX := true 21 endif 22endif # DONT_UNCOMPRESS_PRIV_APPS_DEXS 23 24# Setting LOCAL_DEX_PREOPT based on WITH_DEXPREOPT, LOCAL_DEX_PREOPT, etc 25LOCAL_DEX_PREOPT := $(strip $(LOCAL_DEX_PREOPT)) 26ifndef LOCAL_DEX_PREOPT # LOCAL_DEX_PREOPT undefined 27 LOCAL_DEX_PREOPT := $(DEX_PREOPT_DEFAULT) 28endif 29 30ifeq (false,$(LOCAL_DEX_PREOPT)) 31 LOCAL_DEX_PREOPT := 32endif 33 34# Disable preopt for tests. 35ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests)) 36 LOCAL_DEX_PREOPT := 37endif 38 39# If we have product-specific config for this module? 40ifneq (,$(filter $(LOCAL_MODULE),$(DEXPREOPT_DISABLED_MODULES))) 41 LOCAL_DEX_PREOPT := 42endif 43 44# Disable preopt for DISABLE_PREOPT 45ifeq (true,$(DISABLE_PREOPT)) 46 LOCAL_DEX_PREOPT := 47endif 48 49# Disable preopt if not WITH_DEXPREOPT 50ifneq (true,$(WITH_DEXPREOPT)) 51 LOCAL_DEX_PREOPT := 52endif 53 54ifdef LOCAL_UNINSTALLABLE_MODULE 55 LOCAL_DEX_PREOPT := 56endif 57 58# Disable preopt if the app contains no java code. 59ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file)$(LOCAL_SOONG_DEX_JAR))) 60 LOCAL_DEX_PREOPT := 61endif 62 63ifeq (true,$(WITH_DEXPREOPT_ART_BOOT_IMG_ONLY)) 64 LOCAL_DEX_PREOPT := 65endif 66 67my_process_profile := 68my_profile_is_text_listing := 69 70ifeq (false,$(WITH_DEX_PREOPT_GENERATE_PROFILE)) 71 LOCAL_DEX_PREOPT_GENERATE_PROFILE := false 72endif 73 74ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE 75 # If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the 76 # profile class listing. TODO: Use product specific directory here. 77 ifdef PRODUCT_DEX_PREOPT_PROFILE_DIR 78 LOCAL_DEX_PREOPT_PROFILE := $(PRODUCT_DEX_PREOPT_PROFILE_DIR)/$(LOCAL_MODULE).prof 79 80 ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE))) 81 my_process_profile := true 82 my_profile_is_text_listing := 83 endif 84 endif 85else 86 my_process_profile := $(LOCAL_DEX_PREOPT_GENERATE_PROFILE) 87 my_profile_is_text_listing := true 88 LOCAL_DEX_PREOPT_PROFILE := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING) 89endif 90 91ifeq (true,$(my_process_profile)) 92 ifndef LOCAL_DEX_PREOPT_PROFILE 93 $(call pretty-error,Must have specified class listing (LOCAL_DEX_PREOPT_PROFILE)) 94 endif 95 ifeq (,$(dex_preopt_profile_src_file)) 96 $(call pretty-error, Internal error: dex_preopt_profile_src_file must be set) 97 endif 98endif 99 100################################################################################ 101# Local module variables and functions used in dexpreopt and manifest_check. 102################################################################################ 103 104# TODO(b/132357300): This may filter out too much, as PRODUCT_PACKAGES doesn't 105# include all packages (the full list is unknown until reading all Android.mk 106# makefiles). As a consequence, a library may be present but not included in 107# dexpreopt, which will result in class loader context mismatch and a failure 108# to load dexpreopt code on device. 109# However, we have to do filtering here. Otherwise, we may include extra 110# libraries that Soong and Make don't generate build rules for (e.g., a library 111# that exists in the source tree but not installable), and therefore get Ninja 112# errors. 113# We have deferred CLC computation to the Ninja phase, but the dependency 114# computation still needs to be done early. For now, this is the best we can do. 115my_filtered_optional_uses_libraries := $(filter $(PRODUCT_PACKAGES), \ 116 $(LOCAL_OPTIONAL_USES_LIBRARIES)) 117 118ifeq ($(LOCAL_MODULE_CLASS),APPS) 119 # compatibility libraries are added to class loader context of an app only if 120 # targetSdkVersion in the app's manifest is lower than the given SDK version 121 122 my_dexpreopt_libs_compat_28 := \ 123 org.apache.http.legacy 124 125 my_dexpreopt_libs_compat_29 := \ 126 android.hidl.manager-V1.0-java \ 127 android.hidl.base-V1.0-java 128 129 my_dexpreopt_libs_compat_30 := \ 130 android.test.base \ 131 android.test.mock 132 133 my_dexpreopt_libs_compat := \ 134 $(my_dexpreopt_libs_compat_28) \ 135 $(my_dexpreopt_libs_compat_29) \ 136 $(my_dexpreopt_libs_compat_30) 137else 138 my_dexpreopt_libs_compat := 139endif 140 141my_dexpreopt_libs := \ 142 $(LOCAL_USES_LIBRARIES) \ 143 $(my_filtered_optional_uses_libraries) 144 145# The order needs to be deterministic. 146my_dexpreopt_libs_all := $(sort $(my_dexpreopt_libs) $(my_dexpreopt_libs_compat)) 147 148# Module dexpreopt.config depends on dexpreopt.config files of each 149# <uses-library> dependency, because these libraries may be processed after 150# the current module by Make (there's no topological order), so the dependency 151# information (paths, class loader context) may not be ready yet by the time 152# this dexpreopt.config is generated. So it's necessary to add file-level 153# dependencies between dexpreopt.config files. 154my_dexpreopt_dep_configs := $(foreach lib, \ 155 $(filter-out $(my_dexpreopt_libs_compat),$(LOCAL_USES_LIBRARIES) $(my_filtered_optional_uses_libraries)), \ 156 $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,)/dexpreopt.config) 157 158# 1: SDK version 159# 2: list of libraries 160# 161# Make does not process modules in topological order wrt. <uses-library> 162# dependencies, therefore we cannot rely on variables to get the information 163# about dependencies (in particular, their on-device path and class loader 164# context). This information is communicated via dexpreopt.config files: each 165# config depends on configs for <uses-library> dependencies of this module, 166# and the dex_preopt_config_merger.py script reads all configs and inserts the 167# missing bits from dependency configs into the module config. 168# 169# By default on-device path is /system/framework/*.jar, and class loader 170# subcontext is empty. These values are correct for compatibility libraries, 171# which are special and not handled by dex_preopt_config_merger.py. 172# 173add_json_class_loader_context = \ 174 $(call add_json_array, $(1)) \ 175 $(foreach lib, $(2),\ 176 $(call add_json_map_anon) \ 177 $(call add_json_str, Name, $(lib)) \ 178 $(call add_json_str, Host, $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar) \ 179 $(call add_json_str, Device, /system/framework/$(lib).jar) \ 180 $(call add_json_val, Subcontexts, null) \ 181 $(call end_json_map)) \ 182 $(call end_json_array) 183 184################################################################################ 185# Verify <uses-library> coherence between the build system and the manifest. 186################################################################################ 187 188# Some libraries do not have a manifest, so there is nothing to check against. 189# Handle it as if the manifest had zero <uses-library> tags: it is ok unless the 190# module has non-empty LOCAL_USES_LIBRARIES or LOCAL_OPTIONAL_USES_LIBRARIES. 191ifndef my_manifest_or_apk 192 ifneq (,$(strip $(LOCAL_USES_LIBRARIES)$(LOCAL_OPTIONAL_USES_LIBRARIES))) 193 $(error $(LOCAL_MODULE) has non-empty <uses-library> list but no manifest) 194 else 195 LOCAL_ENFORCE_USES_LIBRARIES := false 196 endif 197endif 198 199# Disable the check for tests. 200ifneq (,$(filter $(LOCAL_MODULE_TAGS),tests)) 201 LOCAL_ENFORCE_USES_LIBRARIES := false 202endif 203ifneq (,$(LOCAL_COMPATIBILITY_SUITE)) 204 LOCAL_ENFORCE_USES_LIBRARIES := false 205 206 # Enable the check for WTS 207 ifneq ($(filter wts,$(LOCAL_COMPATIBILITY_SUITE)),) 208 LOCAL_ENFORCE_USES_LIBRARIES := true 209 endif 210 211endif 212 213# Disable the check if the app contains no java code. 214ifeq (,$(strip $(built_dex)$(my_prebuilt_src_file)$(LOCAL_SOONG_DEX_JAR))) 215 LOCAL_ENFORCE_USES_LIBRARIES := false 216endif 217 218# Disable <uses-library> checks if dexpreopt is globally disabled. 219# Without dexpreopt the check is not necessary, and although it is good to have, 220# it is difficult to maintain on non-linux build platforms where dexpreopt is 221# generally disabled (the check may fail due to various unrelated reasons, such 222# as a failure to get manifest from an APK). 223ifneq (true,$(WITH_DEXPREOPT)) 224 LOCAL_ENFORCE_USES_LIBRARIES := false 225else ifeq (true,$(WITH_DEXPREOPT_ART_BOOT_IMG_ONLY)) 226 LOCAL_ENFORCE_USES_LIBRARIES := false 227endif 228 229# Verify LOCAL_USES_LIBRARIES/LOCAL_OPTIONAL_USES_LIBRARIES against the manifest. 230ifndef LOCAL_ENFORCE_USES_LIBRARIES 231 LOCAL_ENFORCE_USES_LIBRARIES := true 232endif 233 234my_enforced_uses_libraries := 235ifeq (true,$(LOCAL_ENFORCE_USES_LIBRARIES)) 236 my_verify_script := build/soong/scripts/manifest_check.py 237 my_uses_libs_args := $(patsubst %,--uses-library %,$(LOCAL_USES_LIBRARIES)) 238 my_optional_uses_libs_args := $(patsubst %,--optional-uses-library %, \ 239 $(LOCAL_OPTIONAL_USES_LIBRARIES)) 240 my_relax_check_arg := $(if $(filter true,$(RELAX_USES_LIBRARY_CHECK)), \ 241 --enforce-uses-libraries-relax,) 242 my_dexpreopt_config_args := $(patsubst %,--dexpreopt-config %,$(my_dexpreopt_dep_configs)) 243 244 my_enforced_uses_libraries := $(intermediates)/enforce_uses_libraries.status 245 $(my_enforced_uses_libraries): PRIVATE_USES_LIBRARIES := $(my_uses_libs_args) 246 $(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(my_optional_uses_libs_args) 247 $(my_enforced_uses_libraries): PRIVATE_DEXPREOPT_CONFIGS := $(my_dexpreopt_config_args) 248 $(my_enforced_uses_libraries): PRIVATE_RELAX_CHECK := $(my_relax_check_arg) 249 $(my_enforced_uses_libraries): $(AAPT2) 250 $(my_enforced_uses_libraries): $(my_verify_script) 251 $(my_enforced_uses_libraries): $(my_dexpreopt_dep_configs) 252 $(my_enforced_uses_libraries): $(my_manifest_or_apk) 253 @echo Verifying uses-libraries: $< 254 rm -f $@ 255 $(my_verify_script) \ 256 --enforce-uses-libraries \ 257 --enforce-uses-libraries-status $@ \ 258 --aapt $(AAPT2) \ 259 $(PRIVATE_USES_LIBRARIES) \ 260 $(PRIVATE_OPTIONAL_USES_LIBRARIES) \ 261 $(PRIVATE_DEXPREOPT_CONFIGS) \ 262 $(PRIVATE_RELAX_CHECK) \ 263 $< 264 $(LOCAL_BUILT_MODULE) : $(my_enforced_uses_libraries) 265endif 266 267################################################################################ 268# Dexpreopt command. 269################################################################################ 270 271my_dexpreopt_archs := 272my_dexpreopt_images := 273my_dexpreopt_images_deps := 274my_dexpreopt_image_locations_on_host := 275my_dexpreopt_image_locations_on_device := 276my_dexpreopt_infix := $(DEXPREOPT_INFIX) 277my_create_dexpreopt_config := 278 279ifdef LOCAL_DEX_PREOPT 280 ifeq (,$(filter PRESIGNED,$(LOCAL_CERTIFICATE))) 281 # Store uncompressed dex files preopted in /system 282 ifeq ($(BOARD_USES_SYSTEM_OTHER_ODEX),true) 283 ifeq ($(call install-on-system-other, $(my_module_path)),) 284 LOCAL_UNCOMPRESS_DEX := true 285 endif # install-on-system-other 286 else # BOARD_USES_SYSTEM_OTHER_ODEX 287 LOCAL_UNCOMPRESS_DEX := true 288 endif 289 endif 290 my_create_dexpreopt_config := true 291endif 292 293# dexpreopt is disabled when TARGET_BUILD_UNBUNDLED_IMAGE is true, 294# but dexpreopt config files are required to dexpreopt in post-processing. 295ifeq ($(TARGET_BUILD_UNBUNDLED_IMAGE),true) 296 my_create_dexpreopt_config := true 297endif 298 299ifeq ($(my_create_dexpreopt_config), true) 300 ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES) 301 my_module_multilib := $(LOCAL_MULTILIB) 302 # If the module is not an SDK library and it's a system server jar, only preopt the primary arch. 303 ifeq (,$(filter $(JAVA_SDK_LIBRARIES),$(LOCAL_MODULE))) 304 # For a Java library, by default we build odex for both 1st arch and 2nd arch. 305 # But it can be overridden with "LOCAL_MULTILIB := first". 306 ifneq (,$(filter $(PRODUCT_SYSTEM_SERVER_JARS),$(LOCAL_MODULE))) 307 # For system server jars, we build for only "first". 308 my_module_multilib := first 309 endif 310 endif 311 312 # Only preopt primary arch for translated arch since there is only an image there. 313 ifeq ($(TARGET_TRANSLATE_2ND_ARCH),true) 314 my_module_multilib := first 315 endif 316 317 # ################################################# 318 # Odex for the 1st arch 319 my_dexpreopt_archs += $(TARGET_ARCH) 320 my_dexpreopt_images += $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_ARCH)) 321 my_dexpreopt_images_deps += $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_ARCH)) 322 # Odex for the 2nd arch 323 ifdef TARGET_2ND_ARCH 324 ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true) 325 ifneq (first,$(my_module_multilib)) 326 my_dexpreopt_archs += $(TARGET_2ND_ARCH) 327 my_dexpreopt_images += $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_2ND_ARCH)) 328 my_dexpreopt_images_deps += $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_2ND_ARCH)) 329 endif # my_module_multilib is not first. 330 endif # TARGET_TRANSLATE_2ND_ARCH not true 331 endif # TARGET_2ND_ARCH 332 # ################################################# 333 else # must be APPS 334 # The preferred arch 335 # Save the module multilib since setup_one_odex modifies it. 336 my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX) 337 my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH) 338 my_dexpreopt_images += \ 339 $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 340 my_dexpreopt_images_deps += \ 341 $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 342 ifdef TARGET_2ND_ARCH 343 ifeq ($(my_module_multilib),both) 344 # The non-preferred arch 345 my_2nd_arch_prefix := $(if $(LOCAL_2ND_ARCH_VAR_PREFIX),,$(TARGET_2ND_ARCH_VAR_PREFIX)) 346 my_dexpreopt_archs += $(TARGET_$(my_2nd_arch_prefix)ARCH) 347 my_dexpreopt_images += \ 348 $(DEXPREOPT_IMAGE_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 349 my_dexpreopt_images_deps += \ 350 $(DEXPREOPT_IMAGE_DEPS_$(my_dexpreopt_infix)_$(TARGET_$(my_2nd_arch_prefix)ARCH)) 351 endif # LOCAL_MULTILIB is both 352 endif # TARGET_2ND_ARCH 353 endif # LOCAL_MODULE_CLASS 354 355 my_dexpreopt_image_locations_on_host += $(DEXPREOPT_IMAGE_LOCATIONS_ON_HOST$(my_dexpreopt_infix)) 356 my_dexpreopt_image_locations_on_device += $(DEXPREOPT_IMAGE_LOCATIONS_ON_DEVICE$(my_dexpreopt_infix)) 357 358 # Record dex-preopt config. 359 DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT := $(LOCAL_DEX_PREOPT) 360 DEXPREOPT.$(LOCAL_MODULE).MULTILIB := $(LOCAL_MULTILIB) 361 DEXPREOPT.$(LOCAL_MODULE).DEX_PREOPT_FLAGS := $(LOCAL_DEX_PREOPT_FLAGS) 362 DEXPREOPT.$(LOCAL_MODULE).PRIVILEGED_MODULE := $(LOCAL_PRIVILEGED_MODULE) 363 DEXPREOPT.$(LOCAL_MODULE).VENDOR_MODULE := $(LOCAL_VENDOR_MODULE) 364 DEXPREOPT.$(LOCAL_MODULE).TARGET_ARCH := $(LOCAL_MODULE_TARGET_ARCH) 365 DEXPREOPT.$(LOCAL_MODULE).INSTALLED_STRIPPED := $(LOCAL_INSTALLED_MODULE) 366 DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS) := $(sort \ 367 $(DEXPREOPT.MODULES.$(LOCAL_MODULE_CLASS)) $(LOCAL_MODULE)) 368 369 $(call json_start) 370 371 # DexPath is not set: it will be filled in by dexpreopt_gen. 372 373 $(call add_json_str, Name, $(LOCAL_MODULE)) 374 $(call add_json_str, DexLocation, $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))) 375 $(call add_json_str, BuildPath, $(LOCAL_BUILT_MODULE)) 376 $(call add_json_str, ManifestPath, $(full_android_manifest)) 377 $(call add_json_str, ExtrasOutputPath, $$2) 378 $(call add_json_bool, Privileged, $(filter true,$(LOCAL_PRIVILEGED_MODULE))) 379 $(call add_json_bool, UncompressedDex, $(filter true,$(LOCAL_UNCOMPRESS_DEX))) 380 $(call add_json_bool, HasApkLibraries, $(LOCAL_APK_LIBRARIES)) 381 $(call add_json_list, PreoptFlags, $(LOCAL_DEX_PREOPT_FLAGS)) 382 $(call add_json_str, ProfileClassListing, $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE))) 383 $(call add_json_bool, ProfileIsTextListing, $(my_profile_is_text_listing)) 384 $(call add_json_str, EnforceUsesLibrariesStatusFile, $(my_enforced_uses_libraries)) 385 $(call add_json_bool, EnforceUsesLibraries, $(filter true,$(LOCAL_ENFORCE_USES_LIBRARIES))) 386 $(call add_json_str, ProvidesUsesLibrary, $(firstword $(LOCAL_PROVIDES_USES_LIBRARY) $(LOCAL_MODULE))) 387 $(call add_json_map, ClassLoaderContexts) 388 $(call add_json_class_loader_context, any, $(my_dexpreopt_libs)) 389 $(call add_json_class_loader_context, 28, $(my_dexpreopt_libs_compat_28)) 390 $(call add_json_class_loader_context, 29, $(my_dexpreopt_libs_compat_29)) 391 $(call add_json_class_loader_context, 30, $(my_dexpreopt_libs_compat_30)) 392 $(call end_json_map) 393 $(call add_json_list, Archs, $(my_dexpreopt_archs)) 394 $(call add_json_list, DexPreoptImages, $(my_dexpreopt_images)) 395 $(call add_json_list, DexPreoptImageLocationsOnHost, $(my_dexpreopt_image_locations_on_host)) 396 $(call add_json_list, DexPreoptImageLocationsOnDevice,$(my_dexpreopt_image_locations_on_device)) 397 $(call add_json_list, PreoptBootClassPathDexFiles, $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)) 398 $(call add_json_list, PreoptBootClassPathDexLocations,$(DEXPREOPT_BOOTCLASSPATH_DEX_LOCATIONS)) 399 $(call add_json_bool, NoCreateAppImage, $(filter false,$(LOCAL_DEX_PREOPT_APP_IMAGE))) 400 $(call add_json_bool, ForceCreateAppImage, $(filter true,$(LOCAL_DEX_PREOPT_APP_IMAGE))) 401 $(call add_json_bool, PresignedPrebuilt, $(filter PRESIGNED,$(LOCAL_CERTIFICATE))) 402 403 $(call json_end) 404 405 my_dexpreopt_config := $(intermediates)/dexpreopt.config 406 my_dexpreopt_config_for_postprocessing := $(PRODUCT_OUT)/dexpreopt_config/$(LOCAL_MODULE)_dexpreopt.config 407 my_dexpreopt_config_merger := $(BUILD_SYSTEM)/dex_preopt_config_merger.py 408 409 $(my_dexpreopt_config): $(my_dexpreopt_dep_configs) $(my_dexpreopt_config_merger) 410 $(my_dexpreopt_config): PRIVATE_MODULE := $(LOCAL_MODULE) 411 $(my_dexpreopt_config): PRIVATE_CONTENTS := $(json_contents) 412 $(my_dexpreopt_config): PRIVATE_DEP_CONFIGS := $(my_dexpreopt_dep_configs) 413 $(my_dexpreopt_config): PRIVATE_CONFIG_MERGER := $(my_dexpreopt_config_merger) 414 $(my_dexpreopt_config): 415 @echo "$(PRIVATE_MODULE) dexpreopt.config" 416 echo -e -n '$(subst $(newline),\n,$(subst ','\'',$(subst \,\\,$(PRIVATE_CONTENTS))))' > $@ 417 $(PRIVATE_CONFIG_MERGER) $@ $(PRIVATE_DEP_CONFIGS) 418 419$(eval $(call copy-one-file,$(my_dexpreopt_config),$(my_dexpreopt_config_for_postprocessing))) 420 421$(LOCAL_INSTALLED_MODULE): $(my_dexpreopt_config_for_postprocessing) 422 423# System server jars defined in Android.mk are deprecated. 424ifneq (true, $(PRODUCT_BROKEN_DEPRECATED_MK_SYSTEM_SERVER_JARS)) 425 ifneq (,$(filter %:$(LOCAL_MODULE), $(PRODUCT_SYSTEM_SERVER_JARS) $(PRODUCT_APEX_SYSTEM_SERVER_JARS))) 426 $(error System server jars defined in Android.mk are deprecated. \ 427 Convert $(LOCAL_MODULE) to Android.bp or temporarily disable the error \ 428 with 'PRODUCT_BROKEN_DEPRECATED_MK_SYSTEM_SERVER_JARS := true') 429 endif 430endif 431 432ifdef LOCAL_DEX_PREOPT 433 # System server jars must be copied into predefined locations expected by 434 # dexpreopt. Copy rule must be exposed to Ninja (as it uses these files as 435 # inputs), so it cannot go in dexpreopt.sh. 436 ifneq (,$(filter %:$(LOCAL_MODULE), $(PRODUCT_SYSTEM_SERVER_JARS))) 437 my_dexpreopt_jar_copy := $(OUT_DIR)/soong/system_server_dexjars/$(LOCAL_MODULE).jar 438 $(my_dexpreopt_jar_copy): PRIVATE_BUILT_MODULE := $(LOCAL_BUILT_MODULE) 439 $(my_dexpreopt_jar_copy): $(LOCAL_BUILT_MODULE) 440 @cp $(PRIVATE_BUILT_MODULE) $@ 441 endif 442 443 # The root "product_packages.txt" is generated by `build/make/core/Makefile`. It contains a list 444 # of all packages that are installed on the device. We use `grep` to filter the list by the app's 445 # dependencies to create a per-app list, and use `rsync --checksum` to prevent the file's mtime 446 # from being changed if the contents don't change. This avoids unnecessary dexpreopt reruns. 447 my_dexpreopt_product_packages := $(intermediates)/product_packages.txt 448 .KATI_RESTAT: $(my_dexpreopt_product_packages) 449 $(my_dexpreopt_product_packages): PRIVATE_MODULE := $(LOCAL_MODULE) 450 $(my_dexpreopt_product_packages): PRIVATE_LIBS := $(my_dexpreopt_libs_all) 451 $(my_dexpreopt_product_packages): PRIVATE_STAGING := $(my_dexpreopt_product_packages).tmp 452 $(my_dexpreopt_product_packages): $(PRODUCT_OUT)/product_packages.txt 453 @echo "$(PRIVATE_MODULE) dexpreopt product_packages" 454 ifneq (,$(my_dexpreopt_libs_all)) 455 grep -F -x \ 456 $(addprefix -e ,$(PRIVATE_LIBS)) \ 457 $(PRODUCT_OUT)/product_packages.txt \ 458 > $(PRIVATE_STAGING) \ 459 || true 460 else 461 rm -f $(PRIVATE_STAGING) && touch $(PRIVATE_STAGING) 462 endif 463 rsync --checksum $(PRIVATE_STAGING) $@ 464 465 my_dexpreopt_script := $(intermediates)/dexpreopt.sh 466 .KATI_RESTAT: $(my_dexpreopt_script) 467 $(my_dexpreopt_script): PRIVATE_MODULE := $(LOCAL_MODULE) 468 $(my_dexpreopt_script): PRIVATE_GLOBAL_SOONG_CONFIG := $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE) 469 $(my_dexpreopt_script): PRIVATE_GLOBAL_CONFIG := $(DEX_PREOPT_CONFIG_FOR_MAKE) 470 $(my_dexpreopt_script): PRIVATE_MODULE_CONFIG := $(my_dexpreopt_config) 471 $(my_dexpreopt_script): PRIVATE_PRODUCT_PACKAGES := $(my_dexpreopt_product_packages) 472 $(my_dexpreopt_script): $(DEXPREOPT_GEN) 473 $(my_dexpreopt_script): $(my_dexpreopt_jar_copy) 474 $(my_dexpreopt_script): $(my_dexpreopt_config) $(DEX_PREOPT_SOONG_CONFIG_FOR_MAKE) $(DEX_PREOPT_CONFIG_FOR_MAKE) $(my_dexpreopt_product_packages) 475 @echo "$(PRIVATE_MODULE) dexpreopt gen" 476 $(DEXPREOPT_GEN) \ 477 -global_soong $(PRIVATE_GLOBAL_SOONG_CONFIG) \ 478 -global $(PRIVATE_GLOBAL_CONFIG) \ 479 -module $(PRIVATE_MODULE_CONFIG) \ 480 -dexpreopt_script $@ \ 481 -out_dir $(OUT_DIR) \ 482 -product_packages $(PRIVATE_PRODUCT_PACKAGES) 483 484 my_dexpreopt_deps := $(my_dex_jar) 485 my_dexpreopt_deps += $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE)) 486 my_dexpreopt_deps += \ 487 $(foreach lib, $(my_dexpreopt_libs_all), \ 488 $(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar) 489 my_dexpreopt_deps += $(my_dexpreopt_images_deps) 490 my_dexpreopt_deps += $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES) 491 ifeq ($(LOCAL_ENFORCE_USES_LIBRARIES),true) 492 my_dexpreopt_deps += $(intermediates)/enforce_uses_libraries.status 493 endif 494 495 # We need to add all the installed files to ALL_MODULES.$(my_register_name).INSTALLED in order 496 # for the build system to properly track installed files. (for sbom, installclean, etc) 497 # We install all the files in a zip file generated at execution time, which means we have to guess 498 # what's going to be in that zip file before it's created. We then check at executation time that 499 # our guess is correct. 500 # _system_other corresponds to OdexOnSystemOtherByName() in soong. 501 # The other paths correspond to dexpreoptCommand() 502 _dexlocation := $(patsubst $(PRODUCT_OUT)/%,%,$(LOCAL_INSTALLED_MODULE)) 503 _dexname := $(basename $(notdir $(_dexlocation))) 504 _system_other := $(strip $(if $(strip $(BOARD_USES_SYSTEM_OTHER_ODEX)), \ 505 $(if $(strip $(SANITIZE_LITE)),, \ 506 $(if $(filter $(_dexname),$(PRODUCT_DEXPREOPT_SPEED_APPS))$(filter $(_dexname),$(PRODUCT_SYSTEM_SERVER_APPS)),, \ 507 $(if $(strip $(foreach myfilter,$(SYSTEM_OTHER_ODEX_FILTER),$(filter system/$(myfilter),$(_dexlocation)))), \ 508 system_other/))))) 509 # _dexdir has a trailing / 510 _dexdir := $(_system_other)$(dir $(_dexlocation)) 511 my_dexpreopt_zip_contents := $(sort \ 512 $(foreach arch,$(my_dexpreopt_archs), \ 513 $(_dexdir)oat/$(arch)/$(_dexname).odex \ 514 $(_dexdir)oat/$(arch)/$(_dexname).vdex \ 515 $(if $(filter false,$(LOCAL_DEX_PREOPT_APP_IMAGE)),, \ 516 $(if $(my_process_profile)$(filter true,$(LOCAL_DEX_PREOPT_APP_IMAGE)), \ 517 $(_dexdir)oat/$(arch)/$(_dexname).art))) \ 518 $(if $(my_process_profile),$(_dexlocation).prof)) 519 _dexlocation := 520 _dexdir := 521 _dexname := 522 _system_other := 523 524 my_dexpreopt_zip := $(intermediates)/dexpreopt.zip 525 $(my_dexpreopt_zip): PRIVATE_MODULE := $(LOCAL_MODULE) 526 $(my_dexpreopt_zip): $(my_dexpreopt_deps) 527 $(my_dexpreopt_zip): | $(DEXPREOPT_GEN_DEPS) 528 $(my_dexpreopt_zip): .KATI_DEPFILE := $(my_dexpreopt_zip).d 529 $(my_dexpreopt_zip): PRIVATE_DEX := $(my_dex_jar) 530 $(my_dexpreopt_zip): PRIVATE_SCRIPT := $(my_dexpreopt_script) 531 $(my_dexpreopt_zip): PRIVATE_ZIP_CONTENTS := $(my_dexpreopt_zip_contents) 532 $(my_dexpreopt_zip): $(my_dexpreopt_script) 533 @echo "$(PRIVATE_MODULE) dexpreopt" 534 rm -f $@ 535 echo -n > $@.contents 536 $(foreach f,$(PRIVATE_ZIP_CONTENTS),echo "$(f)" >> $@.contents$(newline)) 537 bash $(PRIVATE_SCRIPT) $(PRIVATE_DEX) $@ 538 if ! diff <(zipinfo -1 $@ | sort) $@.contents >&2; then \ 539 echo "Contents of $@ did not match what make was expecting." >&2 && exit 1; \ 540 fi 541 542 $(foreach installed_dex_file,$(my_dexpreopt_zip_contents),\ 543 $(eval $(PRODUCT_OUT)/$(installed_dex_file): $(my_dexpreopt_zip) \ 544$(newline) unzip -qoDD -d $(PRODUCT_OUT) $(my_dexpreopt_zip) $(installed_dex_file))) 545 546 ALL_MODULES.$(my_register_name).INSTALLED += $(addprefix $(PRODUCT_OUT)/,$(my_dexpreopt_zip_contents)) 547 548 # Normally this happens in sbom.mk, which is included from base_rules.mk. But since 549 # dex_preopt_odex_install.mk is included after base_rules.mk, it misses these odex files. 550 $(foreach installed_file,$(addprefix $(PRODUCT_OUT)/,$(my_dexpreopt_zip_contents)), \ 551 $(eval ALL_INSTALLED_FILES.$(installed_file) := $(my_register_name))) 552 553 my_dexpreopt_config := 554 my_dexpreopt_config_for_postprocessing := 555 my_dexpreopt_jar_copy := 556 my_dexpreopt_product_packages := 557 my_dexpreopt_script := 558 my_dexpreopt_zip := 559 my_dexpreopt_zip_contents := 560endif # LOCAL_DEX_PREOPT 561endif # my_create_dexpreopt_config 562 563my_dexpreopt_libs_all := 564