1. jni開發時須要一個外部庫,這個庫要在最終打包時放在libs/armeabi目錄下,可是在每次編譯時ndk-build會更新libs/armeabi這個目錄,使得外部庫被刪除。每次使用時還須要再次copy,很麻煩。
在ndk-build的docs/PREBUILTS.html介紹了prebuilt,只須要很是簡單的幾步,就能夠在ndk-build時將外部庫
自動copy到libs/armeabi/目錄下。
步驟以下:
a. 在 jni目錄下新建目錄prebuilt(名字任意取)
b. 將外部庫libfoo_so.so libbar_so.so libfoo_a.a libbar_a.a放在新建的prebuilt目錄中
c. 在prebuilt目錄中建立Android.mk, 內容以下html
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo_so
LOCAL_SRC_FILES := libfoo-so.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bar_so
LOCAL_SRC_FILES := libbar_so.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo_a
LOCAL_SRC_FILES := libfoo_a.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)ui
LOCAL_MODULE := bar_a
LOCAL_SRC_FILES := libbar_a.ahtm
include $(PREBUILT_STATIC_LIBRARY) 開發
d. 最後在須要使用外部庫的Android.mk中加入
LOCAL_SHARED_LIBRARIES := foo_so bar_so
LOCAL_STATIC_LIBRARIES := foo_a bar_a編譯