前提:客制化定制的接口封装在public class TestCustom 保存在 TestCustom.java文件中
路径:custom/java/com/test/custom/TestCustom.java
package: com.test.custom
步骤:
把目录custom 拷贝到 framework/base/ 下
打开framework/base/Android.mk 可以看到 LOCAL_MODULE := framework 这个关键位置再去找对应的LOCAL_SRC_FILES
# FRAMEWORKS_BASE_SUBDIRS comes from build/core/pathmap.mk
LOCAL_SRC_FILES := \
$(call find-other-java-files,$(FRAMEWORKS_BASE_SUBDIRS)) \
$(call all-proto-files-under, core/proto)
通过改FRAMEWORKS_BASE_SUBDIRS 这个参数让客制化模块添加进LOCAL_SRC_FILES从而编译进 framework jar包中
打开build/core/pathmap.mk文件 找到FRAMEWORKS_BASE_SUBDIRS :=,
在末尾加入:
custom \
这个时候直接编译 Android会报异常:
Error: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar contains class file com/test/custom/TestCustom.class, which is not in the whitelist
打开build/core/tasks/check_boot_jars/package_whitelist.txt文件
在文件末尾加入:
##################################################
# Packages in the custom
com\.test\.custom.*
修改完后在编译结束后可在 \out\target\common\obj\JAVA_LIBRARIES\framework_intermediates\classes 目录下找到对应的 .class 文件