一、编译一个简单的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)
二、编译一个依赖静态.jar文件的APK
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)
注:LOCAL_STATIC_JAVA_LIBRARIES 后面应是你的APK程序所须要的JAVA库的JAR文件名称。
三、编译一个须要platform key签名的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
LOCAL_CERTIFICATE := platform
# Tell it to build an APK
include $(BUILD_PACKAGE)
注:LOCAL_CERTIFICATE 后面应该是签名文件的文件名称
四、编译一个须要特殊vendor key签名的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
LOCAL_CERTIFICATE := vendor/example/certs/app
# Tell it to build an APK
include $(BUILD_PACKAGE)
五、装载一个普通的第三方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)
LOCAL_CERTIFICATE := platform
include $(BUILD_PREBUILT)
六、装载须要.so(动态库)的第三方apk
LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := baiduinput_android_v1.1_1000e
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
include $(BUILD_PREBUILT)
#################################################################
####### copy the library to /system/lib #########################
#################################################################
include $(CLEAR_VARS)
LOCAL_MODULE := libinputcore.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
LOCAL_SRC_FILES := lib/$(LOCAL_MODULE)
OVERRIDE_BUILD_MODULE_PATH := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)
include $(BUILD_PREBUILT)
七、编译一个静态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)
注:LOCAL_JAVA_LIBRARIES表示生成的java库的jar文件名称。
来源:http://www.cnblogs.com/hopetribe/archive/2012/04/23/2467060.html
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := ta:libs/TA4AIDL.jar
include $(BUILD_MULTI_PREBUILT)
以下的代码能够加到任一个文件里:
加入共享库:
LOCAL_MODULE := libffmpeg #库的名字
LOCAL_MODULE_TAGS := optional #系统内有效。你能够试一下不加这一行就能够看到出错提示信息。
LOCAL_PREBUILT_LIBS := libffmpeg.so #库的路径。
include $(BUILD_MULTI_PREBUILT) #这行比較重要是实际做事的地方。參考此文:加入第三方库到Android源代码中
加入静态库:
include $(CLEAR_VARS)
LOCAL_MODULE := libavcodec
LOCAL_PREBUILT_LIBS := libavcodec.a
LOCAL_MODULE_TAGS := optional
include $(BUILD_MULTI_PREBUILT)
静态库和动态库是相应的,静态库是在链接时使用,动态库是在执行时使用。用法:
在要用到相应库的模块的Android.mk文件里增加类似于以下的内容:
静态库(链接时用。它会被拷贝到out/target/product/generic/obj/STATIC_LIBRARIES/libavcodec_intermediates/文件夹下):
LOCAL_WHOLE_STATIC_LIBRARIES += \
libavcodec #这个是模块名(LOCAL_MODULE)
动态库(执行时用。它会被拷贝到/system/lib/文件夹下。):
LOCAL_SHARED_LIBRARIES += \
libffmpeg
include $(call all-makefiles-under,$(LOCAL_PATH)) #这句上调用子文件夹下的非常有Android.mk
来源:http://hi.baidu.com/2400xiaobing/item/ffa78cd51f76d81521e25085
LOCAL_STATIC_JAVA_LIBRARIES := ta
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := ta:libs/TA4AIDL.jar
include $(BUILD_MULTI_PREBUILT)