您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Android中如何使用Android.mk模板,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
Android開發之Android.mk模板的實例詳解
1. 如何自動添加需要編譯的源文件列表
2. 如何添加第三方靜態庫、動態庫的依賴
3. 如何構造一個完整的NDK工程框架
假設我們的項目依賴 libmath.a, libjson.a, libffmpeg.so 這幾個第三方庫文件,項目包含如下幾個模塊:algorithm,core,network,utils,tests,每個模塊都有若干個.c/.h文件,我們要把整個工程編譯為動態庫,并通過 native_sdk.c 中的函數向Java層提供調用接口。
那么,我們可以對 Android 工程的 jni 目錄,做如下劃分:
對應的 Android.mk 文件的寫法示例如下(注:工程文件可以到我的Github(@Jhuster/Android)中在線查看,也可以在本博文最后的附件中下載):
LOCAL_PATH := $(call my-dir) 3RD_INC_DIR = $(LOCAL_PATH)/3rd/inc 3RD_LIB_DIR = $(LOCAL_PATH)/3rd/libs # Prebuild the 3rd libraries include $(CLEAR_VARS) LOCAL_MODULE := math LOCAL_SRC_FILES := $(3RD_LIB_DIR)/libmath.a include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := json LOCAL_SRC_FILES := $(3RD_LIB_DIR)/libjson.a include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := ffmpeg LOCAL_SRC_FILES := $(3RD_LIB_DIR)/libffmpeg.so include $(PREBUILT_SHARED_LIBRARY) # Build native sdk include $(CLEAR_VARS) LOCAL_MODULE := native_sdk LOCAL_SRC_FILES := \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/algorithm/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/core/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/network/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/utils/*.c)) \ $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/src/*.c)) LOCAL_C_INCLUDES := $(3RD_INC_DIR) LOCAL_C_INCLUDES := $(LOCAL_PATH)/src LOCAL_C_INCLUDES := $(LOCAL_PATH)/src/algorithm LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/core LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/network LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/utils LOCAL_CFLAGS := -DANDROID LOCAL_LDLIBS := -llog LOCAL_STATIC_LIBRARIES := math json LOCAL_SHARED_LIBRARIES := ffmpeg include $(BUILD_SHARED_LIBRARY) # Build tests include $(CLEAR_VARS) LOCAL_MODULE := test.out LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/tests/*.c)) LOCAL_CFLAGS := -DANDROID LOCAL_C_INCLUDES := $(LOCAL_PATH)/src LOCAL_LDLIBS := -llog -fPIE -pie LOCAL_SHARED_LIBRARIES:= native_sdk include $(BUILD_EXECUTABLE)
關于Android中如何使用Android.mk模板就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。