android 通过Android.mk将三方的so库编译到apk里

在网上找了好多没有一个能解决此问题,于是自己分析其原理自己写了一个Android.mk文件。通过实验可以将三方的os库编译到apk包里,编译完生成的apk包你打开会看到有个libs目录,so库就放在libs/armeabi目录下,下面是Android.mk文件的写法

写法一:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)  
   
LOCAL_PREBUILT_LIBS :=libtest:libs/armeabi/libtest.so  
LOCAL_MODULE_TAGS := eng  
include $(BUILD_MULTI_PREBUILT)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := eng
LOCAL_CERTIFICATE := platform
LOCAL_PACKAGE_NAME := test
LOCAL_DEX_PREOPT := false
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JNI_SHARED_LIBRARIES := libtest
include $(BUILD_PACKAGE)

写法二:

include $(CLEAR_VARS)
LOCAL_MODULE := libtest.
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
LOCAL_SRC_FILES := libs/armeabi/$(LOCAL_MODULE)
OVERRIDE_BUILD_MODULE_PATH := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)
include $(BUILD_PREBUILT)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := eng
LOCAL_CERTIFICATE := platform
LOCAL_PACKAGE_NAME := test
LOCAL_DEX_PREOPT := false
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_JNI_SHARED_LIBRARIES := libtest
include $(BUILD_PACKAGE)

两种方法都可以实现将三方的so库编译到apk包里,第一种方法要简单些。


你可能感兴趣的:(Android)