Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android NDK Beginner`s Guide - Second Edition

You're reading from   Android NDK Beginner`s Guide - Second Edition Discover the native side of Android and inject the power of C/C++ in your applications

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781783989645
Length 494 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sylvain Ratabouil Sylvain Ratabouil
Author Profile Icon Sylvain Ratabouil
Sylvain Ratabouil
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

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

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.

You have been reading a chapter from
Android NDK Beginner`s Guide - Second Edition
Published in: Apr 2015
Publisher: Packt
ISBN-13: 9781783989645
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image