Android中如何使用Android.mk模板-创新互联
这篇文章将为大家详细讲解有关Android中如何使用Android.mk模板,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
成都创新互联公司是专业的渭城网站建设公司,渭城接单;提供成都做网站、网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行渭城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!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模板就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
网站题目:Android中如何使用Android.mk模板-创新互联
URL分享:http://ybzwz.com/article/hpsgh.html