Using Android Debug Bridge (ADB) in Linux

i have just done the necessary setup to do some Android development on my Fedora 12 machine using Eclipse (Galileo) and the Android SDK. As i have a HTC Dream (or G1) with me, i also wanted to deploy and test directly on the phone itself instead of using an emulator.

However, things didn't go very smoothly when trying to connect to the phone through ADB.

What i had done to that point was:

1. Created a simple Hello World Android application.

2. Turned on the USB Debugging option on the phone (Menu > Settings > Applications > Development > USB Debugging).

3. Connected the phone to the PC (there was an acknowledgement there on the phone in the form of a notification: USB debugging connected - A computer is connected to your phone).

However, when i tried to run the application, the Android Device Chooser (i had set the Deployment Target Selection Mode to Manual) showed this:

And of course, i couldn't run the application even after selecting the "unknown" target.

Doing a adb devices on the command line also showed a problem:

$ ./adb devices
List of devices attached
???????????? no permissions

It turned out that this was quite a common problem (at least for those developing in Linux), and quite a number of pages (references at the end of article) were devoted to solving (or actually, working around) it. Broadly, there were three different workarounds (or rather, attempts).

1. Ensure that the phone device was added with world writable and readable permissions.

Create the new file /etc/udev/rules.d/50-android.rules containing the line

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"

Reload the rules by doing

# udevadm control --reload-rules

Thereafter, when the phone is plugged in, the corresponding devices in /dev would have the rw-rw-rw- permission.

However, this did not work. i do not know why, but from some trial and error, it seemed like it was necessary for the ADB server process and the phone devices to be owned by the same user. This led to the other two workarounds.

2. Start the ADB server as root.

Simply, kill the existing ADB server process

# ./adb kill-server

and start it up as root

# ./adb start-server

i'm not too keen on this though, as i try and avoid starting any process as root.

3. Connect the phone device as the non-root user who starts the ADB server process.

The steps are similar to the first (unsuccessful) workaround, with the content of the /etc/udev/rules.d/50-android.rules file slightly different

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bb4", OWNER="user"

where user is the user who starts the ADB server process.

This is still not completely satisfactory though. If another user were to use the same machine, he/she would face the same issue. (At this point, you may be thinking about groups. i've tested it, and no, having the user who starts the ADB server process to be a member of the disk group (the group that owns the phone device) still is insufficient.) However, i'm running a single-user system, so this workaround was still acceptable.

The ATTRS{idVendor}=="0bb4" works for my HTC Dream. If you have a different Android device, you may need a different vendor ID. i'm not too sure about this.




Chris said...

Ahh yes, I remember this problem from about a year ago when I first installed ADT. I'm surprised this hasn't been addressed or at least called out by those in power...

Thanks for the help...

Jeffrey JCC said...

for opensuse try: http://my.opera.com/Dendiablo/blog/2010/05/04/opensuse-linux-usb-for-droid?cid=41389832#comment41389832

Anonymous said...

"The ATTRS{idVendor}=="0bb4" works for my HTC Dream. If you have a different Android device, you may need a different vendor ID. i'm not too sure about this."
Yes. You must know idVendor of your phone. Simply use: lsusb and fill only first part of ID replacing 0bb4

Unknown said...

Thanks, that's exactly what I needed!

Android app development said...

Android is a mobile operating system that has been highly successful because of its incredible features. Most of the smart phones in the market run on Android OS. Since the success of Android, lot of Android Development Companies has spurred up everywhere. We are also putting good logic to develop more in this field.Android app developers

aman said...

point number 2 did it for me.

Android developer said...

I am afflicted to apprehend such a able annual about The Nifty Files. I will cavalcade a delivery on my advertisement armpit to this blog post. I will be ashamed to apprehend more.

Romona Vimazel said...

Congratulation for the great post. I ended up on your site looking for article on. I noticed that you certainly do have excellent and creative ideas on the topic of Horse Breeds. Great read.