Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Android NDK Beginner`s Guide - Second Edition
Android NDK Beginner`s Guide - Second Edition

Android NDK Beginner`s Guide - Second Edition: Discover the native side of Android and inject the power of C/C++ in your applications

eBook
£28.99 £32.99
Paperback
£41.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. £16.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Android NDK Beginner`s Guide - Second Edition

Chapter 1. Setting Up Your Environment

Are you ready to take up the mobile challenge? Is your computer switched on, mouse and keyboard plugged in, and screen illuminating your desk? Then let's not wait a minute more!

Developing Android applications requires a specific set of tools. You may already know about the Android Software Development Kit for pure Java applications. However, getting full access to the power of Android devices requires more: the Android Native Development Kit.

Setting up a proper Android environment is not that complicated, however it can be rather tricky. Indeed, Android is still an evolving platform and recent additions, such as Android Studio or Gradle, are not well supported when it comes to NDK development. Despite these annoyances, anybody can have a ready-to-work environment in an hour.

In this first chapter, we are going to:

  • Install prerequisites packages
  • Set up an Android development environment
  • Launch an Android emulator
  • Connect an Android device for development

Getting started with Android development

What differentiates mankind from animals is the use of tools. Android developers, the authentic species you belong to, are no different!

To develop applications on Android, we can use any of the following three platforms:

  • Microsoft Windows (XP and later)
  • Apple OS X (Version 10.4.8 or later)
  • Linux (distributions using GLibc 2.7 or later, such as latest versions of Ubuntu)

These systems are supported on x86 platforms (that is, PCs with processors such as Intel or AMD) in both 32- and 64-bit versions, except for Windows XP (32-bit only).

This is a good start but, unless you are able to read and write binary code as well as speak your mother tongue, having a raw OS is not enough. We also need software dedicated to Android development:

  • A JDK (Java Development Kit)
  • An Android SDK (Software Development Kit)
  • An Android NDK (Native Development Kit)
  • An IDE (Integrated Development Environment) such as Eclipse or Visual Studio (or vi for hard-core coders). Android Studio and IntelliJ are not yet well-suited for NDK development, although they provide basic support for native code.
  • A good old command-line shell to manipulate all these tools. We will use Bash.

Now that we know what tools are necessary to work with Android, let's start with the installation and setup process.

Note

The following section is dedicated to Windows. If you are a Mac or Linux user, you can jump to Setting up an OS X or Setting up Linux section.

Setting up Windows

Before installing the necessary tools, we need to set up Windows to host our Android development tools properly. Although it is not the most natural fit for Android development, Windows still provides a fully functional environment.

The following section explains how to set up the prerequisite packages on Windows 7. The process is the same for Windows XP, Vista, or 8.

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.
    Time for action – preparing Windows for Android development

    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:

    Time for action – preparing Windows for Android development

    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.

    Time for action – preparing Windows for Android development
  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:

    Time for action – preparing Windows for Android development
  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:

    Time for action – preparing Windows for Android development
  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:

    Time for action – preparing Windows for Android development

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.

Time for action – installing Android SDK and NDK on Windows

