Android 之永乐大典
DexOpt
Android DexOpt前世今生:参考https://blog.csdn.net/dengtonglong/article/details/140828809
1 dex_preopt_check导致编译报错
问题背景
高通T项目,更新google mainline到6月份,编译nogms版本出现如下异常
报错日志
[2024-12-14T10:08:45.533Z] build/make/core/tasks/dex_preopt_check.mk:13: warning: Missing compilation artifacts. Dexpreopting is not working for some system server jars
[2024-12-14T10:08:45.533Z] Offending entries:
[2024-12-14T10:08:45.533Z] system/framework/oat/arm64/apex@com.android.adservices@javalib@service-adservices.jar@classes.odex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.adservices@javalib@service-adservices.jar@classes.vdex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.adservices@javalib@service-sdksandbox.jar@classes.odex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.adservices@javalib@service-sdksandbox.jar@classes.vdex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.appsearch@javalib@service-appsearch.jar@classes.odex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.appsearch@javalib@service-appsearch.jar@classes.vdex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.media@javalib@service-media-s.jar@classes.odex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.media@javalib@service-media-s.jar@classes.vdex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.os.statsd@javalib@service-statsd.jar@classes.odex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.os.statsd@javalib@service-statsd.jar@classes.vdex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.tethering@javalib@service-connectivity.jar@classes.odex
[2024-12-14T10:08:45.534Z] system/framework/oat/arm64/apex@com.android.tethering@javalib@service-connectivity.jar@classes.vdex
[2024-12-14T10:08:45.534Z] In file included from build/make/core/main.mk:1479:
[2024-12-14T10:08:45.534Z] In file included from build/make/core/Makefile:6977:
[2024-12-14T10:08:45.534Z] build/make/core/tasks/dex_preopt_check.mk:13: error: Build failed.
[2024-12-14T10:08:45.534Z] 18:08:45 ckati failed with: exit status 1
问题分析
如下编译脚本逻辑,这里通过DISABLE_DEXPREORT_CHECK宏控来失能是否进行DEXPREOPT优化检测,如果为true则失能,默认需要进行优化检测,通过过滤所有PRODUCT_PACKAGES安装的应用,即先过滤ALL_DEFAULT_INSTALLED_MODULES宏控指定列表里面的应用,然后在过滤DEXPREOPT_SYSTEMSERVER_ARTIFACTS列表中指定的需要dexpreort优化的系统jar。
/system/build/make/core/tasks/dex_preopt_check.mk
# Checks that some critical dexpreopt output files are installed.
# Inputs:
# DISABLE_DEXPREOPT_CHECK: True if the check should be disabled.
# PRODUCT_PACKAGES: The list of packages to be installed for the product.
# ALL_DEFAULT_INSTALLED_MODULES: The full list of modules going to be installed.
# DEXPREOPT_SYSTEMSERVER_ARTIFACTS: The list of compilation artifacts of system server jars, which
# is generated by Soong in dexpreopt_check.go.
ifneq (true,$(DISABLE_DEXPREOPT_CHECK))
# Skip the check if the system server is not installed for the product.
ifneq (,$(filter services,$(PRODUCT_PACKAGES)))
$(call maybe-print-list-and-error,\
$(filter-out $(ALL_DEFAULT_INSTALLED_MODULES),$(DEXPREOPT_SYSTEMSERVER_ARTIFACTS)),\
Missing compilation artifacts. Dexpreopting is not working for some system server jars \
)
endif
endif
出现上面报错可能的原因,google官方网站已经介绍:
搜索systemserverclasspath_fragment可以看到mainline多个模块都配置了优化
解决方案
- 配置DISABLE_DEXPREORT_CHECK = true使能dexpreopt检查,但是一般不建议
- 取消systemserverclasspath_fragment相关配置,但是针对系统应用一般也不建议,这里的问题为apks本身的问题,更新mainline解决