Android中集成第三方软件包

1.编译一个简单的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)
# Build all java files in src
LOCAL_SRC_FILES := $(call all-java-files-under, src)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)

2.编译一个依赖第三方jar包的APK

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := 第三方Jar包1别名(任意取名)  第三方Jar包2别名(任意取名)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := MyMaps
include $(BUILD_PACKAGE)
 

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := 第三方Jar包1别名:第三方Jar包1路径 				第三方Jar包1别名:第三方Jar包2路径 
LOCAL_MODULE_TAGS := optional
include $(BUILD_MULTI_PREBUILT)
 
# Use the following include to make our testapk.
include $(callall-makefiles-under,$(LOCAL_PATH))
LOCAL_STATIC_JAVA_LIBRARIES 后面应是你的APK程序所需要的JAVA库的JAR文件名。LOCAL_STATIC_JAVA_LIBRARIES取jar库的别名,可以任意取值;
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := jar库的别名:jar文件路径
jar库的别名一定要与LOCAL_STATIC_JAVA_LIBRARIES里所取的别名一致,且不含.jar;
jar文件路径一定要是真实的存放第三方jar包的路径。
使用BUILD_MULTI_PREBUILT编译

3.编译一个需要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 后面应该是签名文件的文件名

4.编译一个指定签名的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)

5.装载一个普通的第三方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) 

6.编译一个静态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文件名。

7.编译可执行文件

include $(CLEAR_VARS)
LOCAL_MODULE:= 可执行文件名称
LOCAL_MODULE_TAGS:= debug
LOCAL_MODULE_PATH:= $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_SRC_FILES:= 	./xxx/xxx.c
include $(BUILD_EXECUTABLE)

8.编译JNI动态库

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
# This is the target being built.
LOCAL_MODULE:= libxxx_jni
# All of the source files that we will compile.
LOCAL_SRC_FILES:= 	xxx.cpp 
# No static libraries.
LOCAL_STATIC_LIBRARIES :=
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
# Also need the JNI headers.
LOCAL_C_INCLUDES += 	$(JNI_H_INCLUDE)     	$(LOCAL_PATH)

LOCAL_SHARED_LIBRARIES := 	libutils     	libcutils 

# Don‘t prelink this library.  For more efficient code, you may want
# to add this library to the prelink map and set this to true. However,
# it‘s difficult to do this for applications that are not supplied as
# part of a system image.

LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)

9.编译第三方so库到APK

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := apk包名
LOCAL_CERTIFICATE := platform
LOCAL_JNI_SHARED_LIBRARIES := 动态库别名
include $(BUILD_PACKAGE)

include $(CLEAR_VARS)
LOCAL_PREBUILT_LIBS :=动态库别名:动态库全路径
LOCAL_MODULE_TAGS := optional
include $(BUILD_MULTI_PREBUILT)
 
# Use the following include to make our testapk.
include $(callall-makefiles-under,$(LOCAL_PATH))

LOCAL_PREBUILT_LIBS := 别名:so文件路径
别名一般是动态库去后缀的名称,so文件路径一定要是真实的存放第三方so文件的路径。
编译拷贝用BUILD_MULTI_PREBUILT。

Android中集成第三方软件包,布布扣,bubuko.com

Android中集成第三方软件包

上一篇:Android Dialog


下一篇:【Objective-C高级编程】iOS与OS X多线程和内存管理