This chapter shows you how to install the Android software development kit (SDK) and all the related software you’re likely to need. By the end, you’ll be able to run a simple “Hello World” program on an emulator. Windows, Mac OS X, and Linux systems can all be used for Android application development. We will load the software, introduce you to the tools in the SDK, and point you to sources of example code.
Throughout this book, and especially in this chapter, we refer to instructions available on various websites for installing and updating the tools you will use for creating Android programs. The most important place to find information and links to tools is the Android Developers site:
Our focus is on guiding you through installation, with explanations that will help you understand how the parts of Android and its developer tools fit together, even as the details of each part change.
The links cited in this book may change over time. Descriptions and updated links are posted on this book’s website. You can find a link to the website on this book’s catalog page. You may find it convenient to have the book’s website open as you read so that you can click through links on the site rather than entering the URLs printed in this book.
Successfully installing the Android SDK requires two other software systems that are not part of the Android SDK: the Java Development Kit (JDK) and the Eclipse integrated development environment (IDE). These two systems are not delivered as part of the Android SDK because you may be using them for purposes outside of Android software development, or because they may already be installed on your system, and redundant installations of these systems can cause version clashes.
The Android SDK is compatible with a range of recent releases of the JDK and the Eclipse IDE. Installing the current release of each of these tools will usually be the right choice. The exact requirements are specified on the System Requirements page of the Android Developers site: http://developer.android.com/sdk/requirements.html.
One can use IDEs other than Eclipse in Android software development, and information on using other IDEs is provided in the Android documentation at http://developer.android.com/guide/developing/other-ide.html. We chose Eclipse as the IDE covered in this book because Eclipse supports the greatest number of Android SDK tools and other plug-ins, and Eclipse is the most widely used Java IDE, but IntelliJ IDEA is an alternative many Java coders prefer.
If your system has an up-to-date JDK installed, you won’t need to install it again. The JDK provides tools, such as the Java compiler, used by IDEs and SDKs for developing Java programs. The JDK also contains a Java Runtime Environment (JRE), which enables Java programs, such as Eclipse, to run on your system.
sudo apt-get install sun-java6-jdk
If this command reports that the JDK package is not available, you may need to enable the “partner” repositories using the Synaptic Package Manager utility in the System→Administration menu. The “partner” repositories are listed on the Other Software tab after you choose Settings→Repositories.
This is one of the very few places in this chapter where you will see a version number, and it appears here only because it can’t be avoided. The version number of the JDK is in the package name. But, as with all other software mentioned in this chapter, you should refer to up-to-date online documentation to determine the version you will need.
If you are a Windows user, or you need to install the JDK from Oracle’s site for some other reason, you can find the JDK at http://www.oracle.com/technetwork/java/javase/downloads/index.html.
The Downloads page will automatically detect your system and offer to download the correct version. The installer you download is an executable file. Run the executable installer file to install the JDK.
Eclipse is a general-purpose technology platform. It has been applied to a variety of uses in creating IDEs for multiple languages and in creating customized IDEs for many specialized SDKs, as well as to uses outside of software development tools, such as providing a Rich Client Platform (RCP) for Lotus Notes and a few other applications.
Eclipse is usually used as an IDE for writing, testing, and debugging software, especially Java software. There are also several derivative IDEs and SDKs for various kinds of Java software development based on Eclipse. In this case, you will take a widely used Eclipse package and add a plug-in to it to make it usable for Android software development. Let’s get that Eclipse package and install it.
Eclipse can be downloaded from http://www.eclipse.org/downloads.
You will see a selection of the most commonly used Eclipse packages on this page. An Eclipse “package” is a ready-made collection of Eclipse modules that make Eclipse better suited for certain kinds of software development. Usually, Eclipse users start with one of the Eclipse packages available for download on this page and customize it with plug-ins, which is what you will do when you add the Android Development Tools (ADT) plug-in to your Eclipse installation. The System Requirements article on the Android Developers site lists three choices of Eclipse packages as a basis for an Eclipse installation for Android software development:
Any of these will work, though unless you are also developing Eclipse plug-ins, choosing either Classic or the Java Developers package (EE or Standard) makes the most sense. The authors of this book started with the Java EE Developers package (“EE” stands for Enterprise Edition), and screenshots of Eclipse used in this book reflect that choice.
The Eclipse download site will automatically determine the available system-specific downloads for your system, though you may have to choose between 32 and 64 bits to match your operating system. The file you download is an archive. To install Eclipse, open the archive and copy the eclipse folder to your home folder. The executable file for launching Eclipse on your system will be found in the folder you just extracted from the archive.
We really mean it about installing Eclipse in your home folder (or another folder you own), especially if you have multiple user accounts on your system. Do not use your system’s package manager. Your Eclipse installation is one of a wide range of possible groupings of Eclipse plug-ins. In addition, you will probably further customize your installation of Eclipse. And Eclipse plug-ins and updates are managed separately from other software in your system.
For these reasons, it is very difficult to successfully install and use Eclipse as a command available to all users on your system, even if your system can do this from its package manager. To successfully complete an installation as it is described here, you must install Eclipse in a folder managed by one user, and launch it from this location.
If you are using Ubuntu or another Linux distribution, you should not install Eclipse from your distribution’s repositories, and if it is currently installed this way, you must remove it and install Eclipse as described here. The presence of an “eclipse” package in the Ubuntu repositories is an inheritance from the Debian repositories on which Ubuntu is based. It is not a widely used approach to installing and using Eclipse, because most of the time, your distribution’s repositories will have older versions of Eclipse.
To confirm that Eclipse is correctly installed and that you have a JRE that supports Eclipse, launch the executable file in the Eclipse folder. You may want to make a shortcut to this executable file to launch Eclipse more conveniently. You should see the Welcome screen shown in Figure 1-1.
With the JDK and Eclipse installed, you have the prerequisites for the Android SDK, and are ready to install the SDK. The Android SDK is a collection of files: libraries, executables, scripts, documentation, and so forth. Installing the SDK means downloading the version of the SDK for your platform and putting the SDK files into a folder in your home directory.
To install the SDK, download the SDK package that corresponds to your system from http://developer.android.com/sdk/index.html.
To check whether you need this package,
try running the
If your system reports that adb cannot be found (despite being
right there in the platform-tools directory) it likely
means that the current version of adb, and possibly other tools,
will not run without the
ia32-libs package installed. The command
to install the
sudo apt-get install ia32-libs
The SDK contains one or two folders for tools: one named
tools and, starting in version
8 of the SDK, another called platform-tools. These folders need to be
on your path, which is a list of folders your system searches for
executable files when you invoke an executable from the command
line. On Macintosh and Linux systems, setting the
PATH environment variable is done in the
.profile (Ubuntu) or .bash_profile (Mac OS X) file in your
home directory. Add a line to that file that sets the
variable to include the tools
directory in the SDK (individual entries in the list are separated
by colons). For example, you could use the following line (but
replace both instances of
with the full path to your Android SDK install):
On Windows systems, click Start→right-click Computer, and choose Properties. Then click Advanced System Settings, and click the Environment Variables button. Double-click the path system variable, and add the path to the folders by going to the end of this variable’s value (do not change anything that’s already there!) and adding the two paths to the end, separated by semicolons with no space before them. For example:
After you’ve edited your path on
Windows, Mac, or Linux, close and reopen any Command Prompts or
Terminals to pick up the new
setting (on Ubuntu, you may need to log out and log in unless your
Terminal program is configured as a login shell).
Before you can build an Android application, or even create a project that would try to build an Android application, you must install one or more build targets. To do this, you will use the SDK and AVD Manager. This tool enables you to install packages in the SDK that will support multiple versions of the Android OS and multiple API levels.
Once the ADT plug-in is installed in Eclipse, which we describe in the next section, the SDK and AVD Manager can be invoked from within Eclipse. It can also be invoked from the command line, which is how we will do it here. To invoke the SDK and AVD Manager from the command line, issue this command:
The screenshot in Figure 1-2 shows the SDK and AVD Manager, with all the available SDK versions selected for installation.
The packages labeled “SDK platform” support building applications compatible with different Android API levels. You should install, at a minimum, the most recent (highest numbered) version, but installing all the available API levels, and all the Google API add-on packages, is a good choice if you might someday want to build applications that run on older Android versions. You should also install, at a minimum, the most recent versions of the example applications package. You must also install the Android SDK Platform-Tools package.
Now that you have the SDK files installed, along with Eclipse and the JDK, there is one more critical part to install: the Android Developer Toolkit (ADT) plug-in. The ADT plug-in adds Android-specific functionality to Eclipse.
Software in the plug-in enables Eclipse to build Android applications, launch the Android emulator, connect to debugging services on the emulator, edit Android XML files, edit and compile Android Interface Definition Language (AIDL) files, create Android application packages (.apk files), and perform other Android-specific tasks.
You start the Install New Software
Wizard by selecting Help→Install New Software (Figure 1-3). To install
the ADT plug-in, type this URL into the Work With field and press
Return or Enter:
(see Figure 1-4).
More information on installing the ADT plug-in using the Install New Software Wizard can be found on the Android Developers site, at http://developer.android.com/sdk/eclipse-adt.html#downloading.
Eclipse documentation on this wizard can be found on the Eclipse documentation site, at http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.user/tasks/tasks-124.htm.
Figure 1-4. The Eclipse Install New Software dialog with the Android Hierarch Viewer plug-in shown as available
Select the Developer Tools item by clicking on the checkbox next to it, and click on the Next button. The next screen will ask you to accept the license for this software. After you accept and click Finish, the ADT will be installed. You will have to restart Eclipse to complete the installation.
One more step, and you are done installing. Once you have installed the ADT plug-in, you will need to configure it. Installing the plug-in means that various parts of Eclipse now contain Android software development-specific dialogs, menu commands, and other tools, including the dialog you will now use to configure the ADT plug-in. Start the Preferences dialog using the Window→Preferences (Linux and Windows) or Eclipse→Preferences (Mac) menu option. Click the item labeled Android in the left pane of the Preferences dialog.
A dialog with the Android settings is displayed next. In this dialog, a text entry field labeled “SDK location” appears near the top. You must enter the path to where you put the SDK, or you can use the file browser to select the directory, as shown in Figure 1-5. Click Apply. Note that the build targets you installed, as described in Adding Build Targets to the SDK, are listed here as well.