In this recipe, we will explore how to set up an Android NDK development environment in Windows.
Check the Windows edition and system type. An Android development environment can be set up on Windows XP 32-bit, Windows Vista 32- or 64-bit, and Windows 7 32- or 64-bit.
Android development requires Java JDK 6 or above to be installed. Follow these steps to install and configure Java JDK:
JAVA_HOME
and value as the path of the JDK installation root directory. This is shown as follows:PATH
(or Path
) environment variable. Insert %JAVA_HOME%in;
at the beginning of the value. If no PATH
or Path
variable exists, create a new variable with the value set to %JAVA_HOME%in
. Click on OK all the way through to dismiss all windows.javac -version
. If JDK is configured correctly, you will get the Java version in the output.Cygwin is a Linux-like environment for Windows to run software available on Linux. Android NDK development requires Cygwin 1.7 or higher installed to execute some Linux programs; for example, the GNU make.
Since NDK r7, the Windows NDK comes with a new ndk-build.cmd
build script, which uses NDK's prebuilt binaries for GNU make, awk, and other tools. Therefore Cygwin is not required for building NDK programs with ndk-build.cmd
. However, it is recommended that you still install Cygwin, because ndk-build.cmd
is an experimental feature and Cygwin is still needed by the debugging script ndk-gdb
.
Follow these steps to install Cygwin:
setup.exe
for Cygwin. Double-click on it after the download is complete in order to start the installation.Eclipse is a powerful software Integrated Development Environment (IDE) with an extensible plugin system. It is the recommended IDE to develop Android apps. Go to http://www.eclipse.org/downloads/, and download the Eclipse Classic or Eclipse IDE for Java developers. Extract the compressed file and it will be ready for use. Note that Android development requires Eclipse 3.6.2 (Helios) or greater.
The Android developer website provides an Android Developer Tools bundle at http://developer.android.com/sdk/index.html. It includes the Eclipse IDE with the ADT plugin, and the Android SDK. We can download this bundle and skip the SDK installation described in steps 1 to 10 of the following How to do it... section.
The following steps show you how to set up an Android NDK development environment in Windows. We will first set up an SDK development environment. Steps 1 to 10 can be skipped if SDK is already set up.
ADT
for Name and https://dl-ssl.google.com/android/eclipse/ for Location. Then click on OK.Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Cygwin.bat
under the cygwin
root directory. It contains the following content by default:@echo off C: chdir C:cygwinin bash --login -i
@echo off
before C
:set IS_UNIX= set JAVA_HOME=<JDK path> set PATH=<SDK path> ools;<NDK path> set ANDROID_NDK_ROOT=/cygdrive/<NDK path>
As an example, the file content on my machine is as follows; note that Progra~1
is the short name for the Program Files
folder:
set IS_UNIX=set JAVA_HOME=c:/Progra~1/Java/jdk1.7.0_05 set PATH=C:/Users/Administrator/AppData/Local/Android/android-sdk/tools;C:/Users/Administrator/Downloads/android-ndk-r8-windows/android-ndk-r8 set ANDROID_NDK_ROOT=/cygdrive/c/Users/Administrator/Downloads/android-ndk-r8-windows/android-ndk-r8
cygwin.bat
, then go to the samples/hello-jni
directory in NDK. Type the command ndk-build
. If the build is successful, it proves that the NDK environment is set up correctly:In this recipe, we first set up an Android SDK development environment and then the NDK development environment.
Android NDK does not require installation. We downloaded NDK, and configured the path to make it more convenient to use.
Cygwin is not required for Android SDK development, but is essential for NDK development because NDK uses some Linux tools that depend on Cygwin.
NDK plugin in ADT: NDK plugin for Eclipse is available in Android Development Tools (ADT), which allows us to build and debug Android NDK applications easily.