1. 程式人生 > >內建帶so的APK為系統APK方法

內建帶so的APK為系統APK方法

(1)若內建為可解除安裝的APK,可以無需解壓出lib直接編譯就可以

具體參考http://blog.csdn.net/a462533587/article/details/46380795

(2)若內建為system APP,上述blog也有兩種方式:

方法一:

如下例,在Android.mk中新增並配置變數(注意路徑對應):

LOCAL_PREBUILT_JNI_LIBS = \
@lib/armeabi-v7a/libcryptox.so \
@lib/armeabi-v7a/libfb.so 
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

注意前面的 @符號,@識別符號會將apk中的so抽離出來,拷貝到對應編譯後的apk目錄;

78ifdef my_prebuilt_jni_libs
79
# Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk; 80# Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree. 81my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \ 82 $(filter @%, $(my_prebuilt_jni_libs)))
此處有對@lib的使用說明方法二:解壓出so
LOCAL_PREBUILT_JNI_LIBS = \
lib/armeabi-v7a/libcryptox.so \ lib/armeabi-v7a/libfb.so
當so較多可以遍歷每個so,使用如下語句###清空臨時變數JNI_LIBS JNI_LIBS:=###當前目錄遞迴搜尋$(foreach FILE,$(shell find $(LOCAL_PATH)/lib/ -name *.so), $(eval JNI_LIBS += $(FILE)))###獲取搜尋檔案目錄集(相對目錄)LOCAL_PREBUILT_JNI_LIBS:= $(subst $(LOCAL_PATH),,$(JNI_LIBS))
  • 1
  • 2
  • 3
但是我嘗試了方法一未成功,方法二可以,但是麻煩。當這類APK比較多時就很繁瑣,有沒有其他方法呢?

帶so的APK在編譯過程中會先解壓縮如out/target/product/msm8953_64/obj/APPS/LauncherB_intermediates/uncompressedlibs/lib/armeabi/libfacialproc_jni.so

intermediates := $(call local-intermediates-dir)這條語句就可以代替out/target/product/msm8953_64/obj/APPS/LauncherB_intermediates
然後再遍歷這個目錄下所有so,就可以copy到與編譯後的APK同級目錄下了