Bit of a long winded title. I recently made the switch from the iPhone to an Android device. I’ve done a little bit of iPhone programming and found the whole process of hooking my iPhone up to my Mac quite easy. Unfortunately my Mac’s hard drive decided to kick the bucket so I installed Ubuntu Natty Narwhal instead and decided my next mobile would be a HTC of some sort (a few friends had them and I loved how open they were compared to my iPhone, the widgets for instance where a major selling point). After seeing the HTC Evo 3D and having a major nerdgasm over it I had my mind set but unfortunately no UK carrier would take on the device so I settled for the HTC Sensation (which is pretty damn awesome).

I’m currently in the process of making a mobile app for work, the hope is that I can use my new phone to create an Android version of the app side by side with the one we’ll be releasing for the iPhone. Yesterday I set about trying to get my HTC Sensation working with the Android Debug Bridge (adb), after reading a few tutorials on the web (listed at the end of this post) I was quite stumped. I eventually mixed and matched a few and managed to get all working. My face lit up when ?????????? No Permissions turned into HT17******* device.

First step – Make sure your computer can see the phone

This tutorial will assume that you are running Ubuntu Natty Narwhal, you have the Android SDK running already, you know the directory it’s in and you know a little about using the terminal, I’ll try and keep it as un-technical as I can.

First things first plug your HTC Sensation into your computer using it’s USB lead. Go to settings > Applications > Debugging and tick the top two boxes. Now press the home button and make sure you don’t look your phone. We’ll start off running adb to see if it finds the device. Open up the terminal and type ‘~/android-sdk-linux_x86/platform-tools/adb devices‘, I’ve set my Android SDK in my home folder, if you’ve placed yours else where replaces the ~ with that directory. Running this command should show all the connnected Android devices, if you see a bunch of question marks it means that it’s not recognising the device. If you see a serial number then you don’t need to do anything as it recognises it. If for some reason it doesn’t say anything type ‘lsusb‘ into the terminal and look for ‘Bus 001 Device 008: ID 0bb4:0c86 High Tech Computer Corp.‘ The bus and Device aren’t important but the other bits are. If you don’t see this then your USB lead may not be working.

Second step – setting up the udev files

Linux uses a thing called udev to define what devices plugged into the system do and can be used for. To get adb to use the HTC Sensation for debugging we need to create some rules for it. First let’s see if there’s any Android rules already set up. Type ‘ls /etc/udev/rules.d/‘ into the terminal this will list the contents of the folder where the Android udev rules would sit. If it prints out the following ‘51-android.rules‘ or ‘99-android.rules‘ then skip the next paragraph.

If there wasn’t either of those files then we need to create the rules for the android devices. I’m not entirely sure if 99 or 51 is the correct name for the file (the Android Dev documents says 51, this tutorial says 99) so to ensure that it works I’m going to create both. Type ‘ sudo touch /etc/udev/rules.d/51-android.rules‘ and ‘ sudo touch /etc/udev/rules.d/99-android.rules‘ into the terminal, this creates both files (touch creates files).

Now we need to add rules for the device into these files. Smakked on the XDA-developer’s forum put up this awesome little snippet which I’ve been using.

#HTC Sensation
SUBSYSTEM=="usb", SYSFS{idVendor}=="[0bb4]", MODE="0666"

Copy this code and then type ‘ sudo gedit /etc/udev/rules.d/51-android.rules‘ into the terminal, this will open the 51-android file. Paste the code at the end of the document and save it. Now type ‘ sudo gedit /etc/udev/rules.d/99-android.rules‘ into the terminal, this opens the 99-android file, again paste the code and save the file.

Finally we need to set the permissions for the files. Type ‘sudo chmod a+r /etc/udev/rules.d/51-android.rules‘ and ‘sudo chmod a+r /etc/udev/rules.d/99-android.rules‘ into the terminal. This will allow the system to use the files properly.

Third step – Restart adb and check the device settings again

So now the udev files are in place we now need to reset adb so we can use them. Type ‘~/android-sdk-linux_x86/platform-tools/adb kill-server‘ into the terminal. This will stop the adb daemon from running. Now unplug your HTC Sensation, I found that it didn’t find my phone until I plugged it in again. After unplugging you phone type ‘~/android-sdk-linux_x86/platform-tools/adb start-server‘ into the terminal, this will start the adb daemon again. Plug your phone in again, make sure it’s not locked and then type ‘~/android-sdk-linux_x86/platform-tools/adb devices‘ into the terminal. Hopefully you’ll see a list of numbers instead of a lot of question marks. If not maybe try restarting the computer and once it’s restarted type ‘~/android-sdk-linux_x86/platform-tools/adb devices‘ into the terminal again.

Below are a list of tutorials that helped me work this out:

If this didn’t work and you found a solution please put it in the comments.

Update – 26/08/2011

So since writing this tutorial I’ve found that the rules weren’t as permanent as I’d hoped. If you’re having issues with ADB after rebooting or generally go to the Terminal and type in “~/android-sdk-linux_x86/platform-tools/adb kill-server” and then use sudo to restart the server by typing “sudo ~/android-sdk-linux_x86/platform-tools/adb start-server“. This should hopefully make it work again as it had before.