1. Androidmk写法
预编译时使用LOCAL_PREBUILT_JNI_LIBS,来制定库的路径
LOCAL_PATH := $(call my-dir)
define get-all-libraries-module-name-in-subdirs
$(sort $(shell cd $(LOCAL_PATH) ; find -L $(1) -name "*.so"))
endef
ALL_LIBRARIES_MODULE_NAME := $(call get-all-libraries-module-name-in-subdirs, lib/arm64-v8a)
$(warning ALL_LIBRARIES_MODULE_NAME:--- $(ALL_LIBRARIES_MODULE_NAME) )
#integrate the apk
include $(CLEAR_VARS)
LOCAL_MODULE := BinderTest
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_SUFFIX := .apk
LOCAL_SRC_FILES := ./BinderTest.apk
LOCAL_MULTILIB := 64
LOCAL_MODULE_PATH := $(TARGET_OUT_SYSTEM_APPS)
LOCAL_PREBUILT_JNI_LIBS := $(ALL_LIBRARIES_MODULE_NAME)
include $(BUILD_PREBUILT)
2. 编译结果
编译log看,只是把库拷贝到system/app/BinderTest/lib下面,并没有预制到system/lib64,这才是正确的预制方法
[ 82% 51/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libplug_ins_project.so
[ 83% 52/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libdumpcrash.so
[ 83% 52/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libsync_cxx.so
[ 85% 53/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libifly_aime.so
[ 85% 53/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libtbt.so
[ 87% 54/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libGNaviDice.so
[ 88% 55/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/liblinkProxy-1.0.0.so
[ 90% 56/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libplug_ins_project.so
[ 91% 57/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libmqtt_jni.so
[ 93% 58/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libsync_cxx.so
[ 95% 59/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libisstts.so
[ 96% 60/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libhsl.so
[ 98% 61/62] Copy: out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64/libtbt.so
[ 98% 61/62] Install: out/target/product/msm8996_gvmq/system/app/BinderTest/BinderTest.apk
[100% 62/62] Install: out/target/product/msm8996_gvmq/system/app/BinderTest/BinderTest.apk
out目录看,apk拷贝到了app/lib下面,这样apk就是用这个位置的库
android/out/target/product/msm8996_gvmq/system/app/BinderTest ls
BinderTest.apk lib oat
ubuntu@ubuntu:/android/out/target/product/msm8996_gvmq/system/app/BinderTest/lib/arm64$ ll
-rwxrwxr-x 1 ubuntu ubuntu 1738664 11月 15 17:10 libxxx.so*
-rwxrwxr-x 1 ubuntu ubuntu 1354248 11月 15 17:10 libxxxxxx.so*
-rwxrwxr-x 1 ubuntu ubuntu 1243400 11月 15 17:10 libaime_key_gd.so*
-rwxrwxr-x 1 ubuntu ubuntu 59720 11月 15 17:10 libapssdk.so*
3. LOCAL_PREBUILT_JNI_LIBS原理
LOCAL_PREBUILT_JNI_LIBS := \
lib/armeabi/libcom_iflytek_inputmethod_bundlesetting.so \
lib/armeabi/libcom_iflytek_inputmethod_mmp.so \
原理就是调用copy-one-file,把LOCAL_PREBUILT_JNI_LIBS的值循环拷贝到app/lib下面
@build/core/install_jni_libs.mk
my_prebuilt_jni_libs := $(LOCAL_PREBUILT_JNI_LIBS)
@build/core/install_jni_libs_internal.mk
# Install my_prebuilt_jni_libs as separate files.
$(foreach lib, $(my_prebuilt_jni_libs), \
$(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))