Saturday, March 12, 2011

Installing Android SDK and Eclipse ADT Plug-In

Previous: Ripping CDs on Ubuntu 10.04

My interest in Android development was rekindled when I got a new Android phone last month. After upgrading to Ubuntu 10.04, I had not reinstalled the Android development tools, so I installed them fresh.

Prerequisites



sudo apt-get install ia32-libs
sudo apt-get install sun-java6-jdk

Get the Android development kit



The Android development kit contains tools for building and testing Android apps. There are some very good tutorials on developer.android.com/resources/ that will help you get started.

1. Create home directory for android development tools. I chose ~/.android.

2. Download sdk from developer.android.com/sdk. At the time I did this, it was release 10. Note that the file name contains the releacd tse number. Place the downloaded file in the android development home directory.

3. In a command line window, change to the android development home directory.

4. Unpack the distribution.
gunzip -c android-sdk_r10-linux_x86.tgz | tar xopf -
You will end up with ~/.android/android-sdk_r10-linux_x86/. (The directory name contains the release number.)

Get Android platform development tools



The basic Android SDK contains only the core development tools. From the readme:

"In order to start developing applications, you must install the Platform-tools
and at least one version of the Android platform, using the SDK Manager.

"Platform-tools contains build tools that are periodically updated to support new
features in the Android platform (which is why they are separate from basic
SDK tools), including adb, dexdump, and others."

1. Change to the Android development home directory and start the SDK Manager:
tools/android
From the selections on the left side of the window, choose Available packages, then expand Android Repository. Tick the checkboxes next to the items you want to install. I chose Android SDK Platform-tools, revision 3, Documentation for Android SDK, API 11, revision 1, SDK Platform Android 3.0, API 11, revision1, SDK Platform Android 2.3.3, API 10, revision 1, Samples for SDK API 10, revision 1, and Samples for SDK API 11, revision 1. I got 3.0 because it was the latest version at the time, and 2.3.3 because it was the version that came with my shiny new Android phone.

After making your selections, click the button labeled Install Selected, in the lower right-hand corner of the window. It will display a list of components and licenses. You must choose Accept for each component or Accept All before the download will proceed. After accepting the licenses you want, click the Install button. It will display download progress.

If you don't have ADB running (and you won't at this point, if this is a fresh install, because ADB is not part of the base distribution), you may see the message "'adb kill-server' failed -- run manually if necessary." The installer attempts to kill the server because the server must be down for the install. This does not stop the installer.

If you get the message, "A package that depends on ADB has been updated. Do you want to restart ADB now?" choose Yes.

When the installation is complete, click Close to close the progress dialog box. Now if you choose Installed packages from the left-hand menu, you will see a list of the components you just installed.

Get the Eclipse IDE


It is not necessary to use Eclipse for Android development. You can use any IDE or other development tools you prefer. The course of least resistance is to use Eclipse, since that is what the Android team uses and all the tutorials and documentation assume you are using it, too. You can do everthing from the command line; there are no hard dependencies on Eclipse.

1. Download the appropriate Eclipse distribution from www.eclipse.org.

Eclipse is available preconfigured to support several common types of development. For Android development, you need only the most basic packaging of Eclipse. At the time I did this, it was called "Eclipse IDE for Java Developers."

2. Create home directory for Android-specific instance of Eclipse

I prefer to have Eclipse configured separately for each project rather than to have a single instance loaded with every imaginable plug-in.g I created a directory named ~/.eclipse-android for this instance.

3. Unpack the Eclipse distribution in its home directory.
gunzip -c eclipse-java-helios-SR2-linux-gtk-x86_64.tar.gz | tar xopf -
This resulted in ~/.eclipse-android/eclipse/

Install the Eclipse ADT plug-in



The documentation at developer.android.com/sdk/eclipse-adt.html#installing is very clear and helpful.

I started the new instance of Eclipse and created a workspace called android-sandbox to play in. I installed the ADT following the instructions at developer.android.com. This is a conventional Eclipse plug-in install, so I am not going to repeat all the steps here. One thing to note is that some of the content is unsigned, and you may see a warning message about that.

Configure the Eclipse ADT plug-in



For convenience, I created a symlink for to the Android development home directory in .profile:
ln -s ~/.android/android-sdk-linux_x86 ~/.android-sdk
. This matches the default configuration of the ADT plug-in. To change it, in Eclipse go to Windows > Preferences, choose Android, and set the value of SDK Location.

Create an Android Virtual Device



After installing the Eclipse ADT plug-in, you can run the Android SDK and AVD Manager from inside Eclipse. The plug-in adds a menu item to Eclipse's Window menu titled Android SDK and AVD Manager.

Start the Manager. If this is a fresh installation, you will see the message "No AVD available." Click New to get the "Create New Android Virtual Device (AVD)" dialog. Enter anything you please as the Name (it doesn't like spaces in the name).

The Target drop-down will contain a list of the Android platforms you installed. Pick the one you want for the new AVD.

Click Create AVD.

Verify the installation



The simplest way to verify the installation is to create an Android project and see if you can build a simple app and run it on your AVD.

The first indication of success is that the ADT options appear in Eclipse menus. Try File > New > Project and see if the Android entry appears in the list of project types.

When you create an Android project in Eclipse, ADT gives you a skeletal Java file to start you off. This isn't runnable as is. I suggest following the "Hello World" tutorial at developer.android.com/resources/tutorials/hello-world.html.

Once you've got the Hello World code in place, you can run the app in the emulator from inside Eclipse by right-clicking the project entry in Package Explorer and choosing Run As > Android Application.

A word of warning. The first time I ran my Hello World app from inside Eclipse, the emulator seemed to hang at a point before it loaded the app. Eventually it timed out, and complained that it could not load the app. However, the emulator itself finally started up. I could then run the app with no problems. If you see this behavior, it doesn't mean your app is configured wrong. The emulator just takes a long time to initialize itself. A long time. Several minutes.

If you eventually see the words "o;Hello, Android" appear on the emulator screen, then your installation was successful. Good luck and have fun.

Next: Ubuntu 11.04 installation