关于cocos2dx3.0在eclipse中的一个小编译问题

前端之家收集整理的这篇文章主要介绍了关于cocos2dx3.0在eclipse中的一个小编译问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

cocos2dx中的c++文件已经添加到jni里面的Android.mk文件中,但是却依然出现问题,之前有同事修改过这个mk文件,循环读取Classes文件夹中的cpp和c文件内容如下:@H_502_1@

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

# 配置自己的源文件目录和源文件后缀名
MY_FILES_PATH  :=  $(LOCAL_PATH) \
                   $(LOCAL_PATH)/../../Classes 

MY_FILES_SUFFIX := %.cpp %.c 

# 递归遍历目录下的所有的文件
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

# 获取相应的源文件
MY_ALL_FILES := $(foreach src_path,$(MY_FILES_PATH),$(src_path),*.*) ) 
MY_ALL_FILES := $(MY_ALL_FILES:$(MY_CPP_PATH)/./%=$(MY_CPP_PATH)%)
MY_SRC_LIST  := $(filter $(MY_FILES_SUFFIX),$(MY_ALL_FILES)) 
MY_SRC_LIST  := $(MY_SRC_LIST:$(LOCAL_PATH)/%=%)

# 去除字串的重复单词
define uniq =
  $(eval seen :=)
  $(foreach _,$1,$(if $(filter $_,${seen}),$(eval seen += $_)))
  ${seen}
endef


# 递归遍历获取所有目录
MY_ALL_DIRS := $(dir $(foreach src_path,*/) ) )
MY_ALL_DIRS := $(call uniq,$(MY_ALL_DIRS))

MY_SRC_LIST := $(filter-out %Classes/main.cpp,$(MY_SRC_LIST))

# 赋值给NDK编译系统
LOCAL_SRC_FILES  := $(MY_SRC_LIST)
LOCAL_C_INCLUDES := $(MY_ALL_DIRS)

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += Box2d_static
# LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static
# LOCAL_WHOLE_STATIC_LIBRARIES += spine_static
# LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx-talkingdata

include $(BUILD_SHARED_LIBRARY)

define add_shared_lib
	include $(CLEAR_VARS)
	LOCAL_MODULE := $1
	LOCAL_MODULE_FILENAME := $1
	LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/$1.so
	include $(PREBUILT_SHARED_LIBRARY)
endef

shared_lib_names := libbdpush_V2_0 \
					libBaiduMapSDK_v2_3_1 \
					libGif \
					liblocSDK4 \
					libTeaCrypt
$(foreach item,$(shared_lib_names),$(eval $(call add_shared_lib,$(item))))

$(call import-module,.)
$(call import-module,audio/android)
$(call import-module,Box2D)
# $(call import-module,editor-support/cocosbuilder)
# $(call import-module,editor-support/spine)
# $(call import-module,editor-support/cocostudio)
$(call import-module,network)
$(call import-module,extensions)
#$(call import-module,proj.android/jni)

我为了方便直接添加@H_502_1@

<pre name="code" class="html"># 赋值给NDK编译系统
LOCAL_SRC_FILES  := $(MY_SRC_LIST) \
<span style="white-space:pre">		</span>    $(LOCAL_PATH)/../../ShareSDK/C2DXShareSDK/Android/C2DXShareSDK.cpp \
<span style="white-space:pre">		</span>    ...等等
LOCAL_C_INCLUDES := $(MY_ALL_DIRS) \
<pre name="code" class="html"><span style="white-space:pre">		</span>    $(LOCAL_PATH)/../../ShareSDK/C2DXShareSDK/Android \
<span style="white-space:pre">		</span>    ...等等
 
 结果还是无法找到定义C2DXSshareSDK中的各种函数定义,很明显是没有编译该文件,最后改变为 
 
 
# 赋值给NDK编译系统
<pre name="code" class="html">MY_SRC_LIST += <span style="font-family: Arial,Helvetica,sans-serif;">../../ShareSDK/C2DXShareSDK/Android/C2DXShareSDK.cpp </span>
<pre name="code" class="html"><span style="font-family:Arial,sans-serif;">MY_SRC_LIST += ...等等</span>
<span style="font-family:Arial,sans-serif;">
</span>
<span style="font-family:Arial,sans-serif;"></span><pre name="code" class="html">MY_ALL_DIRS += <span style="font-family: Arial,sans-serif;">$(LOCAL_PATH)/../../ShareSDK/C2DXShareSDK/Android</span>
 
 
 
<pre name="code" class="html">MY_ALL_DIRS += ...等等
LOCAL_SRC_FILES := $(MY_SRC_LIST)LOCAL_C_INCLUDES := $(MY_ALL_DIRS) 
 

还是编译出错,不过错误不同了,显示vector,std找不到,这个时候我把调用他的文件添加上@H_502_1@

include "cocos2d.h" 
using namespace std;
using namespace cocos2d;

好了,编译成功,总结一下android使用ndk只要是c/c++文件出错的,多半编译错误在jni里面的Android.mk文件中。@H_502_1@

还有android使用Cocos2dx,记得添加cocos的java的src文件,可以右键选择项目,选择Build Path->Link Source,然后自定义一个名字,把需要的文件添加进去,cocos2dx的java目录是...\cocos2d\cocos\platform\android\java\src,当然也可以用其他比如import方式直接选择import->Android->Existing Android Code Into Workspace,选择cocos2dx3.0以上版本直接选择项目中的\cocos文件夹即可。@H_502_1@ 原文链接:https://www.f2er.com/cocos2dx/346200.html

猜你在找的Cocos2d-x相关文章