Setting up our Android Environment
Getting ready
We begin by setting up our Android environment. If you wish to build only on iOS, you can skip this step. To follow this recipe, you will need some files.
The following list provides the prerequisites that need to be downloaded to set up Android:
- Eclipse ADT (Android Developer Tools) with the Android SDK:
https://dl.google.com/android/adt/adt-bundle-mac-x86_64-20140702.zip
Eclipse ADT includes the Android SDK and Eclipse IDE. This is the Android development tool that is used to develop Android applications. Android Studio is an Android development IDE, but it is not supported to build NDK. The official site states that a version of Android Studio that supports NDK will be released soon. That's why we use Eclipse in this book.
- Android NDK (Native Development Kit):
https://dl.google.com/android/ndk/android-ndk-r10c-darwin-x86_64.bin
The NDK is required to build an Android application. You have to use NDK r10c. This is because compiling and linking errors may occur when using NDK r9 or an earlier version.
- Apache ANT:
You can download Apache ANT from http://ant.apache.org/bindownload.cgi
This is a java library that aids in building software. At the time of writing this book, version 1.9.4 was the latest stable version available.
How to do it...
- You begin by installing Eclipse ADT with the Android SDK, and then continue to unzip the zip file to any working directory you are aware of. I recommend that you unzip it to the
Documents
folder (~/adt-bundle-mac-x86_64-20140702
). ADT includes Android SDK and Eclipse. The SDK and Eclipse folders are located under the ADT folder. We call the SDK folder path that is located under the ADT folderANDROID_SDK_ROOT
. You have to remember it because you will use it the next recipe. Now, you can launch Eclipse from~/adt-bundle-mac-x86_64-20140702/eclipse/Eclipse.app
. - The next step is to update Android SDK:
- Open Eclipse from the
eclipse
folder located in ADT. - Go to Window | Android SDK Manager.
- After opening Android SDK Manager, check Tools and the latest Android SDK (
API21
),Android 2.3.3(API10)
, and any other SDK if necessary, as shown in the following screenshot: - Click on Install packages....
- Select each license and click on Accept, as shown in the following screenshot:
- After you accept all licenses, you will see that the Install button is enabled. Click on it.
- You have to wait for a long time to update and install the SDKs.
- Open Eclipse from the
- Installing NDK:
Open the terminal window and change the directory to the path from which you downloaded the package. Change the permission on the downloaded package and execute the package. For example:
$ chmod 700 android-ndk-r10c-darwin-x86_64.bin $ ./android-ndk-r10c-darwin-x86_64.bin
Finally, you move the
NDK
folder to theDocuments
folder. We call the installation path for NDKNDK_ROOT
.NDK_ROOT
is the address of the folder that contains the files, it helps the Cocos2dx engine to locate the native files of Android. You have to rememberNDK_ROOT
because you will use it in the next recipe. - Installing Apache ANT:
Unzip the file to the
Documents
folder. That's all. We callANT_ROOT
the installation path for ANT. You have to rememberANT_ROOT
, as we'll be using it in the next recipe. - Installing Java:
By entering the following command in the terminal, you can automatically install Java (if you haven't installed it earlier):
$ java --version
After installing it, you can check that it was successfully installed by entering the command again.
How it works...
Let's take a look at what we did throughout the recipe:
- Installing Eclipse: You can use Eclipse as an editor for Cocos2d-x
- Installing ADT: You can develop Android applications on Eclipse
- Installing NDK: You can build a C++ source code for Java
- Installing ANT: You can use command line tools for Cocos2d-x
Now you've finished setting up the Android development environment. At this point, you know how to install them and their path. In the next recipe, you will use them to build and execute Android applications. This will be very useful when you want to debug Android applications.