Android NDK
Beginner's Guide
Discover the nave side of Android and inject the power
of C/C++ in your applicaons
Sylvain Ratabouil
BIRMINGHAM - MUMBAI
Android NDK
Beginner's Guide
Copyright © 2012 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmied in any form or by any means, without the prior wrien permission of the
publisher, except in the case of brief quotaons embedded in crical arcles or reviews.
Every eort has been made in the preparaon of this book to ensure the accuracy of the
informaon presented. However, the informaon contained in this book is sold without
warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly
or indirectly by this book.
Packt Publishing has endeavored to provide trademark informaon about all of the companies
and products menoned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this informaon.
First published: January 2012
Producon Reference: 1200112
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84969-152-9
www.packtpub.com
Cover Image by Marcus Grandon ()
Credits
Author
Sylvain Ratabouil
Reviewers
Marko Gargenta
Dr. Frank Grützmacher
Robert Mitchell
Acquision Editor
Sarah Cullington
Lead Technical Editor
Dayan Hyames
Technical Editor
Pramila Balan
Copy Editor
Laxmi Subramanian
Project Coordinator
Jovita Pinto
Proofreader
Lynda Sliwoski
Indexer
Hemangini Bari
Graphics
Valenna D'silva
Producon Coordinators
Prachali Bhiwandkar
Melwyn D'sa
Nilesh Mohite
Cover Work
Alwin Roy
About the Author
Sylvain Ratabouil is a conrmed IT consultant with experience in C++ and Java
technologies. He worked for the space industry and got involved in aeronauc projects at
Valtech Technologies where he now takes part in the Digital Revoluon.
Sylvain earned the master's degree in IT from Paul Sabaer University in Toulouse and did
M.Sc. in Computer Science from Liverpool University.
As a technology lover, he is passionate about mobile technologies and cannot live or sleep
without his Android smartphone.
I would like to thank Steven Wilding for oering me to write this book;
Sneha Harkut and Jovita Pinto for awaing me with so much paence;
Reshma Sundaresan, and Dayan Hyames for pung this book on the
right track; Sarah Cullington for helping me nalizing this book;
Dr. Frank Grützmacher, Marko Gargenta, and Robert Mitchell for
all their helpful comments.
About the Reviewers
Dr. Frank Grützmacher has worked for several major German rms in the area of large
distributed systems. He was an early user of dierent Corba implementaons in the past.
He got his Ph.D. in the eld of electrical engineering, but with the focus on distributed
heterogeneous systems. In 2010, he was involved in a project, which changed parts of the
Android plaorm for a manufacturer. From there, he got his knowledge about the android
NDK and nave processes on this plaorm.
He has already worked as a reviewer for another Android 3.0 book.
Robert Mitchell is an MIT graduate with over 40 years experience in Informaon
Technology and is semirered. He has developed soware for all the big iron companies:
IBM, Amdahl, Fujitsu, Naonal Semiconductor, and Storage Technology. Soware companies
include Veritas and Symantec. Recent languages that he knows are Ruby and Java, with a
long background in C++.
www.PacktPub.com
Support les, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support les and downloads related to
your book.
Did you know that Packt oers eBook versions of every book published, with PDF and ePub
les available? You can upgrade to the eBook version at
www.PacktPub.com and as a print
book customer, you are entled to a discount on the eBook copy. Get in touch with us at
for more details.
At
www.PacktPub.com, you can also read a collecon of free technical arcles, sign up for
a range of free newsleers and receive exclusive discounts and oers on Packt books and
eBooks.
Do you need instant soluons to your IT quesons? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's enre library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print and bookmark content
On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine enrely free books. Simply use your login credenals for
immediate access.
Table of Contents
Preface 1
Chapter 1: Seng Up your Environment 7
Geng started with Android development 7
Seng up Windows 8
Time for acon – preparing Windows for Android development 8
Installing Android development kits on Windows 12
Time for acon – installing Android SDK and NDK on Windows 13
Seng up Mac OS X 18
Time for acon – preparing Mac OS X for Android development 18
Installing Android development kits on Mac OS X 20
Time for acon – installing Android SDK and NDK on Mac OS X 20
Seng up Linux 22
Time for acon – preparing Ubuntu Linux for Android development 22
Installing Android development kits on Linux 27
Time for acon – installing Android SDK and NDK on Ubuntu 27
Seng up the Eclipse development environment 29
Time for acon – installing Eclipse 29
Emulang Android 33
Time for acon – creang an Android virtual device 33
Developing with an Android device on Windows and Mac OS X 37
Time for acon – seng up your Android device on Windows and Mac OS X 37
Developing with an Android device on Linux 39
Time for acon – seng up your Android device on Ubuntu 39
Troubleshoong a development device 42
Summary 43
Chapter 2: Creang, Compiling, and Deploying Nave Projects 45
Compiling and deploying NDK sample applicaons 46
Time for acon – compiling and deploying the hellojni sample 46
Table of Contents
[ ii ]
Exploring Android SDK tools 51
Android debug bridge 51
Project conguraon tool 54
Creang your rst Android project using eclipse 56
Time for acon – iniang a Java project 56
Introducing Dalvik 59
Interfacing Java with C/C++ 60
Time for acon – calling C code from Java 60
More on Makeles 65
Compiling nave code from Eclipse 67
Time for acon – creang a hybrid Java/C/C++ project 67
Summary 72
Chapter 3: Interfacing Java and C/C++ with JNI 73
Working with Java primives 74
Time for acon – building a nave key/value store 75
Referencing Java objects from nave code 85
Time for acon – saving a reference to an object in the Store 85
Local and global JNI references 90
Throwing excepons from nave code 91
Time for acon – raising excepons from the Store 92
JNI in C++ 96
Handling Java arrays 96
Time for acon – saving a reference to an object in the Store 97
Checking JNI excepons 106
Summary 107
Chapter 4: Calling Java Back from Nave Code 109
Synchronizing Java and nave threads 110
Time for acon – running a background thread 111
Aaching and detaching threads 120
More on Java and nave code lifecycles 121
Calling Java back from nave code 122
Time for acon – invoking Java code from a nave thread 122
More on callbacks 133
JNI method denions 134
Processing bitmaps navely 135
Time for acon – decoding camera feed from nave code 136
Summary 146
Chapter 5: Wring a Fully-nave Applicaon 147
Creang a nave acvity 148
Time for acon – creang a basic nave acvity 148
Table of Contents
[ iii ]
Handling acvity events 155
Time for acon – handling acvity events 155
More on Nave App Glue 166
UI thread 167
Nave thread 168
Android_app structure 170
Accessing window and me navely 171
Time for acon – displaying raw graphics and implemenng a mer 172
More on me primives 181
Summary 181
Chapter 6: Rendering Graphics with OpenGL ES 183
Inializing OpenGL ES 184
Time for acon – inializing OpenGL ES 184
Reading PNG textures with the asset manager 193
Time for acon – loading a texture in OpenGL ES 194
Drawing a sprite 208
Time for acon – drawing a Ship sprite 209
Rendering a le map with vertex buer objects 220
Time for acon – drawing a le-based background 221
Summary 238
Chapter 7: Playing Sound with OpenSL ES 239
Inializing OpenSL ES 241
Time for acon – creang OpenSL ES engine and output 241
More on OpenSL ES philosophy 248
Playing music les 249
Time for acon – playing background music 249
Playing sounds 256
Time for acon – creang and playing a sound buer queue 257
Event callback 266
Recording sounds 268
Summary 272
Chapter 8: Handling Input Devices and Sensors 273
Interacng with Android 274
Time for acon – handling touch events 276
Detecng keyboard, D-Pad, and Trackball events 288
Time for acon – handling keyboard, D-Pad, and trackball, navely 289
Probing device sensors 298
Time for acon – turning your device into a joypad 300
Summary 313
Table of Contents
[ iv ]
Chapter 9: Porng Exisng Libraries to Android 315
Developing with the Standard Template Library 316
Time for acon – embedding GNU STL in DroidBlaster 316
Stac versus shared 326
STL performances 327
Compiling Boost on Android 328
Time for acon – embedding Boost in DroidBlaster 328
Porng third-party libraries to Android 338
Time for acon – compiling Box2D and Irrlicht with the NDK 339
GCC opmizaon levels 346
Mastering Makeles 346
Makele variables 347
Makele Instrucons 348
Summary 351
Chapter 10: Towards Professional Gaming 353
Simulang physics with Box2D 353
Time for acon – simulang physics with Box2D 354
More on collision detecon 366
Collision modes 367
Collision ltering 368
More resources about Box2D 369
Running a 3D engine on Android 369
Time for acon – rendring 3D graphics with Irrlicht 370
More on Irrlicht scene management 381
Summary 382
Chapter 11: Debugging and Troubleshoong 383
Debugging with GDB 383
Time for acon – debugging DroidBlaster 384
Stack trace analysis 392
Time for acon – analysing a crash dump 392
More on crash dumps 396
Performance analysis 397
Time for acon – running GProf 398
How it works 403
ARM, thumb, and NEON 403
Summary 405
Index 411
Preface
The short history of compung machines has witnessed some major events, which
forever transformed our usage of technology. From the rst massive main frames to
the democrazaon of personal computers, and then the interconnecon of networks.
Mobility is the next revoluon. Like the primive soup, all the ingredients are now
gathered: an ubiquitous network, new social, professional and industrial usages, a
powerful technology. A new period of innovaon is blooming right now in front of our
eyes. We can fear it or embrace it, but it is here, for good!
The mobile challenge
Today's mobile devices are the product of only a few years of evoluon, from the rst
transportable phones to the new ny high-tech monsters we have in our pocket. The
technological me scale is denitely not the same as the human one.
Only a few years ago, surng on the successful wave of its musical devices, Apple and
its founder Steve Jobs combined the right hardware and the right soware at the right
me not only to sasfy our needs, but to create new ones. We are now facing a new
ecosystem looking for a balance between iOS, Windows Mobile, Blackberry, WebOS, and
more importantly Android! The appete of a new market could not let Google apathec.
Standing on the shoulder of this giant Internet, Android came into the show as the best
alternave to the well established iPhones and other iPads. And it is quickly becoming
the number one.
In this modern Eldorado, new usages or technically speaking, applicaons (acvies, if
you already are an Android adept) sll have to be invented. This is the mobile challenge.
And the dematerialized country of Android is the perfect place to look for. Android is
(mostly) an open source operang system now supported by a large panel of mobile
device manufacturers.
Preface
[ 2 ]
Portability among hardware and adaptability to the constrained resources of mobile devices:
this is the real essence of the mobile challenge from a technical perspecve. With Android,
ones has to deal with mulple screen resoluons, various CPU and GPU speed or capabilies,
memory limitaons, and so on, which are not topics specic to this Linux-based system,
(that is, Android) but can parcularly be incommoding.
To ease portability, Google engineers packaged a virtual machine with a complete framework
(the Android SDK) to run programs wrien in one of the most spread programming language
nowadays: Java. Java, augmented with the Android framework, is really powerful. But rst,
Java is specic to Android. Apple's products are wrien for example in Objecve C and can be
combined with C and C++. And second, a Java virtual machine does not always give you enough
capability to exploit the full power of mobile devices, even with just-in-me compilaon
enabled. Resources are limited on these devices and have to be carefully exploited to oer
the best experience. This is where the Android Nave Development Kit comes into place.
What this book covers
Chapter 1, Seng Up your Environment, covers the tools required to develop an applicaon
with the Android NDK. This chapter also covers how to set up a development environment,
connect your Android device, and congure the Android emulator.
Chapter 2, Creang, Compiling, and Deploying Nave Projects, we will compile, package, and
deploy NDK samples and create our rst Android Java/C hybrid project with NDK and Eclipse.
Chapter 3, Interfacing Java and C/C++ with JNI, presents how Java integrates and
communicates with C/C++ through Java Nave Interface.
Chapter 4, Calling Java Back from Nave Code, we will call Java from C to achieve
bidireconal communicaon and process graphic bitmaps navely.
Chapter 5, Wring a Fully-nave Applicaon, looks into the Android NDK applicaon life-cycle.
We will also write a fully nave applicaon to get rid of Java.
Chapter 6, Rendering Graphics with OpenGL ES, teaches how to display advanced 2D and 3D
graphics at full speed with OpenGL ES. We will inialize display, load textures, draw sprites
and allocate vertex and index buers to display meshes.
Chapter 7, Playing Sound with OpenSL ES, adds a musical dimension to nave applicaons
with OpenSL ES, a unique feature provided only by the Android NDK. We will also record
sounds and reproduce them on the speakers.
Preface
[ 3 ]
Chapter 8, Handling Input Devices and Sensors, covers how to interact with an Android
device through its mul-touch screen. We will also see how to handle keyboard events
navely and apprehend the world through sensors and turn a device into a game controller.
Chapter 9, Porng Exisng Libraries to Android, we will compile the indispensable C/C++
frameworks, STL and Boost. We will also see how to enable excepons and RunTime Type
Informaon. And also port our own or third-party libraries to Android, such as, Irrlicht 3D
engine and Box2D physics engine.
Chapter 10, Towards Professional Gaming, creates a running 3D game controlled with
touches and sensors using Irrlicht and Box2D.
Chapter 11, Debugging and Troubleshoong, provides an in-depth analysis of the running
applicaon with NDK debug ulity. We will also analyze crash dumps and prole the
performance of our applicaon.
What you need for this book
A PC with either Windows or Linux or an Intel-based Mac. As a test machine, an Android device
is highly advisable, although the Android NDK provides an emulator which can sasfy most of
the needs of a hungry developer. But for 2D and 3D graphics, it is sll too limited and slow.
I assume you already understand C and C++ languages, pointers, object-oriented features,
and other modern language concepts. I also assume you have some knowledge about
the Android plaorm and how to create Android Java applicaons. This is not a strong
prerequisite, but preferable. I also guess you are not frighten by command-line terminals.
The version of Eclipse used throughout this book is Helios (3.6).
Finally, bring all your enthusiasm because these lile beasts can become really amazing
when they demonstrate all their potenal and sense of contact.
Who this book is for
Are you an Android Java programmer who needs more performance? Are you a C/C++
developer who doesn't want to bother with Java stu and its out-of-control garbage
collector? Do you want to create fast intensive mulmedia applicaons or games? Answer
yes to any of the above quesons and this book is for you. With some general knowledge
of C/C++ development, you will be able to dive head rst into nave Android development.
Preface
[ 4 ]
Conventions
In this book, you will nd several headings appearing frequently.
To give clear instrucons of how to complete a procedure or task, we use:
Time for action – heading
1. Acon 1
2. Acon 2
3. Acon 3
Instrucons oen need some extra explanaon so that they make sense, so they are
followed with:
What just happened?
This heading explains the working of tasks or instrucons that you have just completed.
You will also nd some other learning aids in the book, including:
Pop quiz – heading
These are short mulple choice quesons intended to help you test your own understanding.
Have a go hero – heading
These set praccal challenges and give you ideas for experimenng with what you
have learned.
You will also nd a number of styles of text that disnguish between dierent kinds of
informaon. Here are some examples of these styles, and an explanaon of their meaning.
Code words in text are shown as follows: "Open a command line window and key in
java –version to check the installaon."
A block of code is set as follows:
export ANT_HOME=`cygpath –u "$ANT_HOME"`
export JAVA_HOME=`cygpath –u "$JAVA_HOME"`
export ANDROID_SDK=`cygpath –u "$ANDROID_SDK"`
export ANDROID_NDK=`cygpath –u "$ANDROID_NDK"`
Preface
[ 5 ]
When we wish to draw your aenon to a parcular part of a code block, the relevant lines
or items are set in bold:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=" /> package="com.example.hellojni"
android:versionCode="1"
android:versionName="1.0">
Any command-line input or output is wrien as follows:
$ make –version
New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "When proposed, include
Devel/make and Shells/bash packages".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
tles that you really get the most out of.
To send us general feedback, simply send an e-mail to
, and
menon the book tle through the subject of your message.
If there is a topic that you have experse in and you are interested in either wring or
contribung to a book, see our author guide on
www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help
you to get the most from your purchase.
Preface
[
6
]
Downloading the example code
You can download the example code les for all Packt books you have purchased from your
account at
. If you purchased this book elsewhere, you can
visit
/> and register to have the les e-mailed directly
to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you nd a mistake in one of our books—maybe a mistake in the text or the
code—we would be grateful if you would report this to us. By doing so, you can save other
readers from frustraon and help us improve subsequent versions of this book. If you
nd any errata, please report them by vising
selecng your book, clicking on the errata submission form link, and entering the details
of your errata. Once your errata are veried, your submission will be accepted and the
errata will be uploaded to our website, or added to any list of exisng errata, under the
Errata secon of that tle.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At
Packt, we take the protecon of our copyright and licenses very seriously. If you come
across any illegal copies of our works, in any form, on the Internet, please provide us with
the locaon address or website name immediately so that we can pursue a remedy.
Please contact us at
with a link to the suspected pirated material.
We appreciate your help in protecng our authors, and our ability to bring you
valuable content.
Questions
You can contact us at
if you are having a problem with any
aspect of the book, and we will do our best to address it.
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 illuminang your desk? Then let’s
not wait a minute more!
In this rst chapter, we are going to do the following:
Download and install the necessary tools to develop applicaons using Android
Set up a development environment
Connect and prepare an Android device for development
Getting started with Android development
What dierenates mankind from animals is the use of tools. Android developers,
this authenc species you are about to belong to, are no dierent!
To develop applicaons on Android, we can use any of the following three plaorms:
Microso Windows PC
Apple Mac OS X
Linux PC
Windows 7, Vista, Mac OS X, and Linux systems are supported in both 32 and 64-bit versions,
but Windows XP in 32-bit mode only. Only Mac OS X computers of version 10.5.8 or later and
based on Intel architectures are supported (not PowerPC processors). Ubuntu is supported
only from version 8.04 (Hardy Heron).
Seng Up your Environment
[ 8 ]
Right, this is a good start but unless you are able to read and write binary language like English,
having an OS is not enough. We also need soware dedicated to Android development:
The JDK (Java Development Kit)
The Android SDK (Soware Development Kit)
The Android NDK (Nave Development Kit)
An IDE (Integrated Development Environment): Eclipse
Android, and more specically Android NDK compilaon system is heavily based on Linux.
So we also need to set up some ulies by default, and we need to install one environment
that supports them: Cygwin (unl NDK R7). This topic is covered in detail later in the chapter.
Finally, a good old command-line Shell to manipulate all these ulies is essenal: we will
use Bash (the default on Cygwin, Ubuntu, and Mac OS X).
Now that we know what tools are necessary to work with Android, let’s start with the
installaon and setup process.
The following secon is dedicated to Windows. If you are a Mac or Linux
user, you can immediately jump to the
Seng up Mac OS X or the
Seng up Linux secon.
Setting up Windows
Before installing the necessary tools, we need to set up Windows to host our Android
development tools properly.
Time for action – preparing Windows for Android development
To work with the Android NDK, we need to set up a Cygwin Linux-like environment
for Windows:
Since NDK R7, Cygwin installaon is not required anymore
(steps 1 to 9). The Android NDK provides addional nave Windows
binaries (for example, ndk-build.cmd).
1. Go to />2. Download setup.exe and execute it.
3. Select Install from Internet.
Chapter 1
[ 9 ]
4. Follow the wizard screens.
5. Select a download site from where Cygwin packages are going to be downloaded.
Consider using a server in your country:
6. When proposed, include Devel/make and Shells/bash packages:
Seng Up your Environment
[ 10 ]
7. Follow the installaon wizard unl the end. This may take some me depending
on your Internet connecon.
8. Aer installaon, launch Cygwin. Your prole les get created on rst launch.
9. Enter the following command to check if Cygwin works:
$ make –version
To run Eclipse and allow compilaon of Android Java code to bytecode, a Java Development
Kit is required. On Windows, the obvious choice is the Oracle Sun JDK:
1. Go to the Oracle website and download the latest Java Development Kit: http://
www.oracle.com/technetwork/java/javase/downloads/index.html
.
2. Launch the downloaded program and follow the installaon wizard. At the end
of the installaon, a browser is opened asking for JDK registraon. This step is
absolutely not compulsory and can be ignored.
3. To make sure the newly installed JDK is used, let’s dene its locaon in environment
variables. Open the Windows Control panel and go to the System panel (or right-
click on Computer item in the Windows Start menu and select Properes). Then go
to Advanced system sengs. The System Properes window appears. Finally, select
Advanced tab and click on the Environment Variables buon.
4. In the Environment Variables window, inside the System variables list, insert the
JAVA_HOME variable with JDK installaon directory as value and validate. Then
edit PATH (or Path) and insert the %JAVA_HOME%\bin directory before any other
directory and separate it with a semicolon. Validate and close the window.
5. Open a command-line window and key in java –version to check the installaon.
The result should be similar to the following screenshot. Check carefully to make
sure that the version number corresponds to the version of the newly installed JDK:
$ java –version
Chapter 1
[ 11 ]
To compile projects from the command line, the Android SDK supports Ant—a Java-based
build automaon ulity. Let’s install it:
1. Go to and download Ant binaries,
packed within a ZIP archive.
2. Unzip Ant in the directory of your choice (for example, C:\Ant).
3. Go back to the Environment Variables window, as in step 12, and create the
ANT_HOME variable with the Ant directory as the value. Append the %ANT_HOME%\
bin
directory to PATH:
4. From a classic Windows terminal, check the Ant version to make sure it is
properly working:
Seng Up your Environment
[ 12 ]
What just happened?
We have prepared Windows with the necessary underlying ulies to host Android
development tools: Cygwin and Java Development Kit.
Cygwin is an open source soware collecon that allows the Windows plaorm to emulate
a Unix-like environment. It aims at navely integrang soware based on POSIX standard
(such as Unix, Linux, and so on) into Windows. It can be considered as an intermediate layer
between applicaons originated from Unix/Linux (but navely recompiled on Windows) and
the Windows OS itself.
We have also deployed a Java Development Kit in version 1.6 and checked if it is properly
working from the command line. Because Android SDK uses generics, the JDK in version 1.5
is the least required when developing with Android. JDK is simple to install on Windows but
it is important to make sure a previous installaon, such as JRE (Java Runme Environment,
which aims at execung applicaons but not developing them) is not interfering. This is why
we have dened
JAVA_HOME and PATH environment variables to ensure proper JDK is used.
Finally, we have installed Ant ulity that we are going to use in the next chapter to build
projects manually. Ant is not required for Android development but is a very good soluon
to set up a connuous integraon chain.
Where is Java’s home?
Dening the JAVA_HOME environment variable is not required. However,
JAVA_HOME is a popular convenon among Java applicaons, Ant being one
of them. It rst looks for the java command in JAVA_HOME (if dened)
before looking in PATH. If you install an up-to-date JDK in another locaon
later on, do not forget to update JAVA_HOME.
Installing Android development kits on Windows
Once JDK is installed on our system, we can start installing Android SDK and NDK to create,
compile, and debug Android programs.
Chapter 1
[ 13 ]
Time for action – installing Android SDK and NDK on Windows
1. Open your Web browser and go to
This web page lists all available SDKs, one for each plaorm.
2. Download Android SDK for Windows, packaged as an Exe installer.
3. Then, go to and download the
Android NDK (not SDK!) for Windows, packaged as a ZIP archive this me.
4. Execute Android SDK installer. Select an appropriate installaon locaon (for example,
C:\Android\android-sdk), knowing that Android SDK and NDK together can take
more than 3 GB of disk space (currently!) with all ocial API versions installed. As a
precauon, avoid leaving any space in the target installaon path.
5. Follow the installaon wizard unl the end. Check the Start SDK Manager:
6. The Android SDK and AVD Manager is launched. The Package installaon window
appears automacally.
Seng Up your Environment
[ 14 ]
7. Check the Accept All opon and click on Install to start the installaon of
Android components:
8. Aer a few minutes, all packages get downloaded and a message asking to restart
ADB service (the Android Debug Bridge) appears. Validate by clicking on Yes.
9. Close the applicaon.
10. Now, unzip Android NDK archive into its nal locaon (for example, C:\Android\
android-ndk
). Again, avoid leaving any space in the installaon path (or some
problems could be encountered with Make).
To easily access Android ulies from the command line, let’s dene the
environment variables:
11. Open the Environment Variables system window, as we did in the previous part.
Inside the System variables list, insert the ANDROID_SDK and ANDROID_NDK
variables with the corresponding directories as values.
12. Append %ANDROID_SDK%\tools, %ANDROID_SDK%\platform-tools and
%ANDROID_NDK%, all separated by a semicolon, to your PATH.