The Android Studio bundle already contains the Android SDK. Let's install it.

  1. Open your web browser and download the Android Studio bundle from http://developer.android.com/sdk/index.html.

    Run the downloaded program and follow the installation wizard. When requested, install all Android components.

    Time for action – installing Android SDK and NDK on Windows

    Then, choose the installation directories for Android Studio and the Android SDK (for example, C:\Android\android-studio and C:\Android\sdk).

  2. Launch Android Studio to ensure it is properly working. If Android Studio proposes to import settings from a previous installation, select your preferred option and click on OK.
    Time for action – installing Android SDK and NDK on Windows

    The Android Studio welcome screen should then appear. Close it.

    Time for action – installing Android SDK and NDK on Windows
  3. Go to http://developer.android.com/tools/sdk/ndk/index.html and download the Android NDK (not SDK!) suitable for your environment. Extract the archive inside the directory of your choice (for example, C:\Android\ndk).
  4. To easily access Android utilities from the command line, let's declare the Android SDK and NDK as environment variables. From now on, we will refer to these directories as $ANDROID_SDK and $ANDROID_NDK.

    Open the Environment Variables system window, as we did previously. Inside the System variables list, add the following:

    • The ANDROID_SDK variable with the SDK installation directory (for example, C:\Android\sdk)
    • The ANDROID_NDK variable with the NDK installation directories (for example, C:\Android\ndk)

    Prepend %ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools;%ANDROID_NDK%;, all separated by a semicolon, at the beginning of your PATH environment variable.

    Time for action – installing Android SDK and NDK on Windows
  5. All Windows environment variables should be imported automatically by Cygwin when launched. Open a Cygwin terminal and list the Android devices connected to your computer (even if none are currently) with adb to check whether SDK is working. No error should appear:
    adb devices
    
    Time for action – installing Android SDK and NDK on Windows
  6. Check the ndk-build version to ensure that NDK is working. If everything works, the Make version should appear:
    ndk-build -version
    
    Time for action – installing Android SDK and NDK on Windows
  7. Open Android SDK Manager, located in the ADB bundle directory's root.
    Time for action – installing Android SDK and NDK on Windows

    In the opened window, click on New to select all the packages and then click on the Install packages... button. Accept the licenses in the popup that appears and start the installation of Android development packages by clicking on the Install button.

    After a few long minutes, all packages are downloaded and a confirmation message indicating that the Android SDK manager has been updated appears.

    Validate and close the manager.

What just happened?

Android Studio is now installed on the system. Although it is now the official Android IDE, we are not going to use it much throughout the book because of its lack of support of the NDK. It is, however, absolutely possible to use Android Studio for Java development, and command line or Eclipse for C/C++.

The Android SDK has been set up through the Android Studio package. An alternative solution consists of manually deploying the SDK standalone package provided by Google. On the other hand, the Android NDK has been deployed manually from its archive. Both the SDK and NDK are made available through the command line thanks to a few environment variables.

To get a fully functional environment, all Android packages have been downloaded thanks to the Android SDK manager, which aims at managing all the platforms, sources, samples, and emulation features available through the SDK. This tool greatly simplifies the update of your environment when new SDK API and components are released. There is no need to reinstall or overwrite anything!

However, the Android SDK Manager does not manage the NDK, which explains why we downloaded it separately, and why you will need to update it manually in the future.

Tip

Installing all Android packages is not strictly necessary. Only the SDK platform (and possibly Google APIs) releases targeted by your application are really required. Installing all packages may avoid troubles when importing other projects or samples though.

The installation of your Android development environment is not over yet. We still need one more thing to develop comfortably with the NDK.

Note

This is the end of the section dedicated to the Windows setup. The following section is dedicated to OS X.

Setting up OS X

Apple computers have a reputation for being simple and easy to use. I must say that this adage is rather true when it comes to Android development. Indeed, as a Unix-based system, OS X is well adapted to run the NDK toolchain.

The following section explains how to set up the prerequisite packages on Mac OS X Yosemite.

Time for action – preparing OS X for Android development

To develop with the Android NDK on OS X, we need to set up a few prerequisites: a JDK, Developer Tools, and Ant.

  1. A JDK is preinstalled on OS X 10.6 Snow Leopard and below. On these systems, Apple's JDK is in version 6. Since this version is deprecated, it is advised to install an up-to-date JDK 7 (or JDK 8, although it is not officially supported at the time this book is written).

    On the other hand, OS X 10.7 Lion and above does not have a default JDK installed. Installing the JDK 7 is thus mandatory.

    To do so, download Oracle JDK 7 from the Oracle website at http://www.oracle.com/technetwork/java/javase/downloads/index.html. Launch the DMG and follow the installation wizard until the end.

    Time for action – preparing OS X for Android development

    Check the Java version to ensure that the JDK is properly installed.

    java -version
    
    Time for action – preparing OS X for Android development

    Tip

    To know if a JDK 6 is installed, check Java Preferences.app located by going to Applications | Utilities on your Mac. If you have JDK 7, check whether you have the Java icon under System Preferences.

  2. All Developer Tools are included in the XCode installation package (Version 5, at the time this book is written). XCode is provided on the AppStore for free. Starting from OS X 10.9, the Developer Tools package can be installed separately from a terminal prompt with the following command:
    xcode-select --install
    
    Time for action – preparing OS X for Android development

    Then, from the popup window that appears, select Install.

  3. To build native code with the Android NDK, whether XCode or the single Developer Tools package is installed, we need Make. Open a terminal prompt and check the Make version to ensure that it correctly works:
    make –version
    
    Time for action – preparing OS X for Android development
  4. On OS X 10.9 and later, Ant must be installed manually. 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, /Developer/Ant).

    Then, create or edit the file ~/.profile and make Ant available on the system path by appending the following:

    export ANT_HOME="/Developer/Ant"
    export PATH=${ANT_HOME}/bin:${PATH}

    Log out from your current session and log in again (or restart your computer) and check whether Ant is correctly installed by checking its version from the command line:

    ant –version
    
    Time for action – preparing OS X for Android development

