Android平台
添加第三方.so
1.将.so放到prebuild目录下。
2.修改mk.
例如添加的库文件是:libfmod.so。
LOCAL_PATH := $(call my-dir)
\##### 添加第三方so库 BEGIN ######
include $(CLEAR_VARS)
LOCAL_MODULE := libfmod
LOCAL_SRC_FILES := prebuild/$(TARGET_ARCH_ABI)/libfmod.so #第三方so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../cocos2d-x/external/fmod/include #导出的头文件路径
include $(PREBUILT_SHARED_LIBRARY)
\##### 添加第三方so库 END ######
include $(CLEAR_VARS) #开始一个新的编译
LOCAL_MODULE := cocos2dlua_shared
LOCAL_MODULE_FILENAME := libcocos2dlua
\# 遍历目录及子目录的函数
define walk
$(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))
endef
\# Classes目录下所有文件
MY_FILES := $(call walk, $(LOCAL_PATH)/../../Classes)
MY_C_FILES := $(filter %.cpp %.c, $(MY_FILES))
MY_H_FILES := $(filter %.h, $(MY_FILES))
LOCAL_SRC_FILES := hellolua/main.cpp \
hellolua/JniUtil.cpp
LOCAL_SRC_FILES += $(MY_C_FILES:$(LOCAL_PATH)/%=%)
\# Classes目录下所有文件夹
MY_H_FOLDERS := $(sort $(dir $(MY_FILES)))
\#$(warning MY_H_FOLDERS:$(MY_H_FOLDERS))
MY_LOCAL_C_INCLUDES := $(sort $(dir $(LOCAL_PATH)/../../Classes/*))
MY_LOCAL_C_INCLUDES += $(MY_H_FOLDERS)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../../cocos2d-x/external \
$(LOCAL_PATH)/../../../cocos2d-x/tools/simulator/libsimulator/lib \
$(LOCAL_PATH)/../../../cocos2d-x/tools/simulator/libsimulator/lib/protobuf-lite
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../cocos2d-x/cocos/ui
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../cocos2d-x/cocos/editor-support/cocostudio
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../cocos2d-x/external/fmod/include #使用了共享库导出的头文件 在在此处定义路径
LOCAL_C_INCLUDES += $(sort $(MY_LOCAL_C_INCLUDES))
\# _COCOS_HEADER_ANDROID_BEGIN
\# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2d_lua_static
LOCAL_STATIC_LIBRARIES += cocos2d_simulator_static
LOCAL_STATIC_LIBRARIES += testin_agent_helper_static
LOCAL_STATIC_LIBRARIES += testin_agent_helper_lua
\# _COCOS_LIB_ANDROID_BEGIN
\# _COCOS_LIB_ANDROID_END
LOCAL_SHARED_LIBRARIES := libfmod #添加共享库
include $(BUILD_SHARED_LIBRARY) #编译成共享库
$(call import-module,scripting/lua-bindings/proj.android)
$(call import-module,tools/simulator/libsimulator/proj.android)
$(call import-module,external/testinagenthelper)
$(call import-module,external/testinagenthelper/lua)
\# _COCOS_LIB_IMPORT_ANDROID_BEGIN
\# _COCOS_LIB_IMPORT_ANDROID_END
PREBUILT_SHARED_LIBRARY—>LOCAL_C_INCLUDES —>LOCAL_SHARED_LIBRARIES 这三放置的位置得注意。
3.在java层加载so
合适的地方调用 如下代码,一般放在静态方法里面。
try {
System.loadLibrary("fmod");
}catch (UnsatisfiedLinkError e) { }
static {
System.loadLibrary("XXX");
}
注意加载的第三方库一定得在 cocos的so之前加载。
以上添加一个动态库编译完成后.so会出现在包里。
---------------------------------------------------------------------------------------------------------
添加第三方.a