Android.mk是什么?
Android.mk是用于控制Android代码的编译流程,用shell编写
Android.mk结构
设置当前路径
除带#的注释,Android.mk第一句话都是
LOCAL_PATH := $(call my-dir)
即将my-dir方法的返回值赋值给LOCAL_PATH,让其等于当前目录,其中的my-dir方法在build/core/defintions.mk中定义,源码如下
###########################################################
## Retrieve the directory of the current makefile
## Must be called before including any other makefile!!
###########################################################
# Figure out where we are.
define my-dir
$(strip \
$(eval LOCAL_MODULE_MAKEFILE := $$(lastword $$(MAKEFILE_LIST))) \
$(if $(filter $(BUILD_SYSTEM)/% $(OUT_DIR)/%,$(LOCAL_MODULE_MAKEFILE)), \
$(error my-dir must be called before including any other makefile.) \
, \
$(patsubst %/,%,$(dir $(LOCAL_MODULE_MAKEFILE))) \
) \
)
endef
清空所有LOCAL变量
接下来是
include $(CLEAR_VARS)
CLEAR_VARS的值在/build/core/config.mk,源码如下:
CLEAR_VARS := $(BUILD_SYSTEM)/clear_vars.mk
BUILD_SYSTEM在/build/core/cleanbuild.mk及/build/core/config.mk中均有定义,源码如下:
BUILD_SYSTEM := $(TOPDIR)build/core
TOPDIR为空,所以BUILD_SYSTEM:=build/core,故CLEAR_VARS=build/core/clear_vars.mk,其内容为清空所有LOCAL变量,部分源码如下:
###########################################################
## Clear out values of all variables used by rule templates.
###########################################################
# '',true
LOCAL_2ND_ARCH_VAR_PREFIX:=
LOCAL_32_BIT_ONLY:=
LOCAL_AAPT2_ONLY:=
LOCAL_AAPT_FLAGS:=
LOCAL_AAPT_INCLUDE_ALL_RESOURCES:=
LOCAL_AAPT_NAMESPACES:=
LOCAL_ADDITIONAL_CERTIFICATES:=
LOCAL_ADDITIONAL_CHECKED_MODULE:=
LOCAL_ADDITIONAL_DEPENDENCIES:=
LOCAL_ADDITIONAL_HTML_DIR:=
LOCAL_ADDITIONAL_JAVA_DIR:=
重新设置LOCAL变量
接下来是为自己的代码设置编译流程,常用的变量及取值有
变量 | 取值及意义 |
---|---|
LOCAL_PACKAGE_NAME | 包名,自定义 |
LOCAL_MODULE_TAGS | optional |
LOCAL_SRC_FILES | $(call all-java-files-under, src) |
LOCAL_STATIC_JAVA_LIBRARIES | android-support-v4 |
LOCAL_JAVA_LIBRARIES | |
LOCAL_CERTIFICATE | platform |
LOCAL_SDK_VERSION | current |
LOCAL_PRODUCT_MODULE | true |
LOCAL_OVERRIDES_PACKAGES | |
LOCAL_STATIC_ANDROID_LIBRARIES | \ android-support-v7-appcompat \ android-support-v7-recyclerview |
选择构建方式
接下来是为自己的代码设置构建方法,常用的构建方式及意义有文章来源:https://www.toymoban.com/news/detail-704479.html
构建方式 | 意义 |
---|---|
include $(BUILD_PACKAGE) |
构建为app BUILD_PACKAGE的值在/build/core/config.mk BUILD_PACKAGE := $(BUILD_SYSTEM)/package.mk 意为引进build/core/package.mk为程序打包 |
调用当前目录下的所有mk文件
include $(call all-makefiles-under,$(LOCAL_PATH))
all-makefiles-under方法在在build/core/defintions.mk中定义,源码如下文章来源地址https://www.toymoban.com/news/detail-704479.html
到了这里,关于AOSP——Android.mk解析的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!