android 通過Android.mk將三方的so庫編譯到apk裡
阿新 • • 發佈:2019-01-25
在網上找了好多沒有一個能解決此問題,於是自己分析其原理自己寫了一個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包裡,第一種方法要簡單些。