此文列出Android.mk的常用模板(部分内容源于多篇他人博客,这里不具体指出),如有错漏,还请在评论中指出,后期持续更新
#链接第三方动态库,在和部分android源码的编译中验证不过
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := libfoo.so
include $(PREBUILT_SHARED_LIBRARY)
#预编译第三方提供的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)
#编译子目录下的源码为jar包
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_JAVA_LIBRARIES := android.test.runner
LOCAL_MODULE := sample
include $(BUILD_STATIC_JAVA_LIBRARY)
#预编译jar包
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libname:lib/needimport.jar
include $(BUILD_MULTI_PREBUILT)
#构建一个被platform key签名的apk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := platform #注意这行
include $(BUILD_PACKAGE)
#编译apk依赖某个jar包
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := static-library
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := LocalPackage
include $(BUILD_PACKAGE)
#编译静态库
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo/foo.c
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)
#编译动态库
include $(CLEAR_VARS)
LOCAL_MODULE := bar
LOCAL_SRC_FILES := bar.c
LOCAL_STATIC_LIBRARIES := foo
include $(BUILD_SHARED_LIBRARY)
#拷贝文件到out相应的类型下,在部分第三方提供的源码编译中未实现
LOCAL_MODULE := test.xml
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_PATH := $(TARGET_OUT)
include $(BUILD_PREBUILT)
#链接第三方动态库,静态库,jar包
include $(CLEAR_VARS)
LOCAL_PREBUILT_LIBS := libabc:libaaa.so
include $(BUILD_MULTI_PREBUILT)
......
LOCAL_STATIC_LIBRARIES := libabc