About a small compilation problem of cocos2dx3.0 in eclipse

The c++ file in cocos2dx has been added to the Android.mk file in jni, but there are still problems. A colleague has modified this mk file before, and read the cpp and c files in the Classes folder in a loop. The content is as follows:

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), $(call rwildcard,$(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_FILES_PATH), $(call rwildcard,$(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)

I add directly for convenience

<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>    ...等等

 
 

 As a result, the various function definitions in the C2DXSshareSDK could not be found. Obviously, the file was not compiled, and finally changed to 
 

# 赋值给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, Helvetica, sans-serif;">MY_SRC_LIST += ...等等</span>
<span style="font-family:Arial, Helvetica, sans-serif;">
</span>
<span style="font-family:Arial, Helvetica, sans-serif;"></span><pre name="code" class="html">MY_ALL_DIRS += <span style="font-family: Arial, Helvetica, 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)
 
 

There is still a compilation error, but the error is different, it shows vector, std cannot be found, at this time I add it to the file that calls him

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

Well, the compilation is successful. To sum up, as long as the c/c++ file is wrong when using ndk for android, most of the compilation error is in the Android.mk file in jni.

And android uses Cocos2dx, remember to add the src file of cocos java, you can right-click to select the project, select Build Path->Link Source, then customize a name, add the required folder, the java directory of cocos2dx is... \cocos2d\cocos\platform\android\java\src, of course, you can also use other methods such as import to directly select import->Android->Existing Android Code Into Workspace, select cocos2dx3.0 or above and directly select the \cocos folder in the project That's it.

Guess you like

Origin blog.csdn.net/rsp19801226/article/details/41116501