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。

發佈留言