framework调用第三方的Jar包

出處: https://blog.csdn.net/jack_liu_2008/article/details/49764131

工作中碰到需要在framework中调用第三方的jar包中的函数

在源码环境下,按照下面的步骤即可实现:

1 在源码frameworks/opt/中创建文件夹demo, 将第三方的demo.jar拷贝拷贝到该目录下,同时在该目录下创建Android.mk (参考android2.1)

LOCAL_PATH := $(my-dir)

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := myjar:demo.jar

include $(BUILD_MULTI_PREBUILT)

“myjar” 只是一个标示名,可以用任意命名替换,该名称在下面步骤中会用到

2 将demo.jar编译到源码环境中
执行命令:mmm framework/opt/demo/
编译之后会生成
out/target/product/xxx/obj/JAVA_LIBRARIES/demo_intermediates/javalib.jar

3 在framework加入demo.jar,需要修改framework/base/Android.mk:

# Build ext.jar
# ============================================================

# NOTICE notes for non-obvious sections
# apache-http - covered by the Apache Commons section.


ext_dirs := \
    ../../external/nist-sip/java \
    ../../external/apache-http/src \
    ../../external/tagsoup/src \
    ../../external/libphonenumber/java/src

ext_src_files := $(call all-java-files-under,$(ext_dirs))

ext_res_dirs := \
    ../../external/libphonenumber/java/src

# ====  the library  =========================================
include $(CLEAR_VARS)

LOCAL_SRC_FILES := $(ext_src_files)

LOCAL_NO_STANDARD_LIBRARIES := true
LOCAL_JAVA_LIBRARIES := core
LOCAL_JAVA_RESOURCE_DIRS := $(ext_res_dirs)
LOCAL_STATIC_JAVA_LIBRARIES := myjar 增加该行,myjar是步骤1中的标示名
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := ext

LOCAL_DX_FLAGS := --core-library

include $(BUILD_JAVA_LIBRARY)

4 将demo.jar编译到framework中
执行命令: mmm framework/base/
会更新3个系统jar包
out/target/product/xxx/system/framework/ext.jar
out/target/product/xxx/system/framework/framework.jar
out/target/product/xxx/system/framework/framework2.jar

需要注意:
编译的中间文件会存在下列目录中
out/target/common/obj/JAVA_LIBRARIES/demo_intermediates/
out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/xxx
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/xxx
out/target/common/obj/JAVA_LIBRARIES/framework2_intermediates/xxx
out/target/product/xxx/obj/JAVA_LIBRARIES/demo_intermediates/javalib.jar
out/target/product/xxx/obj/JAVA_LIBRARIES/ext_intermediates/javalib.jar
out/target/product/xxx/obj/JAVA_LIBRARIES/framework_intermediates/javalib.jar
out/target/product/xxx/obj/JAVA_LIBRARIES/framework2_intermediates/javalib.jar
如果调试中不想打包第三方的Jar包时,需要手动删除上述目录/文件,再重新编译。

经过上述步骤,就可以在framework调用demo.jar包中函数了。

未經允許不得轉載:GoMCU » framework调用第三方的Jar包

評論 搶沙發

  • 昵稱 (必填)
  • 郵箱 (必填)
  • 網址