Android Makefile

Android.mk 是什么

Android.mk是像NDK构建系统描述NDK项目的GNU makefile片段

1.apk
2.jar
3.可执行程序
4. .a
5. .so
Android.mk组成
#定义模块的当前路径(必须定义在开头,只需要定义一次)
LOCAL_PATH := $(call my-dir) //my-dir宏函数返回的是当前mk的路径
#情况当前的环境变量(LOCAL_PATH除外的以"LOCAL_"开头的变量)
include $(CLEAR_VARS)
#当前模块的名称
LOCAL_MODULE := hello-jni
#当前模块包含的源文件
LOCAL_SRC_FILES := hello-jni.c
#指定当前被编译为共享库
include $(BUILD_SHARED_LIBRARY)
生成多个共享库
LOCAL_PATH =  $(call my-dir)

#模块1
include $(CLEAR_VARS)
LOCAL_MODULE := module1
LOCAL_SRC_FILES := module1.c
include $(BUILD_SHARED_LIBRARY)
#模块2
include $(CLEAR_VARS)
LOCAL_MODULE := module2
LOCAL_SRC_FILES := module2.c
include $(BUILD_SHARED_LIBRARY)
编译静态库
LOCAL_PATH := $(call my-dir)
#编译静态库
include $(CLEAR_VARS)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c
include $(BUILD_STATIC_LIBRARY)

#使用静态库
include $(CLEAR_VARS)
LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c
LOCAL_STATIC_LIBRARIES := avilib
include $(BUILD_SHARED_LIBRARY)
使用共享库共享通用模块
 LOCAL_PATH := $(call my-dir)
#通过共享库 共享通用模块
include $(CLEAR_VARS)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c
include $(BUILD_SHARED_LIBRARY)

#使用共享库
include $(CLEAR_VARS)
LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c
LOCAL_SHARED_LIBRARIES := avilib
include $(BUILD_SHARED_LIBRARY)

#使用共享库
include $(CLEAR_VARS)
LOCAL_MODULE := module1
LOCAL_SRC_FILES := module1.c
LOCAL_SHARED_LIBRARIES := avilib
include $(BUILD_SHARED_LIBRARY)
多个项目之间共享模块
#avilib模块有自己的mk文件
#该项目在transcode/avilib下
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := avilib.c platform_posix.c
include $(BULID_SHARED_LIBRYA)

#项目1使用共享库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := module
LOCAL_SRC_FILES := module.c
LOCAL_SHARED_LIBRARIES := avilib
include $(BUILD_SHARED_LIBRARY)
$(call import-module,transcode/lib)

#项目2使用共享库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := module1
LOCAL_SRC_FILES := module1.c
LOCAL_SHARED_LIBRARIES := avilib
include $(BUILD_SHARED_LIBRARY)
$(call import-module,transcode/lib)



NDK_MODULE_PATH的环境变量 ,便于寻找lib
使用预编译库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := libavilib.so
include $(PREBUILD_SHARED_LIBRARY)
编译可执行文件
include $(BUILD_EXCUTABLE)
android studio 中使用ndk-build
1.静态映射  Java_包名_类名_方法名
2.gradle中配置 ndkfilter   ndkbuild
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值