Time for action – installing Android SDK and NDK on OS X
The Android Studio bundle already contains the Android SDK. Let's install it.
- Open your web browser and download the Android Studio bundle from http://developer.android.com/sdk/index.html.
- 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. - 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.
In the next Setup Wizard screen that appears, select the Standard installation type and continue the installation.
Complete the installation until the Android Studio welcome screen appears. Then, close Android Studio.
- 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
). - 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 defaultBash
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}"
- 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
- Check the
ndk-build
version to ensure that NDK is working. If everything works, theMake
version should appear:ndk-build -version
- 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 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.