one of cocos2d-x‘s strengths is that it’s a cross-platform framework. one of those platforms is google’s android.
i have never done any android development before. luckily, the documentation for the initial setup of both the android sdk/ndk, and cocos2d-x, is pretty decent. however, there were a few wrinkles due to version changes in both the os (mavericks) and framework (3.0 alpha 1).
this is not a tutorial: i’m not going to go into step-by-step detail of what i did because everything went pretty much as documented. i’m sharing a few things someone might run into when setting up with an environment like mine.
the cocos2d-x/android development requirements can be divided into two major categories:
installing the android sdk and ndk
i did not go with the “early access preview” of the intellij-based android studio. i have no idea if or how that works with cocos2d-x.
i needed to reinstall the command-line developer tools for xcode 5 and mavericks, using the command:
why did i need the command-line developer tools? because mac os x no longer includes ant as of 10.9 (mavericks). ant is used for building android apps on the command line. i used homebrew to install it:
brew update # make sure you have the update that includes ant brew install ant
configuring for cocos2d-x
i pretty much followed the steps on this cocos2d-x wiki page for setting up a multiplatform project, which includes making the following edits to my
- added the android
platform-toolsdirectories to my
- defining the environment variables for
- i did not define
NDK_TOOLCHAIN_VERSION, because (at least in cocos2d-x 3.0 alpha 1), the
build_nativescript actually sets that for you
updating the android project
the wiki page walks you through this pretty well. there are two minor variations due to cocos2d-x 3.0 alpha 1:
the following command:
$ android update project -p ../../../cocos2dx/platform/android/java --target android-18
needs to be changed to:
$ android update project -p ../../../cocos/2d/platform/android/java --target android-18
(the path in the
-pparameter is different due to changes in directory layout in cocos2d-x 3.0 alpha 1.)
i then followed the rest of the documentation on that page and got the cocos2d-x hello world project running in both the emulator and on an actual hardware device. success!
a note on android emulation
the android emulator that comes with the android sdk is slow. a product/service called genymotion makes a faster one. however, it’s not so much an emulator as a simulator: much like the iOS simulator, the genymotion vm runs x86 code.
this is great if you’re writing java code, but trying to run native arm code on it will not work. i don’t know how to make the android toolchain build x86 code yet, so for now i’ll be sticking to google’s emulator and real hardware.
a note on eclipse
at the moment, i have not been able to build a cocos2d-x 3.0 alpha 1 project inside eclipse (command line builds work fine). so far, the only information i can find about using eclipse for cocos2d-x is for pre-3.0 versions, and doesn’t seem to work for 3.0 alpha 1.