What just happened?

Our OS X system is now set up with the necessary packages to host Android development tools:

  • A JDK 7, which contains the runtime and tools necessary to build Java applications on Android and to run the Eclipse IDE as well as Ant.
  • Developer Tools package, which packages various command-line utilities. It includes Make, which is required by the Android NDK compilation system to build native code.
  • 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 Kit.

Installing Android development kits on OS X

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 are going to install these kits to start developing native Android applications on Mac OS X Yosemite.

Time for action – installing Android SDK and NDK on OS X

The Android Studio bundle already contains the Android SDK. Let's install it.

  1. Open your web browser and download the Android Studio bundle from http://developer.android.com/sdk/index.html.
  2. Run the downloaded DMG file. In the window that appears, drag the Android Studio icon into Applications and wait for Android Studio to be fully copied on the system.
    Time for action – installing Android SDK and NDK on OS X
  3. Run Android Studio from Launchpad.

    If an error Unable to find a valid JVM appears (because Android Studio cannot find a suitable JRE when launched), you can run Android Studio from the command line as follows (using the appropriate JDK path):

    export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk
    open /Applications/Android\ Studio.apps
    

    Tip

    To solve the Android Studio startup issue, you can also install the former JDK 6 package provided by Apple. Beware! This version is outdated and thus, deprecated.

    If Android Studio proposes to import settings from a previous installation, select your preferred option and click on OK.

    Time for action – installing Android SDK and NDK on OS X

    In the next Setup Wizard screen that appears, select the Standard installation type and continue the installation.

    Time for action – installing Android SDK and NDK on OS X

    Complete the installation until the Android Studio welcome screen appears. Then, close Android Studio.

    Time for action – installing Android SDK and NDK on OS X
  4. Go to http://developer.android.com/tools/sdk/ndk/index.html and download the Android NDK (not SDK!) archive suitable for your environment. Extract it inside the directory of your choice (for example, ~/Library/Android/ndk).
  5. To easily access Android utilities from the command line, let's declare the Android SDK and NDK as environment variables. From now on, we will refer to these directories as $ANDROID_SDK and $ANDROID_NDK. Assuming you use the default Bash command-line shell, create or edit .profile (which is a hidden file!) in your home directory and append the following instructions (adapt paths according to your installation):
    export ANDROID_SDK="~/Library/Android/sdk"
    export ANDROID_NDK="~/Library/Android/ndk"
    export PATH="${ANDROID_SDK}/tools:${ANDROID_SDK}/platform-tools:${ANDROID_NDK}:${PATH}"
  6. Log out from your current session and log in again (or restart your computer). List the Android devices connected to your computer (even if none currently are) with adb to check whether Android SDK is working. No error should appear:
    adb devices
    
    Time for action – installing Android SDK and NDK on OS X
  7. Check the ndk-build version to ensure that NDK is working. If everything works, the Make version should appear:
    ndk-build -version
    
    Time for action – installing Android SDK and NDK on OS X
  8. Open a terminal and start the Android SDK manager with the following command:
    android
    
    Time for action – installing Android SDK and NDK on OS X

    In the opened window, click on New to select all the packages and then click on the Install packages... button. Accept the licenses in the popup that appears and start the installation of all Android packages by clicking on the Install button.

    After a few long minutes, all packages are downloaded and a confirmation message indicating that the Android SDK manager has been updated appears.

    Validate and close the manager.

