Cocos2d-x: How to port a Cocos2d-x project developed with XCode to Android (via Eclipse)?

天大地大妈咪最大 提交于 2019-12-03 03:26:05

From the looks of it you need to add your custom created files to Classes/Android.mk in the LOCAL_SRC_FILES section like this:

LOCAL_SRC_FILES := AppDelegate.cpp \
                   HelloWorldScene.cpp \
                   IntroMenu.cpp \
                   GameLayer.cpp \
                   ScoreManager.cpp

You need to do this in order to let the android build file know about the new files which need to be included in the build process.

You will need to do this, afaik, for each new source file that you add to the project.

@clawoo is right, but you do not have to include every file you add to the project. Instead, you can do the following and forget about it ;)

In order to not need to update the file every time new source file is added to the project, you can use the following script (found here: http://www.cocos2d-x.org/boards/6/topics/5321)

dirs := $(shell find $(LOCAL_PATH) -type d)

cppfilestemp1 := $(shell find $(LOCAL_PATH) -type d)
cppfilestemp2 := $(shell find $(cppfilestemp1) -name *.cpp)
cppfilestemp3 := $(sort $(cppfilestemp2))
cppfiles := $(subst $(LOCAL_PATH)/,,$(cppfilestemp3))

LOCAL_SRC_FILES := \
           $(cppfiles)

Please remember, that if you have the files somewhere else, e.g.:

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

you can do the following:

cppfilestemp1 := $(shell find $(LOCAL_PATH)/../../../Classes/ -type d)

and

LOCAL_SRC_FILES := main.cpp
LOCAL_SRC_FILES += $(cppfiles)

In my case it worked.

HINT:

If you have problems with compiler complaining about: 'No rule to make target /.../', I suggest to delete in Eclipse contents of obj/local/armeabi/objs-debug/game_shared folder. Then, rerun build_native.sh and refresh (F5) contents of obj folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!