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 – 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.

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

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

  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
    
  6. Check the ndk-build version to ensure that NDK is working. If everything works, the Make version should appear:

    ndk-build -version
    
  7. Open a terminal and start the Android SDK manager with the following command:

    android
    

    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.