android编译系统的makefile文件Android.mk写法如下
(1) Android.mk文件首先需要指定LOCAL_PATH变量,用于查找源文件。由于一般情况下
Android.mk和需要编译的源文件在同一目录下,宏函数“my-dir”右编译系统提供的,用于返回当前路径。所以定义成如下形式:
LOCAL_PATH:=$(call my-dir)
上面的语句的意思是将LOCAL_PATH变量定义成本文件所在目录路径。
(2) Android.mk中可以定义多个编译模块,每个编译模块都是以include $(CLEAR_VARS)开始
以include $(BUILD_XXX)结束。
include $(CLEAR_VARS)
CLEAR_VARS由编译系统提供,指定让GNUMAKEFILE为你清除除LOCAL_PATH以外的所有LOCAL_XXX变量,
如LOCAL_MODULE,LOCAL_SRC_FILES,LOCAL_SHARED_LIBRARIES,LOCAL_STATIC_LIBRARIES等。
include $(BUILD_STATIC_LIBRARY)表示编译成静态库
include $(BUILD_SHARED_LIBRARY)表示编译成动态库。
include $(BUILD_EXECUTABLE)表示编译成可执行程序
(3) LOCAL_MODULE_TAGS:= optional
(4) LOCAL_MODULE_TAGS :=user eng tests optional
(5) user: 指该模块只在user版本下才编译
(6) eng: 指该模块只在eng版本下才编译
(7) tests: 指该模块只在tests版本下才编译
(8) optional:指该模块在所有版本下都编译
(9)
(10) LOCAL_SRC_FILES:编译的源代码文件列表 添加所有的java 源文件LOCAL_SRC_FILES:= $(call all-java-files-under, src)
(11) LOCAL_SDK_VERSION := current
(12) LOCAL_MODULE:= jar 包名称
(13) LOCAL_PACKAGE_NAME := APK包的名称
(14) LOCAL_JAVA_LIBRARIES := platform core ext依赖的共享jar
(15) LOCAL_STATIC_JAVA_LIBRARIES:=依赖的静态jar包(jar包是使用 include $(BUILD_STATIC_JAVA_LIBRARY)生成的。)
(16) LOCAL_CERTIFICATE:签名认证
(17) 1.系统中所有使用android.uid.system作为共享UID的APK,都会首先在manifest节点中增加android:sharedUserId="android.uid.system",然后在Android.mk中增加LOCAL_CERTIFICATE:= platform。 2. 系统中所有使用android.uid.shared作为共享UID的APK,都会在manifest节点中增加android:sharedUserId="android.uid.shared",然后在Android.mk中增加LOCAL_CERTIFICATE:= shared。 3.系统中所有使用android.media作为共享UID的APK,都会在manifest节点中增加android:sharedUserId="android.media",然后在Android.mk中增加LOCAL_CERTIFICATE:= media
(18) 编译一个应用程序(APK)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)
(19) 编译静态库
#清除java环境变量
include$(CLEAR_VARS)
LOCAL_MODULE_TAGS:= user
#添加aidl文件
LOCAL_SRC_FILES+= src/net/sunniwell/download/aidl/IDownload.aidl
# SDK 版本
LOCAL_SDK_VERSION:= current
#jar包的名字
LOCAL_MODULE:=DownLoadServerapi
#编译 DownLoadServerapi jar包
include $(BUILD_STATIC_JAVA_LIBRARY)
(20) 编译一个依赖于静态Java库(static.jar)的应用程序
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# List of static libraries to include in the package
LOCAL_STATIC_JAVA_LIBRARIES := DownLoadServerapi 第三方jar包
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)
(21) 编译一个需要用平台的key签名的应用程序
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := platform
# Tell it to build an APK
include $(BUILD_PACKAGE)
(22) 添加一个静态JAVA库
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Any libraries that this library depends on
LOCAL_JAVA_LIBRARIES := android.test.runner
# The name of the jar file to create
LOCAL_MODULE := sample
# Build a static jar file.
include $(BUILD_STATIC_JAVA_LIBRARY)
(23) 引用第三方JAR包方式
#引入第三方包
include $(CLEAR_VARS)
# 表示在当前目录下的lib/iptv.jar进行预处理到android jar包的目录中去
#LOCAL_PREBUILT_JAVA_LIBRARIES := libiptv:lib/iptv.jar
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
libiptv:lib/iptv.jar
include $(BUILD_MULTI_PREBUILT)
需要在编译apk 中进行、并添加
LOCAL_STATIC_JAVA_LIBRARIES := libiptv