Android.mk中的常见变量
LOCAL_PATH:= $(call my-dir) 用于返回当前路径
include $(CLEAR_VARS) 编译模块开始
include $(BUILD_XXX) 编译模块结束
include $(BUILD_PACKAGE) 编译生成apk
include $(BUILD_STATIC_LIBRARY) 编译成静态库
include $(BUILD_SHARED_LIBRARY) 编译成动态库
include $(BUILD_EXECUTABLE) 编译成可执行程序
LOCAL_MODULE_TAGS := optional
user: 指该模块只在user版本下才编译
eng: 指该模块只在eng版本下才编译
tests: 指该模块只在tests版本下才编译
optional: 指该模块在所有版本下都编译
LOCAL_CERTIFICATE := platform
LOCAL_CERTIFICATE 后面是签名文件的文件名,说明Settings.apk是一个需要platform key签名的APK
用于指定签名时使用的KEY,如果不指定,默认使用testkey,LOCAL_CERTIFICATE可设置的值如下:
LOCAL_CERTIFICATE := platform
LOCAL_CERTIFICATE := shared
LOCAL_CERTIFICATE := media
而在Android.mk中的这些配置,需要在APK源码的AndroidManifest.xml文件中的manifest节点添加如下内容:
android:sharedUserId="android.uid.system"
android:sharedUserId="android.uid.shared"
android:sharedUserId="android.media"
LOCAL_MODULE_PATH 和 LOCAL_UNSTRIPPED_PATH 指定最后的目标安装路径
TARGET_ROOT_OUT:表示根文件系统。
TARGET_OUT:表示 system文件系统。
TARGET_OUT_DATA:表示 data文件系统。
用法如:LOCAL_MODULE_PATH :=$(TARGET_ROOT_OUT)
复制一般文件,不能是APK
PRODUCT_COPY_FILES
$(call all-java-files-under, <src>) 获取指定目录下的所有 Java 文件。
$(call all-c-files-under, <src>) 获取指定目录下的所有 C 语言文件。
$(call all-Iaidl-files-under, <src>) 获取指定目录下的所有 AIDL 文件。
$(call all-makefiles-under, <folder>) 获取指定目录下的所有 Make 文件。
编译一个APK
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
#包含的静态库
LOCAL_STATIC_JAVA_LIBRARIES := libarity android-support-v4 guava
# 所有子目录下的java文件
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SDK_VERSION := current
# APK名字
LOCAL_PACKAGE_NAME := Calculator
#编译生成apk
include $(BUILD_PACKAGE)
预装第三方APK
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := LocalModuleName
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
编译一个c/c++动态库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := # 源文件
LOCAL_MODULE := name # 库的名字
LOCAL_SHARED_LIBRARIES := # 依赖的库
include $(BUILD_SHARED_LIBRARY)
编译一个java静态库
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := Hello.java
LOCAL_MODULE := Hello
include $(BUILD_STATIC_JAVA_LIBRARY)
编译一个java库
#编译一个java库 会生成Hello.jar
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := Hello.java
LOCAL_MODULE := Hello
include $(BUILD_JAVA_LIBRARY)
内置jar包
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE := lib/file name
include $(BUILD_PREBUILT)
编译一个可执行程序
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := \
libOpenSLES \
libandroidfw \
libbase \
libbinder \
libbootanimation \
libcutils \
liblog \
libutils \
LOCAL_SRC_FILES:= \
BootAnimationUtil.cpp \
LOCAL_MODULE:= bootanimation
include $(BUILD_EXECUTABLE)