cocos 引入第三方动态库的三种方法

方法一,修改 build-cfg.json

{
    "ndk_module_path" :[
        "${COCOS_FRAMEWORKS}/cocos2d-x-3.8.1",
        "${COCOS_FRAMEWORKS}/cocos2d-x-3.8.1/cocos",
        "${COCOS_FRAMEWORKS}/cocos2d-x-3.8.1/external"
    ],
    "copy_resources": [
        {
            "from": "../Resources",
            "to": ""
        },
        {
            "from":"jni/pluginadcolony/libs/armeabi/libadcolony.so",
            "to":"../libs/armeabi/"
        },
        {
            "from":"jni/pluginadcolony/libs/armeabi/libjs.so",
            "to":"../libs/armeabi/"
        }
    ]
}

方法二,proj.android/jni/Android.mk

# include adcolony
include $(CLEAR_VARS)
LOCAL_MODULE := libadcolony
LOCAL_SRC_FILES := pluginadcolony/libs/armeabi/libadcolony.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libjs
LOCAL_SRC_FILES := pluginadcolony/libs/armeabi/libjs.so
include $(PREBUILT_SHARED_LIBRARY)
# include adcolony end

完整文件:

LOCAL_PATH := $(call my-dir)

# include adcolony
include $(CLEAR_VARS)
LOCAL_MODULE := libadcolony
LOCAL_SRC_FILES := pluginadcolony/libs/armeabi/libadcolony.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libjs
LOCAL_SRC_FILES := pluginadcolony/libs/armeabi/libjs.so
include $(PREBUILT_SHARED_LIBRARY)
#

include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp

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

LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES += PluginAdColony
LOCAL_STATIC_LIBRARIES += sdkbox


include $(BUILD_SHARED_LIBRARY)

$(call import-add-path,$(LOCAL_PATH))
$(call import-module, ./prebuilt-mk)
$(call import-module, ./sdkbox)
$(call import-module, ./pluginadcolony)

方法三:LOCAL_SHARED_LIBRARIES,proj.android/jni/Android.mk

一定要在 include $(BUILD_SHARED_LIBRARY) 前添加 LOCAL_SHARED_LIBRARIES, 如:

LOCAL_SHARED_LIBRARIES := ffmpeg
include $(BUILD_SHARED_LIBRARY)

子工程写法:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
LOCAL_SRC_FILES := libffmpeg.so

include $(PREBUILT_SHARED_LIBRARY)

验证:

解开 apk 包,检查里面是否包含 xx.so 文件。

参考:

  • http://discuss.cocos2d-x.org/t/how-to-add-third-party-so-file-in-the-project-for-android-build/19172/10?u=yinjimmy
  • http://blog.csdn.net/sozell/article/details/10551309
  • http://www.jianshu.com/p/ce003c4fe1cf

你可能感兴趣的:(cocos 引入第三方动态库的三种方法)