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

I developed a Cocos2d-X app with Xcode that works great when I run it from Xcode on an iOS device.

Now I want to port it to Android. I understand that I need to find a way to import the "Xcode" project into Eclipse so that it can be compiled and run on an Android device.

I am currently trying to convert this project into a hybrid iOS / Android project, following this guide: http://gameit.ro/2012/01/creating-an-iphone-and-android-cocos2d-x-hybrid-project-updated / # comment-640

However, I do not see any of my cpp classes (cocos2d-x C ++ classes) appearing in Eclipse when I open this hybrid project and I get the following errors when trying to compile it using build_native.sh:

Compile++ thumb : game_logic <= AppDelegate.cpp jni/../../Classes/AppDelegate.cpp:14:23: error: IntroMenu.h: No such file or directory jni/../../Classes/AppDelegate.cpp:15:23: error: GameLayer.h: No such file or directory jni/../../Classes/AppDelegate.cpp:16:26: error: ScoreManager.h: No such file or directory jni/../../Classes/AppDelegate.cpp: In member function 'virtual bool AppDelegate::applicationDidFinishLaunching()': jni/../../Classes/AppDelegate.cpp:99: error: invalid use of incomplete type 'struct ScoreManager' jni/../../Classes/AppDelegate.h:17: error: forward declaration of 'struct ScoreManager' jni/../../Classes/AppDelegate.cpp:101: error: invalid use of incomplete type 'struct ScoreManager' jni/../../Classes/AppDelegate.h:17: error: forward declaration of 'struct ScoreManager' jni/../../Classes/AppDelegate.cpp:118: error: 'GameLayer' has not been declared jni/../../Classes/AppDelegate.cpp:120: error: 'IntroMenu' has not been declared make: *** [obj/local/armeabi/objs-debug/game_logic/AppDelegate.o] Error 1 macbook-de-regis-andre-2:android regisandre$ ./build_native.sh 

Do I need to import some files into Eclispe? Do I need to modify some android.mk files? Something else?

Can anyone help me or write a tutorial on this topic? Thanks!

+7
source share
2 answers

In appearance, you need to add your custom created files in Classes / Android.mk to the LOCAL_SRC_FILES section as follows:

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

You need to do this so that the android build file is aware of the new files that 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.

+12
source

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

To avoid updating the file every time a new source file is added to the project, you can use the following script (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) 

Remember that if you have files somewhere else, for example:

 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 the compiler complaining: "There is no rule for creating target /.../," I suggest deleting the contents of the obj / local / armeabi / objs-debug / game_shared folder in Eclipse. Then download build_native.sh and update (F5) the contents of the obj folder.

0
source

All Articles