首先,把第三方 class jar 包生成 .dex jar,如 test-1.0.0.1.jar
dx --dex --output=dex/test-1.0.0.1.jar class/test-1.0.0.1.jar
第一种方案:
(1)编译Android源码系统,生成不带 .odex 优化的 image,参见 Ubuntu 18.04编译Android8.1 automotive
make WITH_DEXPREOPT=false DISABLE_DEXPREOPT=true -j8
(2)第一步生成的 test-1.0.0.1.jar 复制到 system/framework 目录下 make snod 重新打包 system.img
cp dex/test-1.0.0.1.jar out/target/product/generic_x86/system/framework/
make snod
(3)更改 out/target/product/generic_x86/root/init.environ.rc 文件 export BOOTCLASSPATH=,增加 /system/framework/test-1.0.0.1.jar
export BOOTCLASSPATH /system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/test-1.0.0.1.jar
(4)mkbootfs 重新打包 out/target/product/generic_x86/root 目录为 ramdisk.img
mkbootfs out/target/product/generic_x86/root/ | gzip > out/target/product/generic_x86/ramdisk.img
(5)emulator 运行新 img 镜像
注:如果测试没有加载进系统,删除 cache.img 和 userdata-qemu.img 重试
第二种方案:
(1)源码 framework/opt 目录新建文件夹 test,第一步生成的 test-1.0.0.1.jar 复制到此目录,并新建立 Android.mk,写法如下
LOCAL_PATH := $(call my-dir)
#test-1.0.0.1.jar
include $(CLEAR_VARS)
LOCAL_MODULE := test-1.0.0.1
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := test-1.0.0.1.jar
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
include $(BUILD_PREBUILT)
(2)build/target/product/core_minimal.mk 或 build/target/product/core_base.mk 文件 PRODUCT_PACKAGES += 和 PRODUCT_BOOT_JARS := 末尾分别增加 test-1.0.0.1 (上一步 LOCAL_MODULE := 的定义值)
# The order of PRODUCT_BOOT_JARS matters.
PRODUCT_BOOT_JARS := \
core-libart \
conscrypt \
okhttp \
core-junit \
bouncycastle \
ext \
framework \
telephony-common \
voip-common \
ims-common \
apache-xml \
org.apache.http.legacy.boot \
test-1.0.0.1
(3)修改 build/core/tasks/check_boot_jars/package_whitelist.txt,文件末尾增加 test-1.0.0.1.jar 包名,如:
###################################################
# test-1.0.0.1.jar
com\.king\.test\..*
(4)源码根目录执行系统 make 或在已经编译过的源码目录 framework/opt/test 执行 mmm 编译生成新系统 img 镜像
#全源码编译
make -j8
#单模块编译
make test-1.0.0.1
#或模块目录
mmm
(5)emulator 运行新 img 镜像