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

2

7

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 !!

Smtih answered 8/2, 2012 at 11:3 Comment(0)
Z
12

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.

Zebra answered 8/2, 2012 at 11:29 Comment(0)
R
0

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

Reservation answered 26/8, 2012 at 18:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.