What just happened?

Android Studio is now installed on the system. Although it is now the official Android IDE, we will not use it much through the book because of its lack of support of the NDK. It is, however, absolutely possible to use Android Studio for Java development, and command line or Eclipse for C/C++.

The Android SDK has been set up through the Android Studio package. An alternative solution consists of manually deploying the SDK standalone package provided by Google. On the other hand, the Android NDK has been deployed manually from its archive. Both the SDK and NDK are made available through the command line, thanks to a few environment variables.

Tip

OS X is tricky when it comes to environment variables. They can be easily declared in .profile for applications launched from a terminal, as we just did. They can also be declared using an environment.plist file for GUI applications, which are not launched from Spotlight.

To get a fully functional environment, all Android packages have been downloaded thanks to the Android SDK manager, which aims at managing all the platforms, sources, samples, and emulation features available through the SDK. This tool greatly simplifies the update of your environment when new SDK API and components are released. There is no need to reinstall or overwrite anything!

However, the Android SDK manager does not manage the NDK, which explains why we downloaded it separately, and why you will need to update it manually in the future.

Tip

Installing all Android packages is not strictly necessary. Only the SDK platform (and possibly Google APIs) releases targeted by your application are really required. Installing all packages may avoid troubles importing other projects or samples though.

The installation of your Android development environment is not over yet. We still need one more thing to develop comfortably with the NDK.

Note

This is the end of the section dedicated to the OS X setup. The following section is dedicated to Linux.

Setting up Linux

Linux is naturally suited for Android development as the Android toolchain is Linux-based. Indeed, as a Unix-based system, Linux is well adapted to run the NDK toolchain. Beware, however, that commands to install packages may vary depending on your Linux distribution.

The following section explains how to set up the prerequisite packages on Ubuntu 14.10 Utopic Unicorn.

Time for action – preparing Ubuntu for Android development

To develop with the Android NDK on Linux, we need to set up a few prerequisites: Glibc, Make, OpenJDK, and Ant.

  1. From Command Prompt, check whether Glibc (the GNU C standard library) 2.7 or later, usually shipped with Linux systems by default, is installed:
    ldd -–version
    
    Time for action – preparing Ubuntu for Android development
  2. Make is also required to build native code. Install it from the build-essential package (requires administrative privilege):
    sudo apt-get install build-essential
    

    Run the following command to ensure Make is correctly installed, in which case its version is displayed:

    make –version
    
    Time for action – preparing Ubuntu for Android development
  3. On 64-bit Linux systems, install the 32-bit libraries compatibility package, as Android SDK has binaries compiled for 32 bits only. To do so on Ubuntu 13.04 and earlier, simply install the ia32-libs package:
    sudo apt-get install ia32-libs
    

    On Ubuntu 13.10 64 bits and later, this package has been removed. So, install the required packages manually:

    sudo apt-get install lib32ncurses5 lib32stdc++6 zlib1g:i386 libc6-i386
    
  4. Install Java OpenJDK 7 (or JDK 8, although it is not officially supported at the time this book is written). Oracle JDK is also fine:
    sudo apt-get install openjdk-7-jdk
    

    Ensure JDK is properly installed by running Java and checking its version:

    java –version
    
    Time for action – preparing Ubuntu for Android development
  5. Install Ant with the following command (requires administrative privilege):
    sudo apt-get install ant
    

    Check whether Ant is properly working:

    ant -version
    
    Time for action – preparing Ubuntu for Android development

What just happened?

Our Linux system is now prepared with the necessary packages to host Android development tools:

  • The build-essential package, which is a minimal set of tools for compilation and packaging on Linux Systems. It includes Make, which is required by the Android NDK compilation system to build native code. GCC (the GNU C Compiler) is also included but is not required as Android NDK already contains its own version.
  • 32-bit compatibility libraries for 64-bit systems, since the Android SDK still uses 32-bit binaries.
  • 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.
  • 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 Linux

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 Ubuntu 14.10 Utopic Unicorn.

