NDK 編譯和使用靜態庫、動態庫
NDK 編譯和使用靜態庫、動態庫
情況一:編譯靜態庫
情況二:編譯動態庫
情況三:編譯動態庫+靜態庫
情況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)
預設所有程式碼和檔案在$project/jni下,否則特殊說明。
情況一:編譯靜態庫
檔案Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_STATIC_LIBRARY)
檔案Application.mk:
APP_MODULES
情況二:編譯動態庫
檔案Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
情況三:編譯動態庫+靜態庫
檔案Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mylib_static
LOCAL_SRC_FILES := src.c
include $(BUILD_STATIC_LIBRARY
include $(CLEAR_VARS)
LOCAL_MODULE := mylib_shared
LOCAL_SRC_FILES := src2.c
LOCAL_STATIC_LIBRARIES:= mylib_static
include $(BUILD_SHARED_LIBRARY)
情況四:已有第三方靜態庫(動態庫),編譯靜態庫(動態庫)
檔案Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := thirdlib1 # name it whatever
LOCAL_SRC_FILES :=$(TARGET_ARCH_ABI)/libthird1.a
#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY) #or PREBUILT_SHARED_LIBRARY
include $(CLEAR_VARS)
LOCAL_MODULE := mylib_use_thirdlib
LOCAL_SRC_FILES := src.c
LOCAL_STATIC_LIBRARIES:= thirdlib1 #or LOCAL_SHARED_LIBRARY
include $(BUILD_SHARED_LIBRARY) #如果編譯靜態庫,需要Application.mk