Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – preparing Windows for Android development


To develop with the Android NDK on Windows, we need to set up a few prerequisites: Cygwin, a JDK, and Ant.

  1. Go to http://cygwin.com/install.html and download the Cygwin setup program suitable for your environment. Once downloaded, execute it.

  2. In the installation window, click on Next and then Install from Internet.

    Follow the installation wizard screens. Consider selecting a download site from where Cygwin packages are downloaded in your country.

    Then, when proposed, include the Devel, Make, Shells, and bash packages:

    Follow the installation wizard until the end. This may take some time depending on your Internet connection.

  3. Download Oracle JDK 7 from the Oracle website at http://www.oracle.com/technetwork/java/javase/downloads/index.html (or JDK 8, although it is not officially supported at the time this book is written). Launch and follow the installation wizard until the end.

  4. Download Ant from its website at http://ant.apache.org/bindownload.cgi and unzip its binary package in the directory of your choice (for example, C:\Ant).

  5. After installation, define JDK, Cygwin, and Ant locations in environment variables. To do so, open Windows Control Panel and go to the System panel (or right-click on the Computer item in the Windows Start menu and select Properties).

    Then, go to Advanced system settings. The System Properties window appears. Finally, select the Advanced tab and click on the Environment Variables button.

  6. In the Environment Variables window, inside the System variables list, add:

    • The CYGWIN_HOME variable with the Cygwin installation directory as the value (for example, C:\Cygwin)

    • The JAVA_HOME variable with the JDK installation directory as the value

    • The ANT_HOME variable with the Ant installation directory as the value (for example, C:\Ant)

    Prepend %CYGWIN_HOME%\bin;%JAVA_HOME%\bin;%ANT_HOME%\bin;, all separated by a semicolon, at the beginning of your PATH environment variable.

  7. Finally, launch a Cygwin terminal. Your profile files get created on the first launch. Check the make version to ensure Cygwin works:

    make –version
    

    You will see the following output:

  8. Ensure JDK is properly installed by running Java and checking its version. Check carefully to make sure the version number corresponds to the newly installed JDK:

    java –version
    

    You will see the following output on the screen:

  9. From a classic Windows terminal, check the Ant version to make sure it is properly working:

    ant -version
    

    You will see the following on the terminal:

What just happened?

Windows is now set up with all the necessary packages to host Android development tools:

  • Cygwin, which is an open source software collection, allows the Windows platform to emulate a Unix-like environment. It aims at natively integrating software based on the POSIX standard (such as Unix, Linux, and so on) into Windows. It can be considered as an intermediate layer between applications originated from Unix/Linux (but natively recompiled on Windows) and the Windows OS itself. Cygwin includes Make, which is required by the Android NDK compilation system to build native code.

    Tip

    Even if Android NDK R7 introduced native Windows binaries, which does not require a Cygwin runtime, it is still recommended to install the latter for debugging purpose.

  • A JDK 7, which contains the runtime and tools necessary to build Java applications on Android and run the Eclipse IDE as well as Ant. The only real trouble that you may encounter when installing a JDK is some interferences from a previous installation, such as an existing Java Runtime Environment (JRE). Proper JDK use can be enforced through the JAVA_HOME and PATH environment variables.

    Tip

    Defining the JAVA_HOME environment variable is not required. However, JAVA_HOME is a popular convention among Java applications, Ant being one of them. It first looks for the java command in JAVA_HOME (if defined) before looking in PATH. If you install an up-to-date JDK in another location later on, do not forget to update JAVA_HOME.

  • Ant, which is a Java-based build automation utility. Although not a requirement, it allows building Android applications from the command line, as we will see in Chapter 2, Starting a Native Android Project. It is also a good solution to set up a continuous integration chain.

The next step consists of setting up the Android development kits.

Installing Android development kits on Windows

Android requires specific development kits to develop applications: the Android SDK and NDK. Hopefully, Google has thought about the developer community and provides all the necessary tools for free.

In the following part, we will install these kits to start developing native Android applications on Windows 7.