Time for action – installing Android SDK and NDK on Ubuntu

The Android Studio bundle already contains the Android SDK. Let's install it.

  1. Open your web browser and download the Android Studio bundle from http://developer.android.com/sdk/index.html. Extract the downloaded archive in the directory of your choice (for example, ~/Android/Android-studio).
  2. Run the Android Studio script bin/studio.sh. If Android Studio proposes to import settings from a previous installation, select your preferred option and click on OK.
    Time for action – installing Android SDK and NDK on Ubuntu

    In the next Setup Wizard screen that appears, select a Standard installation type and continue installation.

    Time for action – installing Android SDK and NDK on Ubuntu

    Complete installation until the Android Studio welcome screen. Then, close Android Studio.

    Time for action – installing Android SDK and NDK on Ubuntu
  3. Go to http://developer.android.com/tools/sdk/ndk/index.html and download the Android NDK (not SDK!) archive suitable for your environment. Extract it inside the directory of your choice (for example, ~/Android/Ndk).
  4. To easily access Android utilities from the command line, let's declare the Android SDK and NDK as environment variables. From now on, we will refer to these directories as $ANDROID_SDK and $ANDROID_NDK. Edit your .profile file (beware since this is a hidden file!) in your home directory and add the following variables at the end (adapt their path according to your installation directories):
    export ANDROID_SDK="~/Android/Sdk"
    export ANDROID_NDK="~/Android/Ndk"
    export PATH="${ANDROID_SDK}/tools:${ANDROID_SDK}/platform-tools:${ANDROID_NDK}:${PATH}"
  5. Log out from your current session and log in again (or restart your computer). List the Android devices connected to your computer (even if none currently are) with adb to check whether Android SDK is working. No error should appear:
    adb devices
    
    Time for action – installing Android SDK and NDK on Ubuntu
  6. Check the ndk-build version to ensure that NDK is working. If everything works, the Make version should appear:
    ndk-build -version
    
    Time for action – installing Android SDK and NDK on Ubuntu
  7. Open a terminal and start the Android SDK manager with the following command:
    android
    
    Time for action – installing Android SDK and NDK on Ubuntu

    In the opened window, click on New to select all the packages, and then click on the Install packages... button. Accept the licenses in the popup that appears and start the installation of all Android package by clicking on the Install button.

    After a few long minutes, all packages are downloaded and a confirmation message indicating that the Android SDK manager has been updated appears.

    Validate and close the manager.

What just happened?

Android Studio is now installed on the system. Although it is now the official Android IDE, we are not going to use it much throughout the book because of its lack of support of the NDK. It is, however, absolutely possible to use Android Studio for Java development, and the command line or Eclipse for C/C++.

The Android SDK has been set up through the Android Studio package. An alternative solution consists of manually deploying the SDK standalone package provided by Google. On the other hand, the Android NDK has been deployed manually from its archive. Both the SDK and NDK are made available through the command line, thanks to a few environment variables.

To get a fully functional environment, all Android packages have been downloaded thanks to the Android SDK manager, which aims at managing all the platforms, sources, samples, and emulation features available through the SDK. This tool greatly simplifies the update of your environment when new SDK API and components are released. There is no need to reinstall or overwrite anything!

However, the Android SDK manager does not manage the NDK, which explains why we downloaded it separately, and why you will need to update it manually in the future.

Tip

Installing all Android packages is not strictly necessary. Only the SDK platform (and possibly Google APIs) releases targeted by your application are really required. Installing all packages may avoid trouble when importing other projects or samples though.

The installation of not or Android development environment is not over yet. We still need one more thing to develop comfortably with the NDK.

Note

This is the end of the section dedicated to the Linux setup. The following section is for all operating systems.

Installing the Eclipse IDE

Because of Android Studio limitations, Eclipse is still one of the most appropriate IDEs to develop native code on Android. Using an IDE is not required though; command-line lovers or vi fanatics can skip this part!

In the following section, we will see how to set up Eclipse.

