這篇文章主要介紹了Android中怎么使用Android.mk模板的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇Android中怎么使用Android.mk模板文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。
創(chuàng)新互聯(lián)公司是一家專業(yè)從事網(wǎng)站制作、做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)的品牌網(wǎng)絡(luò)公司。如今是成都地區(qū)具影響力的網(wǎng)站設(shè)計(jì)公司,作為專業(yè)的成都網(wǎng)站建設(shè)公司,創(chuàng)新互聯(lián)公司依托強(qiáng)大的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營(yíng)經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、營(yíng)銷型網(wǎng)站建設(shè)及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!Android開發(fā)之Android.mk模板的實(shí)例詳解
1. 如何自動(dòng)添加需要編譯的源文件列表
2. 如何添加第三方靜態(tài)庫(kù)、動(dòng)態(tài)庫(kù)的依賴
3. 如何構(gòu)造一個(gè)完整的NDK工程框架
假設(shè)我們的項(xiàng)目依賴 libmath.a, libjson.a, libffmpeg.so 這幾個(gè)第三方庫(kù)文件,項(xiàng)目包含如下幾個(gè)模塊:algorithm,core,network,utils,tests,每個(gè)模塊都有若干個(gè).c/.h文件,我們要把整個(gè)工程編譯為動(dòng)態(tài)庫(kù),并通過(guò) native_sdk.c 中的函數(shù)向Java層提供調(diào)用接口。
那么,我們可以對(duì) Android 工程的 jni 目錄,做如下劃分:
對(duì)應(yīng)的 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)
關(guān)于“Android中怎么使用Android.mk模板”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“Android中怎么使用Android.mk模板”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。