If you do any Android development in Ubuntu it is much better to test your applications on a real device rather than just relying on the emulator.
If you just connect the phone to the computer through USB and run adb devices you will find out that your phone is not recognized:
$ adb devices
List of devices attached
???????????? no permissions
This is easily fixable in Ubuntu. You have to add a line to a file in the /etc/udev/rules.d directory.
What line in which file depends on the manufacturer and model of the device. You can find out the Vendor ID number and Product ID number of the device by running (after you connected it via USB of course):
$ lsusb
For example, if you had a Nexus One connected you would get:
Bus 002 Device 004: ID 18d1:4e12
In this case the Vendor Id is “18d1” and the Product ID is “4e12”. Please keep in mind that the Vendor ID for HTC changed from “0bb4” to “18d1”. The older HTC phones like the G1 have a Vendor ID of “0bb4”.
Here is how to set up some of the major Android phones:
Step 1. Enable Unknown sources and USB debugging:
Go to Settings -> Applications and check the Unknown sources check-box, then go to Development and enable the USB debugging.
Step 2. Depending on your phone follow these instructions:
- G1
Create/edit a file in /etc/udev/rules.d called 51-android.rules:$ sudo gedit /etc/udev/rules.d/51-android.rules
Add the following line to it and save it:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c01″, MODE=”0666″
- HTC Hero
Add to the file (or create it if it does not exist- see above) /etc/udev/rules.d/51-android.rules the following line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c02″, MODE=”0666″
- HTC EVO
Add to the file (or create it if it does not exist- see above) /etc/udev/rules.d/51-android.rules the following line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0c8d”, MODE=”0666″
- HTC EVO Shift
Add to the file (or create it if it does not exist- see above) /etc/udev/rules.d/51-android.rules the following line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0ca5″, MODE=”0666″
- HTC ThunderBolt
Add to the file (or create it if it does not exist- see above) /etc/udev/rules.d/51-android.rules the following line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”0bb4″, ATTRS{idProduct}==”0ca4″, MODE=”0666″
- LG OPTIMUS LG-P506
Add to the file (or create it if it does not exist- see above) /etc/udev/rules.d/51-android.rules the following line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”1004″, ATTRS{idProduct}==”618e”, MODE=”0666″
- Motorola Xoom
Add to the file (or create it if it does not exist- see above) /etc/udev/rules.d/51-android.rules the following line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8″, ATTRS{idProduct}==”70a9″, MODE=”0666″
- Motorola Droid
Create/edit a file in /etc/udev/rules.d called 10-motorola-droid.rules:$ sudo gedit /etc/udev/rules.d/10-motorola-droid.rules
Add the following line to it and save it:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8″, ATTRS{idProduct} ==”41db”, MODE=”0600″
- Nexus One
Create/edit a file in /etc/udev/rules.d called 99-android.rules:$ sudo gedit /etc/udev/rules.d/99-android.rules
Add the following line to it and save it:
SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1″, SYMLINK+=”android_adb”, MODE=”0666″
Step 3. Restart udev:
$ sudo restart udev
Check if the device is recognized:
$ adb devices
You may need to stop and start the adb server:
$ adb kill-server
$ adb start-server
Update: Please note that some devices require to disconnect the usb cable at this point and then reconnecting it.
You should be good to go…
Thanks for the post,
I have a nexus and for me worked writing this line:
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”22b8?, ATTRS{idProduct} ==”41db”, MODE=”0600?
in this file:
/etc/udev/rules.d/51-android.rules
Many thanks Dimitar – my Nexus One (AT&T / Rogers Wireless) needed config as per your instructions.
Cheers,
Alan
Excellent Post. Needed to know about the different Vendor ID for the Nexus One.
Also, I had to disconnect my phone from the USB before adb found it.
Top One
It works. Thank you very much. My phone is Nexus One
I had to start the server with sudo in order for it to recognize the permissions – using Ubuntu 10.04
darn, still doesn’t work.
Tried all the instructions exactly as mentioned but my T-Mobile Samsung Galaxy S Vibrant is still not getting recognized. Any pointers?
i have lg gw 620 i want to connect it to ubuntu
Using Ubuntu 10.10 there is no need to restart udev (or set permissions as some other guides have). udev automatically monitors and picks up changes.
If you will be using more than one phone then this works to pick them all up:
SUBSYSTEM=”usb”, SYSFS{product}=”Android Phone”, MODE=”0666″
For the techies the rules is looking in /sys/bus/usb/devices where each directory then corresponds to a device and there are files in each one with data in them. Using the SYSFS rule means all devices with that file containing that value. As you can see above Android Phones are easy to identify. There are also serial, idProduct/idVendor with hex values, manufacturer and product with text etc so you can be very specific or lax about what matches.
I am running Ubuntu Netbook Remix (UNR 9.10) and I cannot execute
code: $ adb devices
It says
code: Undefined command: “adb”. Try “help”.
@ flametop,
adb is part of the Android SDK. You need to install the SDK first. Take a look at this:
Installing the SDK
I have Samsung Galaxy that I would like my ubuntu machine to recognize.
1- lsusb command gives “Bus 001 Device 008: ID 04e8:681c Samsung Electronics Co., Ltd Galaxy Portal/Spica Android Phone”
2- Then I created and edited a file 51-android.rules
SUBSYSTEMS==”usb”,ATTRS{idVendor}==”04e8″,ATTRS{idProduct}==”681c” MODE=”0666″
3-sudo restart udev
4-
$ adb kill-server
$ adb start-server
5- adb devices
no luck.. still
List of devices attached
emulator-5554 device
???????????? no permissions
Any help will be beneficial
@ Vijay,
I struggled for a bit with the Samsung Galaxy as well, but got it working.
Make a file called “91-android.rules” and put the following in it:
SUBSYSTEM==”usb”, ATTRS{idVendor}==”04e8″, SYMLINK+=”android_adb”, MODE=”0666″, OWNER=”your_user_name”
Then restart udev and adb. You might have to disconnect and reconnect the phone to the USB.
Thank you so much dimitar!. This worked. You are absolutely right about disconnecting and reconnecting the phone to USB.
interesting. I have a GPAD G10 4Gig that I bought from pandawill.
I used the following:
SUBSYSTEM==”usb”, ATTRS{idVendor}==”18d1?, SYMLINK+=”android_adb”, MODE=”deed?, OWNER=”My_user_name”
Worked like a charm. Also disconnected and reconnected usb.
Thanks for this!
Works for me only, when starting adb with superuser
frank@frank-laptop:~$ sudo restart udev
udev start/running, process 5429
frank@frank-laptop:~$ adb devices
No command ‘adb’ found, did you mean:
Command ‘cdb’ from package ‘tinycdb’ (main)
Command ‘gdb’ from package ‘gdb’ (main)
Command ‘aub’ from package ‘aub’ (universe)
Command ‘dab’ from package ‘bsdgames’ (universe)
Command ‘zdb’ from package ‘zfs-fuse’ (universe)
Command ‘mdb’ from package ‘mono-debugger’ (universe)
Command ‘tdb’ from package ‘tads2-dev’ (multiverse)
Command ‘pdb’ from package ‘python’ (main)
Command ‘jdb’ from package ‘openjdk-6-jdk’ (main)
Command ‘ab’ from package ‘apache2-utils’ (main)
@Chito,
It looks like you have not added adb to your path, so the shell cannot find the command “adb”.
Depending on the Android SDK version you have, adb will be under either the “tools” or the “platform-tools” directory, which are in the SDK home directory.
So… in your case the path will looks something like this:
/home/frank/android-sdk-linux_86/tools
or
/home/frank/android-sdk-linux_86/platform-tools
In your case I would add both of these directories to your user’s path, since they contain useful tools you might need in the future.
To add them to your path, edit your .bashrc file and add them to the end of your PATH variable like so:
export PATH=${PATH}:/home/frank/android-sdk-linux_86/tools:/home/frank/android-sdk-linux_86/platform-tools
Once you are done you will need to source the .bashrc file if you want the change to be picked up. Just run:
. ./.bashrc
Pingback:Running App on Kendo M7 « Geek Quiet
Thanks Dimitar! I have a Samsung Galaxy S and have struggled with this. Thanks for the solution!
hi all…
i have a htc desire hd device… I tried so many things but can’t make it work… anybody made it ?
The google tutorial actually worked better than this: http://developer.android.com/guide/developing/device.html
great post Dimitar..was really useful…worked for my HTC desire fine…i just followed step 1…step 2 gives me following:
restart: Unknown job: udev
I got this to work by fixing the quotation marks around the SUBSYSTEMS==”usb”, etc. Copying and pasting this text directly caused some problems, and would not work for me until I deleted the quotation marks and put my own in. Hope that helps.
Thanks a million to Dimitar. 🙂
I’m running Ubuntu 10.04 with no success seeing either a netbook running Android or an LG phone running Android.
—
The netbook is connected with a Belkin Host to Host cable.
lsusb shows…
Bus 001 Device 009: ID 050d:258a Belkin Components F5U258 Host to Host cable.
The file
-rw-r–r– 1 root root 57 2011-07-04 18:29 /etc/udev/rules.d/51-android.rules
I tried both
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”050d”, ATTRS{idProduct}==”258a”, MODE=”0666″
and
SUBSYSTEMS==”usb”, SYSFS{idVendor}==”050d”, MODE=”0666″
—
lsusb reports the Android phone as…
Bus 001 Device 008: ID 1004:61ce LG Electronics, Inc.
The file was changed to …
SUBSYSTEMS==”usb”, SYSFS{idVendor}==”1004″, MODE=”0666″
—
After trying all of these…
$ sudo restart udev
$ adb kill-server
$ adb start-server
Disconnecting and reconnecting the usb cable.
Fail to report any devices when …
$ adb devices
I have several questions:
1. Does anyone have working rules for these devices?
2. What is the format of the file name?
3. Does 51-android.rules, 10-motorola-droid.rules or 99-android.rules have any specific meaning?
4. Can both devices be supported without changing the file?
5. Does anything need to be done on the Android device so that it can work with USB and Eclipse?
6. What is adb devices for looking for when it searches for Android devices?
Some progress has been made thanks to this article http://reactivated.net/writing_udev_rules.html.
Run “udevadm monitor –environment” in one window and change /etc/udev/rules.d/51-android.rules in another window. By repeatedly plugging and unplugging the Belkin cable I was able to refine a rule that would match only the netbook.
SUBSYSTEM==”usb”, ATTR{product}=”Belkin USB Easy Transfer Cable”, ENV{GLEN}=”%s{product}”, SYMLINK+=”belkin%n”, MODE=”0666″
The ENV{GLEN}=”%s{product}” is not needed, but is displayed by udevadm. The SYMLINK may prove useful, because the device shows up as /dev/belkin5. SYSFS and ATTRS do not appear to work, only ATTR.
The bad news is adb devices still doesn’t list anything as an Android device.
I have answered some of my questions…
1. Does anyone have working rules for these devices?
Using this method I should be able to work out the rules.d for any device.
2. What is the format of the file name?
Something to do with sorting the rules. Still unclear on this.
3. Does 51-android.rules, 10-motorola-droid.rules or 99-android.rules have any specific meaning?
see answer to 2.
4. Can both devices be supported without changing the file?
One file with multiple lines should be able to support several devices. Again not sure on the sorting priority as discussed in 2 above. Maybe the rules need to be in separate files.
5. Does anything need to be done on the Android device so that it can work with USB and Eclipse?
Still clueless.
6. What is adb devices for looking for when it searches for Android devices?
Same as 5 above.
@Glen,
First make sure that you have enabled “Unknown sources” on your device:
Settings -> Application Settings – check “Unknown sources”
I assume you want to do some development on it… so in this case hit “Development” on the same screen and enable “USB debugging” and the “Stay awake” feature (which is handy so the screen does not go out on you all the time).
1. I do not have your devices to test with, but if you follow the article you should be fine. Looks like you got the VendorID and the ProductID right.
2. The file names in the rules.d directory should follow this format:
nn-*.rules (where nn is a two digit number and * is a string that you want to supply in order to give some meaning to the file name)
3. See the answer to 2.
4. You can certainly have both of the devices in the same file. You do not have to have a separate file for each device. I have 5 devices in one file.
5. See the beginning of my comment.
6. adb devices lists any android devices that are running on the system. That includes physical devices connected to the computer and virtual devices that you might have created and are currently running.
The following 51-android.rules brings in both netbook and the LG Android phone.
SUBSYSTEM==”usb”, ATTR{product}==”Belkin USB Easy Transfer Cable”, ENV{GLEN}=”%s{product}”, SYMLINK+=”belkin%n”, MODE=”0666″
SUBSYSTEM==”usb”, ATTR{product}==”LG Android USB Device”, ENV{GLEN}=”%s{product}”, SYMLINK+=”lgandroid%n”, MODE=”0666″
In my previous post I had mistakenly written ATTR{product}=”…”. Use == for match criteria, single = for assignment.
After turning on Settings -> Applications -> Development -> USB Debugging on the Android phone adb devices listed something!
Still somewhat clueless about the finer points, but inching toward success. 😀
Thanks Dimitar for your help.
Even after turning on “Unknown sources” and “Stay awake” the Android EEE PC is not listed by “adb devices”.
Android on the EEE PCI can get to the internet and App Store. Is there any diagnostic tool that might be helpful? None of the Apps I downloaded could be installed.
Does Android need to be installed on a partition in the EEE PC for the App Store or “adb devices” to work properly? Android is running directly from the Flash drive now.
The ethernet connection has worked for me…
adb connect :5555
then do
adb devices
to see that its connected…..
Thanks for your help!
Should show IP address in previous post
adb connect EEEPC ip address here:5555
Thank you so much for this post. Have been struggling to get it to work for days on Ubuntu.
@dimitar, I have a Galaxy S2 and your suggestion worked perfectly (with the different details required, found as per the explanation by the OP).
Thanks a lot!
Thank you very much for your post. Worked perfectly.
This worked for me: Ubuntu 10.04 with Samsung Galaxy S II I9100
1: install eclipse and android sdk
2: set phone to accceth unknown sources and accept usb debuging
3 plugin phone
4 open term and type: lsusb | grep Samsung
, youll get a line like
Bus 001 Device 010: ID 04e8:685e Samsung Electronics Co., Ltd
notice the ID part !! 04e8 is vendor aka samsung, 685e is the product id
5 edit the udev rules file with:
sudo nano /etc/udev/rules.d/51-android.rules
add line
SUBSYSTEMS==”usb”, ATTRS{idVendor}==”04e8″, ATTRS{idProduct} ==”685e”, MODE=”0666″
Youll notice i used the vendor and product id , so this tactic will help you on other devices too.
The 51 of the file name just determine the order of the rules for udev.
6: restart udev with
sudo /etc/init.d/udev restart
this might not be needed but why take the risk
7: restart adk
sudo /android-sdk-linux_x86platform-tools/adb kill-server
sudo /android-sdk-linux_x86platform-tools/adb start-server
8: pull your handset out of the usb plug and put it in again
9: check your handset with adb:
adb devices
List of devices attached
304D19165B2E604E device
YEAH!!!!!
10: now eclipse debug section should recognize this godlike device.
Pingback:Colin Wren - Using your HTC Sensation to debug Android apps on Ubuntu 11.04 (Natty Narwhal) using udev and adb
so many people struggling with contents of rules file!!!
why not just do what roger said back in november 2010???!!
SUBSYSTEM=”usb”, SYSFS{product}=”Android Phone”, MODE=”0666″
Or even better…
SUBSYSTEM=”usb”, SYSFS{product}=””, MODE=”0666″
First will allow any droid phone, second should allow anything. It’s a silly requirement really, if somebody has physical access to your computer and is logged in, and doing things with it that you dont like, your freakin rules file is at the bottom of the list of problems you face.
also, put the droid tools under /opt/ and add the folders with the tools in to global system wide paths. no more worries, make sure you sudo chown -R root:root the_android_folder so it’s accessible but nobody fiddles with it.
hope this helps someone
f35
Hi All, I have the Samsung Gallaxy S phone. I wasn’t able to get it working in spite following the post from dimitar. The devices showing up was ?????????
The problem was the quotation marks. I copy pasted the text from the post and in the editor it got pasted as ? while they should have been ” . Once fixed it all worked for me!
After trying a bit, I’ve noted that udev is case sensitive too, you’ll want to put the phone ID in lower case when you do the product/vendor codes (and the phone needs to be in debug mode when you plug it in).
thanks much !
After all above, I had to do below steps to make it working.
sudo ./android
Then
Delete the Samsung Galay Tab Add-Ons
Install the Samsung Galay Tab Add-Ons again
Oh thank you so much. I had tried a hell lot to get this thing going. Even after following all your steps I still had ???????? listed for the adb devices command. Your final line was my savior 🙂 Disconnected the usb cable and reconnected and voila! 🙂
i have a samsung nexus s and I used this:
SUBSYSTEM==”usb”, ATTR{idVendor}==”18d1″, ATTR{idProduct}==”4e22″, MODE=”0666″
Pingback:Enicma
AndAndAndroid, yeaaaaahhhh!!!!! Worked!!!!
This works fine. Though make sure if you are copying and pasting you make sure all your double quotes look right!
spoke to soon soon is recognised by adb devices now but not showing up in the android SDK still???
Even after reboot!
Sorry what an idiot my android app is running on my Samsung Galaxy Phone so that is good enough for me even though it is not showing in the AVD Manager.
Thank you very much.
Thank you. Useful for me and my xubuntu 11.10 and samsung galaxy S IT9000.
One little remark:
I think the (x)ubuntu commands should be: $ ./adb …..
but again, thank you very much
I have problems attaching a kraun android tablet… on lsusb I have
Bus 002 Device 016: ID 05c6:9018 Qualcomm, Inc
but on the udev monitor is seen as an hard drive.
My udev rule is
SUBSYSTEM==”usb”, ATTRS{idVendor}==”05c6″, ATTRS{idProduct}==”9018″, MODE=”0666″
(have tried subsystem==”block” but with no luck)
Can someone help?
udevadm monitor result is available on http://pastebin.com/BmS24yML
Solved, the problem was adb not running with root permissions, thanks for the article.