Friday, July 22, 2011

Android SDK, Fastboot, ADB with Ubuntu 10.04 and HTC Desire

NOTE: In all cases, USERNAME should be replaced with your own username.


These instructions were written using a 10.04.2 build of Ubuntu and it should be fine for both 32 and 64 bit versions of the operating system. We'll walk through how to prepare your PC from start to finish, so this should be the only instruction you need.

Remove Java alternatives
In terminal:
sudo apt-get remove -y --purge openjdk-6-jre openjdk-6-jre-lib openjdk-6-jdk gcj
Install Sun Java
See the full Ubuntu Release Notes for more detail... the important part is a follows:

'For Ubuntu 10.04 LTS, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive.'

So we need to add the Repo prior to installation. 

In terminal: 
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-fonts sun-java6-plugin
sudo update-alternatives --config java
Should return:
There is only one alternative in link group java: /usr/lib/jvm/java-6-sun/jre/bin/java
Nothing to configure.
Get the android SDK, choose one of the following three ways:
1. Google search
2. Android Developer Page
3. SDK direct link
Installation is as simple as extracting the SDK to your /home directory using File Roller (just execute the downloaded archive)...
/home/USERNAME/android-sdk-linux_x86
You'll need to update the SDK.
In terminal:
android-sdk-linux_x86/tools/android update sdk
Allow it to refresh sources, select 'Accept All' and 'Install'. It will take a while.

Get FASTBOOT, choose one of the following two ways:
1. Google search
2. HTC Developer page

Installation is as simple as extracting FASTBOOT into the platform-tools directory using File Roller... but the platform-tools directory won't exist until the SDK and AVD Manager has finished updating. Once it has, extract FASTBOOT to the platform-tools directory...
/home/USERNAME/android-sdk-linux_x86/platform-tools/fastboot
Using Nautilus (your file browser), navigate to the platform-tools directory, right click on adb and fastboot in turn, and confirm on the permissions tab you have 'Allow executing file as program' selected.

Add the platform-tools directory to your $PATH
From here, you could use ADB shell and FASTBOOT from within the SDK's platform-tools directory, but to make life easier and save keystrokes, we'll edit your .profile $PATH to allow execution of the commands from outside the platform-tools directory.
In terminal:
gedit .profile

We're looking for the following text:
PATH="$HOME/bin:$PATH"
Which we're going to replace with the following:
PATH="$HOME/bin:$PATH:/home/'USERNAME'/android-sdk-linux_x86/platform-tools"
Save and close gedit.

Add a BIN directory.
In terminal:
mkdir bin
Create a udev rule to allow access to the Android device
Confirm your vendor ID, without the Android device plugged in...
In terminal:
lsusb
With it plugged in...
In terminal:
lsusb
Should result in an extra entry, something like this:
Bus 002 Device 002: ID 0bb4:0c87 High Tech Computer Corp. 
In this case, the vendor ID is 0bb4.
Create a fresh udev rule.
In terminal:
sudo gedit /etc/udev/rules.d/51-android.rules 
Add the following lines (for the HTC Desire):
SUSBYSTEMS=="usb", ATTRS{idVendor}=="18d1", MODE="0666" 
SUSBYSTEMS=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
NOTE: Other devices will need different vendor IDs. You can find your vendor ID using google.
Save and close gedit.
Give the new rule file some permissions.
In terminal:
sudo chmod a+rx /etc/udev/rules.d/51-android.rules
Now restart the PC. After your reboot, confirm everything worked as follows:

Time for testing
With the Android device running normally, plugged in and debugging turned on.
In terminal:
adb devices
Shoud return something like this:
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached HT08ZRx0x6xx device
Reboot the Android device into the bootloader (fastboot). Confirm 'fastboot USB' appears on the Android device.
In terminal:
fastboot devices
Should return something like this:
HT08ZRx0x6xx fastboot
Troubleshooting:
If you get errors relating to no such command, try the same commands manually using the path. 
In terminal:
./android-sdk-linux_x86/platform-tools/adb devices
and
./android-sdk-linux_x86/platform-tools/fastboot devices
If these don't work, or one works and the other doesn't, you probably have a problem with your udev rules, the install, or permissions.
If these work, your .profile $PATH needs work. Checking your $PATH is easy.
In terminal:
echo $PATH
Should return something like:
/home/USERNAME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/'USERNAME'/android-sdk-linux_x86/platform-tools

1 comment:

Use information found here at your own risk!!

Hopefully you'll be more interested in my other blog... motorbikes, beer and stuff...