5 May 2011

Setting Android SDK on Ubuntu 10.10

Setting up the SDK is easy on Linux. It's getting the supporting tools installed that is the PITA. Here's one way to get it done. This is geared to the Ubuntu user, but it's the same method for all distros.

Running as root -- yes, there is a portion of this guide that has you run commands as root. This is a bad practice, but to make the guide simpler and more universal, it's necessary in this case. Just remember, when you're running as root, you can really screw things up.

Step One -- 32-bit libraries and headers
If you're using a 32 bit version of Linux, be aware that building from the AOSP tree is no longer supported after version 2.2.2. Most modern processors will run (and benefit) from using a 64-bit version of Linux, so upgrading is something worth considering.
If you are using a 64-bit version of Linux, you'll need to install the 32-bit versions of some libraries, as they aren't installed by default. If you are using Ubuntu 10.10, open your terminal and install them like so:

sudo apt-get install ia32-libs


Step Two -- Java 6
The SDK almost works with open Java alternatives, but almost doesn't cut it. We need to install Oracle's closed source version of the Java Development Kit and Runtime Environment. Since it's closed source, it's not available by default in the Ubuntu package manager. These commands will add a repository to your apt source list that keeps the Linux version of Sun Java up to date and available, then install what's needed.

 sudo apt-get install openjdk-6-jre openjdk-6-jre-headless

Step Three -- download the SDK

Download the Android SDK for Linux (http://dl.google.com/android/android-sdk_r08-linux_86.tgz). Open the archive, and extract the entire android-sdk-linux_86 folder into your home folder.

Step Four -- Setup the path for SDK
Now that you have it installed, you need to tell your shell where it is. Open your ~/.bashrc file and add it to your PATH. Here's a copy/paste method using vim -

    vim ~/.bashrc
Paste code:
PATH=$PATH:/home/<user name>/android-sdk-linux_86/tools
export PATH
PATH=$PATH:/home/<user name>/android-sdk-linux_86/platform-tools
export PATH

press (Esc :wq) to save and exit

Now you need to refresh your shell. Enter this at the prompt:
Code:
cd ~/android-sdk-linux_86/tools/
./android

On the left, choose Available packages.
Check the box that says Android Repository, then choose to install selected.
Choose Accept all and Install.

This take a few minutes, as it downloads everything you will ever need. If you want, you can choose to only install the tools and platform tools in your choice above.


Step five -- testing
On Ubuntu systems, adb has to run as root, or your device needs permission to communicate declared in the udev rules. You really should set up the udev rule for your phone and not run as root. In the meantime, you will need to restart adb as root each time your reboot or stop adb. Do it like so:
Code:
sudo su
<password>
cd /home/<username>/android-sdk-linux_86/platform-tools
./adb kill-server
./adb start-server
exit

Next, make sure USB debugging is enabled on your phone, and connect it to a full speed USB port, one that's not on a hub. Sometimes hubs and front ports work fine. Sometimes they don't. Use the right ones to test, and try others later once you know it all works. After it's connected go back to the terminal:

cd ~/android-sdk-linux_86/platform-tools
./adb devices

You should see a serial number. That means it worked. Now try:
cd ~/
adb devices

You should see the same thing. This means your PATH was set-up right. And you're done. If you hit any snags, post away and we'll try to fix them.


No comments:

Post a Comment