Development process with cocos2d-x

Hello,

I’m new to cocos2d-x and I got a very simple small demo working under VS.

I would like to now run that under my android phone. I have a created a few scenes and I’m wondering how do I make those new classes show up under my android project?

Here is a sample error message:

“error: undefined reference to 'SplashScene::createScene()”

I know what it means and how to fix it but what I would like to know is how to keep my VS project and Android one in sync.

Any help will be greatly appreciated.

Thank you!

Hello there,
you have to add new scenes (cpp files, not h files) in Android.mk file.

1 Like

Open the proj.android folder

in proj.android You will see " jni " folder

in the jni folder You need to open the file name "Android.mk"

Example of how to add CustomScene.cpp in Classes and
Example of how to add CustomFolder/GameLayer.cpp is shown below.

1 Like

Yea I was aware of this I was just wondering if there was a way to have it in sync so I would not have to do it every time I add a new file. Thank you!

Thank you for the detailed answer. I guess this is the only way for now.

I followed the instructions under the Spine manual for example and now I get the following error:

error: undefined reference to 'spine::SkeletonAnimation::createWithJsonFile

How do I add all the spine, spine-cocos2dx includes, SRCs to the android mk file? Do I need to add one by one?

I have the following:

LOCAL_SRC_FILES := game/main.cpp
…/…/…/Classes/AppDelegate.cpp
…/…/…/Classes/SplashScene.cpp
…/…/…/Classes/MainMenuScene.cpp
…/…/…/Classes/GameScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/…/…/…/Classes
$(LOCAL_PATH)/…/…/…/Classes/spine
$(LOCAL_PATH)/…/…/…/Classes/spine-cocos2dx

Shouldn’t that cover it?

Any help will be great.

Thank you!

Try this:

As for spine it’s strange, what cocos2d-x version are you using?

for “spine related issue”

Check these two steps:

Step 1:

In Your project check whether this folder exists or not,
“cocos/edit-support/spine/”

If the above folder exists then check this file,
“cocos/Android.mk”

“cocos/Android.mk” should contain the below lines,

LOCAL_STATIC_LIBRARIES += spine_static ( somewhere in the “cocos/Android.mk” file)

$(call import-module,editor-support/spine) ( somewhere in the “cocos/Android.mk” file)

If the above lines are there in the “cocos/Android.mk”, that means “spine” library / Framework is supported in Your project.

Note : If Your project support “spine” then You don’t need to add spine related files in Your “jni/Android.mk” file.

Step 2:

To know more about,

How to include spine related header files and how to run spine related samples You shall check these Two files,


Hope this info helps.

Thank you! That should save me some time. I’m using the latest version for cocos2d-x and Spine runtime.

I’m still getting the error even though I’m including all the *.cpp and *.h related to spine.

Thank you for your reply. Unfortunately the spine documentation calls for all those settings plus directories to be removed. I have been trying to follow their instructions so I can use the latest version of spine and I have managed to get it working under VS but under android studio I get errors I mentioned above (undefined references).

Here is the link to the instructions I’m following: https://github.com/EsotericSoftware/spine-runtimes/tree/3.6/spine-cocos2dx

I found the solution:

Here is the contents (relevant) of my Android mk file:

LIR_FILE_LIST_CLASSES := $(wildcard $(LOCAL_PATH)/../../../Classes/*.cpp)
LIR_FILE_LIST_SPINEC := $(wildcard $(LOCAL_PATH)/../../../Classes/spine/*.c)
LIR_FILE_LIST_SPINECOCOS2DX := $(wildcard $(LOCAL_PATH)/../../../Classes/spine-cocos2dx/*.cpp)

LOCAL_SRC_FILES := game/main.cpp
LOCAL_SRC_FILES += $(LIR_FILE_LIST_CLASSES:$(LOCAL_PATH)/%=%)
LOCAL_SRC_FILES += $(LIR_FILE_LIST_SPINEC:$(LOCAL_PATH)/%=%)
LOCAL_SRC_FILES += $(LIR_FILE_LIST_SPINECOCOS2DX:$(LOCAL_PATH)/%=%)


LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes \
                    $(LOCAL_PATH)/../../../Classes/spine \
                    $(LOCAL_PATH)/../../../Classes/spine-cocos2dx

Thank you all for helping and I hope this helps someone else as well.

spine is already added in cocos2d-x … you didnt need to do all that

Lol, I actually answered that question

1 Like

I understand spine is already included but according to the documentation the include run time is not always up to speed so if you use a newer version of spine you may have issues.

It was probably not necessary but I wanted to play it safe.