http://source.android.com/porting/build_cookbook.html
Android的Build Cookbook提供代码片段以帮助您快速执行一些常见的build任务。如需指示,请参阅本节中的其他build文件.
Building a simple 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)
Building a APK that depends on a static .jar file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# List of static libraries to include in the package
LOCAL_STATIC_JAVA_LIBRARIES := static-library
# 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)
Building a APK that should be signed with the platform 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)
Building a APK that should be signed with a specific vendor 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 := vendor/example/certs/app
# Tell it to build an APK
include $(BUILD_PACKAGE)
Adding a prebuilt APK
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed.
LOCAL_MODULE := LocalModuleName
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Adding a Static Java Library
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)
Android.mk Variables
这些都是变量,你会经常看到按字母顺序列出Android.mk文件。首先,关于命名变量说明:
· LOCAL_ -这些变量被设置每个模块。他们清除了包括$(CLEAR_VARS)行,所以你可以依靠他们正在该文件后,包括空的。大部分你的变量在大多数模块将使用LOCAL_变量。
· PRIVATE_ -这些变量是make-target-specific变量。这意味着他们只能在该模块中的命令可用。这也意味着你从后面你包含的模块回来他们也不会改变。(link to the make documentation) 介绍了更多target-specific variables。
· HOST_ and TARGET_ -这些包含特定于主机或目标的基础之上的目录和定义。不要设置HOST_和TARGET_开头的变量在你的makefile..
· BUILD_ and CLEAR_VARS -这包含了名字和定义模板的makefiles。一些例子CLEAR_VARS和BUILD_HOST_PACKAGE。
· 任何其他的名字在您使用Android.mk是公平的。但是,请记住,这是一个非递归生成系统,因此它可能是您的变量将被改变,以后推出的另一Android.mk,并且一样当为您的规则/ module执行的命令。
Parameter | Description |
LOCAL_AAPT_FLAGS |
|
LOCAL_ACP_UNAVAILABLE |
|
LOCAL_ADDITIONAL_JAVA_DIR |
|
LOCAL_AIDL_INCLUDES |
|
LOCAL_ALLOW_UNDEFINED_SYMBOLS |
|
LOCAL_ARM_MODE |
|
LOCAL_ASFLAGS |
|
LOCAL_ASSET_DIR |
|
LOCAL_ASSET_FILES | In Android.mk files that
|
LOCAL_BUILT_MODULE_STEM |
|
LOCAL_C_INCLUDES | Additional directories to instruct the C/C++ compilers to look for header files in. These paths are rooted at the top of the tree. Use
You should not add subdirectories of include to
|
LOCAL_CC | If you want to use a different C compiler for this module, set LOCAL_CC to the path to the compiler. If LOCAL_CC is blank, the appropriate default compiler is used. |
LOCAL_CERTIFICATE |
|
LOCAL_CFLAGS | If you have additional flags to pass into the C or C++ compiler, add them here. For example:
|
LOCAL_CLASSPATH |
|
LOCAL_COMPRESS_MODULE_SYMBOLS |
|
LOCAL_COPY_HEADERS | The set of files to copy to the install include tree. You must also supply This is going away because copying headers messes up the error messages, and may lead to people editing those headers instead of the correct ones. It also makes it easier to do bad layering in the system, which we want to avoid. We also aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any headers. |
LOCAL_COPY_HEADERS_TO | The directory within "include" to copy the headers listed in This is going away because copying headers messes up the error messages, and may lead to people editing those headers instead of the correct ones. It also makes it easier to do bad layering in the system, which we want to avoid. We also aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any headers. |
LOCAL_CPP_EXTENSION | If your C++ files end in something other than "
Note that all C++ files for a given module must have the same extension; it is not currently possible to mix different extensions. |
LOCAL_CPPFLAGS | If you have additional flags to pass into only the C++ compiler, add them here. For example:
|
LOCAL_CXX | If you want to use a different C++ compiler for this module, set LOCAL_CXX to the path to the compiler. If LOCAL_CXX is blank, the appropriate default compiler is used. |
LOCAL_DX_FLAGS |
|
LOCAL_EXPORT_PACKAGE_RESOURCES |
|
LOCAL_FORCE_STATIC_EXECUTABLE | If your executable should be linked statically, set |
LOCAL_GENERATED_SOURCES | Files that you add to |
LOCAL_INSTRUMENTATION_FOR |
|
LOCAL_INSTRUMENTATION_FOR_PACKAGE_NAME |
|
LOCAL_INTERMEDIATE_SOURCES |
|
LOCAL_INTERMEDIATE_TARGETS |
|
LOCAL_IS_HOST_MODULE |
|
LOCAL_JAR_MANIFEST |
|
LOCAL_JARJAR_RULES |
|
LOCAL_JAVA_LIBRARIES | When linking Java apps and libraries,
Note that setting |
LOCAL_JAVA_RESOURCE_DIRS |
|
LOCAL_JAVA_RESOURCE_FILES |
|
LOCAL_JNI_SHARED_LIBRARIES |
|
LOCAL_LDFLAGS | You can pass additional flags to the linker by setting |
LOCAL_LDLIBS |
|
LOCAL_MODULE |
|
LOCAL_MODULE_PATH | Instructs the build system to put the module somewhere other than what's normal for its type. If you override this, make sure you also set See Putting modules elsewhere for more. |
LOCAL_MODULE_STEM |
|
LOCAL_MODULE_TAGS | Set This variable controls what build flavors the package gets included in. For example: · · · · |
LOCAL_NO_DEFAULT_COMPILER_FLAGS |
|
LOCAL_NO_EMMA_COMPILE |
|
LOCAL_NO_EMMA_INSTRUMENT |
|
LOCAL_NO_STANDARD_LIBRARIES |
|
LOCAL_OVERRIDES_PACKAGES |
|
LOCAL_PACKAGE_NAME |
|
LOCAL_POST_PROCESS_COMMAND | For host executables, you can specify a command to run on the module after it's been linked. You might have to go through some contortions to get variables right because of early or late variable evaluation:
|
LOCAL_PREBUILT_EXECUTABLES | When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these to executables that you want copied. They're located automatically into the right bin directory. |
LOCAL_PREBUILT_JAVA_LIBRARIES |
|
LOCAL_PREBUILT_LIBS | When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these to libraries that you want copied. They're located automatically into the right lib directory. |
LOCAL_PREBUILT_OBJ_FILES |
|
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES |
|
LOCAL_PRELINK_MODULE |
|
LOCAL_REQUIRED_MODULES | Set |
LOCAL_RESOURCE_DIR |
|
LOCAL_SDK_VERSION |
|
LOCAL_SHARED_LIBRARIES | These are the libraries you directly link against. You don't need to pass transitively included libraries. Specify the name without the suffix:
|
LOCAL_SRC_FILES | The build system looks at
|
LOCAL_STATIC_JAVA_LIBRARIES |
|
LOCAL_STATIC_LIBRARIES | These are the static libraries that you want to include in your module. Mostly, we use shared libraries, but there are a couple of places, like executables in sbin and host executables where we use static libraries instead.
|
LOCAL_UNINSTALLABLE_MODULE |
|
LOCAL_UNSTRIPPED_PATH | Instructs the build system to put the unstripped version of the module somewhere other than what's normal for its type. Usually, you override this because you overrode See Putting modules elsewhere for more. |
LOCAL_WHOLE_STATIC_LIBRARIES | These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them. This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shared library.
|
LOCAL_YACCFLAGS | Any flags to pass to invocations of yacc for your module. A known limitation here is that the flags will be the same for all invocations of YACC for your module. This can be fixed. If you ever need it to be, just ask.
|
OVERRIDE_BUILT_MODULE_PATH |
|