Left arrow icon Right arrow icon

Description

Are you an Android Java programmer who needs more performance? Are you a C/C++ developer who doesn’t want to bother with the complexity of Java and its out-of-control garbage collector? Do you want to create fast intensive multimedia applications or games? If you’ve answered yes to any of these questions then this book is for you. With some general knowledge of C/C++ development, you will be able to dive headfirst into native Android development.

What you will learn

  • Build your first Android native project from scratch
  • Communicate with Java through Java Native Interfaces
  • Learn the key design intricacies of creating a native OpenGL ES 2.0 graphics application
  • Initialize, play, and record sound and music with OpenSL ES
  • Handle input events and sensors to create different interaction types
  • Port an existing library on Android by compiling most common C++ frameworks on Android
  • Interface and optimize the existing code with RenderScript
  • Combine graphics, sound, input, sensors, and physics in your application

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 28, 2015
Length: 494 pages
Edition : 1st
Language : English
ISBN-13 : 9781783989645
Vendor :
Google
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. £16.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Apr 28, 2015
Length: 494 pages
Edition : 1st
Language : English
ISBN-13 : 9781783989645
Vendor :
Google
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 115.97
Android Game Programming By Example
£36.99
Learning Java by Building Android Games
£36.99
Android NDK Beginner`s Guide - Second Edition
£41.99
Total £ 115.97 Stars icon

Table of Contents

12 Chapters
1. Setting Up Your Environment Chevron down icon Chevron up icon
2. Starting a Native Android Project Chevron down icon Chevron up icon
3. Interfacing Java and C/C++ with JNI Chevron down icon Chevron up icon
4. Calling Java Back from Native Code Chevron down icon Chevron up icon
5. Writing a Fully Native Application Chevron down icon Chevron up icon
6. Rendering Graphics with OpenGL ES Chevron down icon Chevron up icon
7. Playing Sound with OpenSL ES Chevron down icon Chevron up icon
8. Handling Input Devices and Sensors Chevron down icon Chevron up icon
9. Porting Existing Libraries to Android Chevron down icon Chevron up icon
10. Intensive Computing with RenderScript Chevron down icon Chevron up icon
11. Afterword Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6
(8 Ratings)
5 star 25%
4 star 50%
3 star 0%
2 star 12.5%
1 star 12.5%
Filter icon Filter
Top Reviews

Filter reviews by




iPaul Aug 20, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good intro to the NDK usage with Android Studio.
Amazon Verified review Amazon
Fabio Radin Jul 29, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love this book! This is a great book to start with the Android NDK, even it it is targeted to someone that has some experience developing on Android and has some programming experience in C/C++. I really appreciated the chapters on setting it up for Linux, Mac and Windows and, over the top, inside Android Studio!I liked a lot that it provides information about integrating existing C++ code in Android, as OpenGL from C++, and integrating both Box2D, and the Irrlicht open source 3d game engine.
Amazon Verified review Amazon
jdc Oct 02, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book is a tricky one to review. I'm giving 4 stars because I think it's coverage of the NDK is fairly good but I'm personally not too interested in writing app completely in C++. I would have preferred the book to focus more on the interaction between Java and C++ since to get the most out of Android you really have to use Java
Amazon Verified review Amazon
Krunal Jhaveri Jul 13, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book is really useful. It is right from the scratch and covers a wide range of topics. Examples are lucid and easy to implement.
Amazon Verified review Amazon
Robin T. Wernick May 25, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book on the Android NDK is the most comprehensive source of NDK examples in both C and C++ that I have seen in five years of searching. Had it included program development on the Android Studio instead of the obsolete and often unconfigurable Eclipse, I would have given it five stars.I'm very glad to have this book because it's clarity and organization helped to clarify some lingering issues concerning the details of using C(++) libraries and controlling sensors that were overlooked in most of the previous sources. Now, I have a source that tells me in detail how to control the UI and respond to attitude and touch events in the NDK. Reading sensors and files are also included.I highly recommend buying this book if you want to work with the NDK and potentially build C(++) libraries that can support both Android and iPhone mobile applications.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.