Cocos2D-X Tutorial for iOS and Android: Getting Started

In this Cocos2D-X tutorial, you’ll learn how to use Cocos2D-X and C++ to produce a cross-platform “Hello World” app that will run under both iOS and Android. By .

Leave a rating/review
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Debugging Tips and Tricks

Debugging the iOS part of the Cocos2d-x project is exactly the same as debugging standard Cocos2D code, so there is nothing special to add here.

However, for Android, here’s some notes.

When building for debug with NDK, a ‘server side’ gdb and gdbcontext is bundled inside the APK generated by the ndk-build shell and populated to the device. This remote debugger will communicate with any compatible GDB client agent.

The best GDB agent to use with Eclipse is the NVidia debug manager plugin, but installing that is beyond the scope of this Cocos2D-X tutorial.

Note:

If you want to install the NVidia Debug Manager plugin, all you really need to do is to go to this page and download the full Tegra Android Developer Pack even though you might think you don’t need it. When you install the Tegra Developer pack, it gives you the option to select what you want to install and at this point, you can opt to install just the plugin.

However, that will not install the plugin into Eclipse. It will simply put the plugin ZIP file on your hard drive. Now follow the instructions on this PDF to actually install the plugin.

I found that on some physical devices (Samsumg Galaxy S being one of them), the remote debugger always fails to start though it correctly starts with the same APK on an AVD (Android Virtual Device).

To start a debug session select your project, right click and select Debug As/Android NDK Application, as you can see below:

Do note though that you get the Android NDK Application option only if you download and install the NVidia debug manager plugin. Otherwise, you will not see the above option when you right-click.

You can set a breakpoint by double clicking a code line, as you can see here:

When the breakpoint hits, it will halt at that line of code with more information:

Sadly, debugging from Android using GDB may not always work, so you might find it helpful to add an extra debug tracing system in place as an alternative debugging method. For more info on this, contact me and I’ll share some tips on how you might do this.

Where To Go From Here?

Congrats, you now have your hands dirty with Cocos2D-X and have your iPhone and Android development environments fully set up and ready to go!

Stay tuned for my next Cocos2D-X tutorial, where I’ll show you how you can make a complete cross-platform Space Game with Cocos2D-X.

In the meantime, if you have any questions or comments about this Cocos2D-X tutorial or Cocos2D-X in general, please join the forum discussion below!