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, 内容如下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) LOCAL_MODULE := bar_a LOCAL_SRC_FILES := libbar_a.a include $(PREBUILT_STATIC_LIBRARY)d. 最后在需要使用外部库的Android.mk中加入
LOCAL_SHARED_LIBRARIES := foo_so bar_so LOCAL_STATIC_LIBRARIES := foo_a bar_a