Eclipse接入第三方動態庫.so方案

Kaitiren發表於2017-09-26

在Android.mk中加入如下程式碼


####### third so begin

include $(CLEAR_VARS)

LOCAL_MODULE:= agora-rtc

LOCAL_SRC_FILES :=../prebuilt/$(TARGET_ARCH_ABI)/libagora-rtc-sdk-jni.so

include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)

LOCAL_MODULE:= agoraSdkCWrwper

LOCAL_SRC_FILES := ../prebuilt/$(TARGET_ARCH_ABI)/libagoraSdkCWrapper.so

include $(PREBUILT_SHARED_LIBRARY)

####### third so end


### 定義標頭檔案目錄

LOCAL_C_INCLUDES :=    $(LOCAL_PATH)/../../Classes \

                                            $(LOCAL_PATH)/../../Classes/sdk/Agora \

                                            $(LOCAL_PATH)/../../Classes/sdk/Agora/include


### 引用第三方模組

LOCAL_SHARED_LIBRARIES := agora-rtc agoraSdkCWrapper




include $(CLEAR_VARS)                                清理變數資訊

include $(PREBUILT_SHARED_LIBRARY)     預編譯第三方庫

LOCAL_MODULE     模組名稱
LOCAL_SRC_FILES  模組檔案
LOCAL_SHARED_LIBRARIES 引用第三方模組




用例:
Andorid.mk:

LOCAL_PATH := $(call my-dir)

####### third so begin


include $(CLEAR_VARS)    // 清理變數

LOCAL_MODULE:= agora-rtc   // prebuilt中的.so庫

LOCAL_SRC_FILES :=../prebuilt/$(TARGET_ARCH_ABI)/libagora-rtc-sdk-jni.so  //完整路徑

include $(PREBUILT_SHARED_LIBRARY) // ndk編譯匯入共享庫


include $(CLEAR_VARS)

LOCAL_MODULE:= agoraSdkCWrapper

LOCAL_SRC_FILES := ../prebuilt/$(TARGET_ARCH_ABI)/libagoraSdkCWrapper.so

include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)

LOCAL_MODULE:= jcore116

LOCAL_SRC_FILES := ../prebuilt/$(TARGET_ARCH_ABI)/libjcore116.so

include $(PREBUILT_SHARED_LIBRARY)


####### third so end


include $(CLEAR_VARS)


LOCAL_MODULE := cocos2djs_shared


LOCAL_MODULE_FILENAME := libcocos2djs


ifeq ($(USE_ARM_MODE),1)

LOCAL_ARM_MODE := arm

endif


LOCAL_SRC_FILES := hellojavascript/main.cpp \

                   ../../Classes/AppDelegate.cpp \

                   ../../Classes/sdk/wx/Android/JniManager.cpp \

                   ../../Classes/sdk/wx/Android/JSBindingAndroidWXManager.cpp \

                   ../../Classes/sdk/wx/Android/JSBindingAndroidRecorderManager.cpp \

                   ../../Classes/jsb/Android/AndroidNativeHttpClient.cpp \

                   ../../Classes/jsb/Android/JSBindingAndroidNativeHttpClient.cpp \

                   ../../Classes/sdk/Agora/AgoraManager.cpp \


LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \

$(LOCAL_PATH)/../../Classes/sdk/Agora \

$(LOCAL_PATH)/../../Classes/sdk/Agora/include 


LOCAL_STATIC_LIBRARIES := cocos2d_js_static


LOCAL_SHARED_LIBRARIES := agora-rtc agoraSdkCWrapper jcore116


LOCAL_EXPORT_CFLAGS := -DCOCOS2D_DEBUG=2 -DCOCOS2D_JAVASCRIPT


include $(BUILD_SHARED_LIBRARY)


$(call import-module, scripting/js-bindings/proj.android)




工程配置檔案:

Application.mk (編譯架構 armeabi-v7a / armeabi-v8a / x86   通用架構: armeabi)

APP_STL := gnustl_static 


# Uncomment this line to compile to armeabi-v7a, your application will run faster but support less devices

APP_ABI := armeabi-v7a x86  // ABI使用的編譯架構


APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char

APP_LDFLAGS := -latomic


USE_ARM_MODE := 1


ifeq ($(NDK_DEBUG),1)

  APP_CPPFLAGS += -DCOCOS2D_DEBUG=1

  APP_OPTIM := debug

else

  APP_CPPFLAGS += -DNDEBUG

  APP_OPTIM := release

endif

NDK編譯自動生成結果:


注意:eclipse接入動態連結庫流程, 選擇對應的ANDROID架構編譯好的.so檔案放入prebuilt目錄下, 修改android.mk檔案, 啟用Application.mk檔案中的

APP_ABI指定NDK編譯架構, 進行NDK編譯生成到libs對應資料夾中,在進行JAVA環境的配置和呼叫即可。




相關文章