Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have developed a Cocos2d-X app with XCode which works perfectly when I launch it from XCode on an iOS device.

Now, I want to port it to Android. What I understand is that I have to find a way to import my "XCode project" to Eclipse in order to be able to compile it and launch it on an Android device.

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

Nevertheless, I don't 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 with 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 have to import some files to Eclispe? Do I have to modify some android.mk files? Something else?

Anybody can help me or write a tutorial on this topic? Thanks !!

like image 882
Regis_AG Avatar asked Feb 08 '12 11:02

Regis_AG


1 Answers

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.

like image 113
clawoo Avatar answered Sep 22 '22 14:09

clawoo