Setting up Cocos2d-x 3.0beta2 for Android on Windows and Ant build

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

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.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">