平台
RK3288 + Android 7.1
概述
增加供第三方式应用调用的SDK接口, 并以JAR包的方式提供全应用开发者.
实现
增加JAVA代码并编写Android MK
Android.mk, JAVA 代码忽略
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional #LOCAL_NO_STANDARD_LIBRARIES := true LOCAL_JAVA_LIBRARIES := core-oj core-libart framework LOCAL_SRC_FILES := $(call all-java-files-under, java) LOCAL_MODULE := sdkapi #LOCAL_DX_FLAGS := --core-library include $(BUILD_JAVA_LIBRARY)
修改源码MK文件, 增加编译模块sdkapi
diff --git a/build/target/product/core_minimal.mk b/build/target/product/core_minimal.mk index 4674add..cc4a08b 100755 --- a/build/target/product/core_minimal.mk +++ b/build/target/product/core_minimal.mk @@ -100,7 +100,10 @@ PRODUCT_BOOT_JARS := \ voip-common \ ims-common \ apache-xml \ org.apache.http.legacy.boot \ + sdkapi \
重新source后,编译模块mmm frameworks/base/sdkapi/
android@server:~/codes/rk3288_n712$ ll out/target/common/obj/JAVA_LIBRARIES/sdkapi_intermediates/ total 56 drwxrwxr-x 4 android android 4096 10月 26 10:56 ./ drwxrwxr-x 329 android android 20480 10月 26 10:55 ../ -rw-rw-r-- 1 android android 4492 10月 26 10:56 classes.dex -rw-rw-r-- 1 android android 6922 10月 26 10:56 classes.jack -rw-rw-r-- 1 android android 0 10月 26 10:56 jack_res_jar_flags drwxrwxr-x 2 android android 4096 10月 26 10:56 jack-rsc/ -rw-rw-r-- 1 android android 78 10月 26 10:55 jack-rsc.java-source-list -rw-rw-r-- 1 android android 2745 10月 26 10:56 javalib.jar drwxrwxr-x 2 android android 4096 10月 26 10:56 with-local/
未找到相应可用JAR包(classes.jar), 重新执行make
[ 27% 29/107] Check package name for out/target/common/obj/JAVA_LIBRARIES/cor...sses.jar out/target/common/obj/JAVA_LIBRARIES/xsapi_intermediates/classes.jar FAILED: /bin/bash -c "(build/core/tasks/check_boot_jars/check_boot_jars.py build/core/tasks/check_boot_jars/package_whitelist.txt out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/core-junit_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/openapi_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/voip-common_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/ims-common_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/org.apache.http.legacy.boot_intermediates/classes.jar out/target/common/obj/JAVA_LIBRARIES/sdkapi_intermediates/classes.jar ) && (mkdir -p out/target/common/obj/PACKAGING/boot-jars-package-check_intermediates/ && touch out/target/common/obj/PACKAGING/boot-jars-package-check_intermediates/stamp )" Error: out/target/common/obj/JAVA_LIBRARIES/sdkapi_intermediates/classes.jar: unknown package name of class file com/sdkapi/tools/DeviceApi.class
编译出错, LOG中的信息有三点
build/core/tasks/check_boot_jars/package_whitelist.txt
out/target/common/obj/JAVA_LIBRARIES/sdkapi_intermediates/classes.jar
unknown package name of class file com/sdkapi/tools/DeviceApi.class
第三点说明编译时找不到类, 经查证后, 发现跟第 1 点的文件相关.
修改
android@server:~/codes/rk3288_n712$ git diff build diff --git a/build/core/tasks/check_boot_jars/package_whitelist.txt b/build/core/tasks/check_boot_jars/package_whitelist.txt old mode 100644 new mode 100755 index 3cb6e28..46870a9 --- a/build/core/tasks/check_boot_jars/package_whitelist.txt +++ b/build/core/tasks/check_boot_jars/package_whitelist.txt @@ -109,7 +109,8 @@ dalvik\..* libcore\..* android\..* com\.android\..* - +com\.sdkapi\.tools ################################################### # core-junit.jar
增加 com.sdkapi.tools 到白名单后, 再次执行make, 编译成功.
查看输出文件
android@server:~/codes/rk3288_n712$ ll out/target/common/obj/JAVA_LIBRARIES/sdkapi_intermediates/ total 72 drwxrwxr-x 5 android android 4096 10月 26 11:00 ./ drwxrwxr-x 330 android android 20480 10月 26 11:00 ../ drwxrwxr-x 3 android android 4096 10月 26 11:00 classes/ -rw-rw-r-- 1 android android 4492 10月 26 10:56 classes.dex -rw-rw-r-- 1 android android 3290 10月 26 11:00 classes-full-debug.jar -rw-rw-r-- 1 android android 6922 10月 26 10:56 classes.jack -rw-rw-r-- 1 android android 3290 10月 26 11:00 classes.jar -rw-rw-r-- 1 android android 3290 10月 26 11:00 classes-jarjar.jar -rw-rw-r-- 1 android android 0 10月 26 10:56 jack_res_jar_flags drwxrwxr-x 2 android android 4096 10月 26 10:56 jack-rsc/ -rw-rw-r-- 1 android android 78 10月 26 10:55 jack-rsc.java-source-list -rw-rw-r-- 1 android android 2745 10月 26 10:56 javalib.jar drwxrwxr-x 2 android android 4096 10月 26 10:56 with-local/
将classes.jar文件拷贝出来发送给应用开发人员即可.
扩展
android 修改新增jar 路径
Android6.0上frameworks增加代码编译错误
[android6.0]添加System Jar记录