Objectives
- Install everything needed to build and run Cocos2d-X 3.x beta samples on an Android 4.3 device
- Uses only the command line, (NOT using eclipse at all).
Prerequisites
- Some game programming knowledge
- Windows 7 PC
- Android device with Android 4.3 (if not, either use the emulator or download the necessary SDKs and modify the tutorial as necessary)
Download
- Android SDK bundle: http://dl.google.com/android/adt/adt-bundle-windows-x86-20131030.zip
- Android NDK: http://dl.google.com/android/ndk/android-ndk-r9c-windows-x86.zip
- Cocos2d-X: http://cdn.cocos2d-x.org/cocos2d-x-3.0beta2.zip
- Apache ANT: http://www.us.apache.org/dist//ant/binaries/apache-ant-1.9.3-bin.zip
- Java SE SDK: http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-windows-i586.exe
- Portable Python 2.7.5.1: http://elvis.rowan.edu/mirrors/portablepython/v2.7/PortablePython_2.7.5.1.exe
Note: Python 3.x is not supported by the python script files in Cocos2d-x 3.x (at the time of writing)
Installation
- Extract Android SDK bundle to somewhere (without spaces in the path), e.g. D:\
- Extract or install the rest of the downloads into the Android SDK folder, e.g. D:\AndroidDevelopmentKit, so it should now contain these:
- In a text editor, create the following setup_cocos_env.bat, and save it into D:\AndroidDevelopmentKit
set NDK_ROOT=D:\AndroidDevelopmentKit\android-ndk-r9c\ set path=D:\AndroidDevelopmentKit\Portable_Python_2.7.5.1\App;D:\AndroidDevelopmentKit\Java\jdk1.7.0_45\jre\bin;D:\AndroidDevelopmentKit\apache-ant-1.9.3\bin;D:\AndroidDevelopmentKit\sdk\tools;D:\AndroidDevelopmentKit\sdk\platform-tools;%path% set JAVA_HOME=D:\AndroidDevelopmentKit\jdk1.7.0_45 cd cocos2d-x-3.0beta2 cmd
- This sets up the various paths necessary for building the Cocos2d-X samples.
- Building and installing the samples
- Double-click on this batch file. It will open a command prompt in the Cocos2d-X folder.
- Run the following commands to see if the paths are set up correctly (simply type those commands in without additional parameters, and without changing directory)
- android
- adb
- ant
- python
- If any of these fail, check your paths
- If ok, go on to build the samples
cd build python android-build.py all (This will take a while)
- Go to build the java files needed for creating the apks.
cd cocos\2d\platform\android\java android update project -p . -t android-18 (assuming you have a device with Android 4.3) ant debug ant release (so that we won’t need to do it again)
- Go to every project folder and do the following (using HelloCpp as example):
cd ..\..\..\..\..\samples\Cpp\HelloCpp\proj.android
android update project -p . -t android-18
ant debug install
- It will be installed on your device.
- Run the samples!
Eclipse Notes
- I’ve not covered how to set it up with Eclipse because that wasn’t my focus.
- I’ve quickly tried, and it doesn’t package the apk with the libs, but didn’t investigate further. Another time perhaps. 🙂
No Comments.