This webpage helps you set up your 51-android.rules file so that you can automatically start Android's adb server program.
This file is of interest to you if you use the Android SDK toolkit or Eclipse on Linux while trying to develop or test a program on your Android Cell Phone or Tablet. The contents on this webpage are based on information found on Android's SDK Dev Guide, the Vendor and Product list found on the USB ID Repository and information gathered from various other websites and pages (as of October 11, 2011).
This webpage was written due to what seemed to be some confusion and a lack of information needed to get other Linux Distros such as Fedora, Mageia, Mandriva, RedHat, and other distros with subtle differences to work.
WHY ARE YOU INTERESTED IN THIS FILE?
Three reasons come to mind, but you may think of other reasons why too.
The problem that is happening is that the SDK tries to connect to the Android cell Phone or Tablet as a regular user program, but Linux is blocking and firewalling as a default condition. Linux needs to know that you are allowed access, and therefore needs to setup for those conditions.
These conditions can be solved manually, or automatically. To do this automatically, the solution is to describe what needs to be done when the hardware is plugged into the USB port on your computer, and the way to do that "here" is using a udev rules file. For the Android SDK, this file is referred to, as 51-android.rules.
First, you can download 51-android.rules, or you can copy and paste the file shown below into a text editor.
# Android Debug Bridge (adb) udev definition file # # This rules file will add a /dev/android_adb symlink when an Android phone with # an identified idVendor:idProduct appears on the USB port. Then it will run the # Android adb program (located in specified RUN+ statement below). # # This file may be out of date, please check Android developer documentation for # ##-android.rules udev rules file to support Android Debug Bridge on USB. # Some codes have idVendor, and some have an extra {idProduct} code. # # NOTE: Only uncomment the phone you are debugging since you will not want to # uncomment a working phone. You may need to add extra ATTRS{idProduct}=="????" # tests if you have more than 1 USB device from the same manufacturer, this way, # you identify the right product. For examples, look at # Google or HTC codes # shown below which have additional {idProduct} tests. # # If you find new {idProduct} codes, please send info to www.linux-usb.org, and # also to android developer forum. You can test for new values by running the # command lsusb to identify any USB devices. Some Android devices have different # codes while running in normal or in debug mode. udev is case sensitive so you # need to ensure that you use the same (lower) case for hexidecimal values. # # NOTE: You need to modify the RUN+="" statement to point to your location you # use where your adb program is located. # # NOTE: Debian type distros may need to have GROUP="plugdev" instead of "usb" # NOTE: You have to add yourself to the "usb" (or "plugdev") group if you choose # to use MODE=0664 instead of MODE=0666. This example rules file uses MODE=0664. # # Version 1.0, by Jose Da Silva <Digital@JoesCat.com> 2011oct11 # Version 1.1, by Jose Da Silva <Digital@JoesCat.com> 2012sep30 ACTION!="add", GOTO="android_usb_rules_end" SUBSYSTEM!="usb", GOTO="android_usb_rules_end" LABEL="android_usb_rules_begin" # (Remove the comment '#' if your device has a comment in front of it) # Acer # ATTRS{idVendor}=="0502", ENV{adb_matched}="yes" # Acer Liquid 3202, 3203=(debug) ATTRS{idVendor}=="0502", ATTRS{idProduct}=="3203", ENV{adb_matched}="yes" # Archos 5 1350=(storage), 1357=(media), 1360=(network), 1361, 18d1:0002=(debug) # ATTRS{idVendor}=="0e79", ATTRS{idProduct}=="1361", ENV{adb_matched}="yes" # ASUS # ATTRS{idVendor}=="0b05", ENV{adb_matched}="yes" # Dell # ATTRS{idVendor}=="413c", ENV{adb_matched}="yes" # Foxconn ATTRS{idVendor}=="0489", ENV{adb_matched}="yes" # Fujitsu, Fujitsu Toshiba # ATTRS{idVendor}=="04c5", ENV{adb_matched}="yes" # Garmin-Asus # ATTRS{idVendor}=="091e", ENV{adb_matched}="yes" # Google, Nexus One 4e11, 4e12=(debug), 4e13=(tether) # Google, Nexus S 4e20=(fastboot), 4e21, 4e22=(debug), 4e24=(tether) ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e?2", ENV{adb_matched}="yes" # Haier # ATTRS{idVendor}=="201E", ENV{adb_matched}="yes" # Hisense # ATTRS{idVendor}=="109b", ENV{adb_matched}="yes" # HTC Dream / ADP1 / G1 / Magic / Tattoo =0c01, 0c02=(debug) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c02", ENV{adb_matched}="yes" # HTC Desire 0c87=(debug) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c87", ENV{adb_matched}="yes" # HTC EVO 4G 0c8d=(debug) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c8d", ENV{adb_matched}="yes" # HTC Desire 0c99=(debug) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c99", ENV{adb_matched}="yes" # HTC Desire HD 0ca2=(debug), 0ff8=(tether) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0ca2", ENV{adb_matched}="yes" # HTC Android Fastboot Bootloader 0fff, 0ffe=(modem) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0fff", ENV{adb_matched}="yes" # Huawei # ATTRS{idVendor}=="12d1", ENV{adb_matched}="yes" # Huawei Ideos 1037, 1038=(debug) ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1038", ENV{adb_matched}="yes" # K-Touch # ATTRS{idVendor}=="24e3", ENV{adb_matched}="yes" # KT Tech # ATTRS{idVendor}=="2116", ENV{adb_matched}="yes" # Kyocera # ATTRS{idVendor}=="0482", ENV{adb_matched}="yes" # Lenovo # ATTRS{idVendor}=="17ef", ENV{adb_matched}="yes" # LG # ATTRS{idVendor}=="1004", ENV{adb_matched}="yes" # LG Ally/Optimus One/Vortex/P500 618f, 618e=(debug) ATTRS{idVendor}=="1004", ATTRS{idProduct}=="618e", ENV{adb_matched}="yes" # LG GT540, 61b4 (disable "as USB storage) ATTRS{idVendor}=="1004", ATTRS{idProduct}=="61b4", ENV{adb_matched}="yes" # Motorola # ATTRS{idVendor}=="22b8", ENV{adb_matched}="yes" # Motorola Droid/Milestone/Nexus 41d9, 41db=(debug), 41de=(PCmode) ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="41db", ENV{adb_matched}="yes" # Motorola Cliq/MB200 2d66=(debug) ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="2d66", ENV{adb_matched}="yes" # Motorola Xoom MZ600 70a8, 70a9=(debug) ATTRS{idVendor}=="22b8", ATTRS{idProduct}=="70a9", ENV{adb_matched}="yes" # MTK # ATTRS{idVendor}=="0e8d", ENV{adb_matched}="yes" # NEC # ATTRS{idVendor}=="0409", ENV{adb_matched}="yes" # Barnes and Noble Nook=0001, NOOKcolor=0002 # ATTRS{idVendor}=="2080", ENV{adb_matched}="yes" # Nvidia # ATTRS{idVendor}=="0955", ENV{adb_matched}="yes" # Nvidia Notion Ink Adam 7100, ????=(debug) ATTRS{idVendor}=="0955", ATTRS{idProduct}=="71??", ENV{adb_matched}="yes" # OTGV # ATTRS{idVendor}=="2257", ENV{adb_matched}="yes" # Pantech # ATTRS{idVendor}=="10a9", ENV{adb_matched}="yes" # Pegatron # ATTRS{idVendor}=="1d4d", ENV{adb_matched}="yes" # Philips # ATTRS{idVendor}=="0471", ENV{adb_matched}="yes" # Panasonic (Matsushita) # ATTRS{idVendor}=="04da", ENV{adb_matched}="yes" # Qualcomm # ATTRS{idVendor}=="05c6", ENV{adb_matched}="yes" # SK Telesys # ATTRS{idVendor}=="1f53", ENV{adb_matched}="yes" # Samsung # ATTRS{idVendor}=="04e8", ENV{adb_matched}="yes" # Samsung GT19100 Galaxy S II, 6860, 685e=(debug), 685b=(storage) ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="685e", ENV{adb_matched}="yes" # Samsung Z100 Mobile Phone 6601=(debug) ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="6601", ENV{adb_matched}="yes" # Sharp # ATTRS{idVendor}=="04dd", ENV{adb_matched}="yes" # Sony Ericsson # ATTRS{idVendor}=="0fce", ENV{adb_matched}="yes" # Sony Ericsson Xperia X10 mini 3137, 2137=(debug) ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="2137", ENV{adb_matched}="yes" # Sony Ericsson Xperia X10 mini pro 3138, 2138=(debug) ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="2138", ENV{adb_matched}="yes" # Sony Ericsson Xperia X8 3149, 2149=(debug) ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="2149", ENV{adb_matched}="yes" # Sony Ericsson Xperia X12 e14f, 614f=(debug) ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="614f", ENV{adb_matched}="yes" # Teleepoch # ATTRS{idVendor}=="2340", ENV{adb_matched}="yes" # Toshiba # ATTRS{idVendor}=="0930", ENV{adb_matched}="yes" # ZTE # ATTRS{idVendor}=="19d2", ENV{adb_matched}="yes" # ZTE Blade 1353, 1351=(debug), 1354=(recovery) 18d1:d00d=(fastboot) ATTRS{idVendor}=="19d2", ATTRS{idProduct}=="1351", ENV{adb_matched}="yes" # If a match is found, then add the device and run the adb server ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" SYMLINK+="android_adb", MODE="0664", GROUP="usb" RUN+="/opt/android-sdk-linux_x86/platform-tools/adb devices" LABEL="android_usb_rules_end" |
You need to modify this file before you can use it.
GET YOUR PHONE OR TABLET ID DETAILS FIRST
Before you can make use of the file above, you need to see what are the {idVendor} and {idProduct} numbers so that you can edit the file with the correct information before using it.
When you plug your Android phone or tablet into the USB on your computer, it identifies itself differently based on which mode your cell phone is set to, for example, the HTC Magic cell phone identifies itself as "0bb4:0c01" in normal mode, but as "0bb4:0c02" when it is in debug mode.
If you have a development cell phone or tablet, go to it's settings and find the setting you need to turn it into "debug" mode. After you switch your Android phone or tablet into "debug" mode, then plug it into the USB slot on your computer. Next go to the command line, and use the lsusb command to find the cell phone or tablet identity. You can follow the steps shown below.
1. 2. |
|
This example above shows the results of "0bb4:0c02".
ADD OR EDIT THE FILE WITH YOUR PHONE OR TABLET ID DETAILS
The udev program that uses the ID information is case sensitive and expects the information as lower-case hexidecimal values. You need to edit, or add a line to your 51-android.rules file with the information you found if it isn't already included in the list. It should look something like this:
# HTC Dream / ADP1 / G1 / Magic / Tattoo =0c01, 0c02=(debug) ATTRS{idVendor}=="0bb4", ATTRS{idProduct}=="0c02", ENV{adb_matched}="yes" |
If your Android cell phone or table does not have a separate code for "debug" mode, or you want to make the udev rules a bit more general, then you can substitute ? (question marks), such as ATTR{idProduct}="0c0?", or you can leave-out the statement like this:
# HTC Dream / ADP1 / G1 / Magic / Tattoo =0c01, 0c02=(debug) ATTRS{idVendor}=="0bb4", ENV{adb_matched}="yes" |
If your device does not have a separate ID for debug mode, or if you decide to do the more general method, you should comment-out the instructions at the bottom because you may not want to run the Android adb server every time you plug-in your Development Phone or Tablet.
# If a match is found, then add the device and run the adb server # ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" # SYMLINK+="android_adb", MODE="0664", GROUP="usb" # RUN+="/opt/android-sdk-linux_x86/platform-tools/adb devices" |
If you want to simplify this file, you can remove all the other lines referring to other Cell Phones that you do not have or use.
Good question. This is one of those subtle differences between various Linux distributions. For example: RedHat, Fedora, Mageia, Mandriva, etc... have a user group named "usb" while other distributions such as Debian, Ubuntu, etc... have a user group named "plugdev".
If you want to follow the example shown on Android's Using Hardware Devices and you are using a Linux distribution which makes use of "plugdev", then you will want to edit this line near the bottom of the file:
# If a match is found, then add the device and run the adb server ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" SYMLINK+="android_adb", MODE="0664", GROUP="plugdev" RUN+="/opt/android-sdk-linux_x86/platform-tools/adb devices" |
If you want only users belonging to group "usb" to be able to write to your Cell Phone or Tablet, then keep MODE="0664", but you need to add yourself to the "usb" or "plugdev" group. If you want to keep it simple and give eveyone access, then you will need to change the command to MODE="0666".
# If a match is found, then add the device and run the adb server ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" SYMLINK+="android_adb", MODE="0666", GROUP="usb" RUN+="/opt/android-sdk-linux_x86/platform-tools/adb devices" |
YOU NEED TO EDIT THE RUN+ INSTRUCTION
When you downloaded Android's SDK toolkit, you saved it somewhere, like your home directory, or another directory. Inside the toolkit is a subdirectory "android-sdk-linux_x86/platform-tools/" which has the adb server which is needed when you connect to your hardware to debug a program. You will need to edit the "RUN+" instruction to point to the location where your adb is located.
# If a match is found, then add the device and run the adb server ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" SYMLINK+="android_adb", MODE="0664", GROUP="usb" RUN+="/opt/android-sdk-linux_x86/platform-tools/adb devices" |
If you run the adb server as a normal user, you can run into the problem that Linux blocks access to your hardware.
1. |
|
If you get these udev 51-android.rules set up, and you run the adb server as a root user, then you can access your hardware device. Once the adb server is running as a root user, you can then access your hardware as a normal user too.
1. |
|
If you want to run Android's adb server under another user other than "root", then modify the "RUN+" statement like this (substitute a user for "you"):
# If a match is found, then add the device and run the adb server ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" SYMLINK+="android_adb", MODE="0664", GROUP="usb" RUN+="/bin/su you -c '/opt/android-sdk-linux_x86/platform-tools/adb devices'" |
Here is an example output if you did it this way:
1. 2. |
|
This is not important for Android's adb server since it does not use this, but it might be useful to you if you need a consistent location to find your hardware for other purposes.
Some computers have USB devices appear in directory "/dev/usb/", other computers may have devices appear in directory "/dev/bus/usb/". You may have noticed that when you plug in a device into a USB port, it appears on one port when you look inside directory "/dev", then if you unplug the device and plug it back in, it appears on another location. Do it again, it appears somewhere else in directory "/dev". Not very consistent. What the "SYMLINK+" instruction does, is create a link to your device in a consistent location, so regardless of where it appears in directory "/dev/", you can always find a link at "/dev/android_adb/" when you plug your device into a USB port on your computer.
A few webpages referred to "android_adb", so it seemed a good choice just to be consistent.
# If a match is found, then add the device and run the adb server ENV{adb_matched}!="yes", GOTO="android_usb_rules_end" SYMLINK+="android_adb", MODE="0664", GROUP="usb" RUN+="/opt/android-sdk-linux_x86/platform-tools/adb devices" |
This shows you what it could look like for you after you setup your udev rules file.
1. 2. |
|
INSERT YOUR FILE IN UDEV RULES.D DIRECTORY
Once you have added or edited your particular Cell Phone or Tablet to the rules file, and added the location of where you keep your adb server, it is now time to save the 51-android.rules file in directory "/etc/udev/rules.d/". We assume you saved your edited file in your "~" home directory.
1. 2. 3. 4. 5. 6. 7. |
|
NOTES: According to some websites, some people indicate they have had trouble with this file if it is named 51-android.rules. This can happen if another rule after this changes some settings, such as user or group ownership of the USB ports get reverted back to "root:root". To solve this problem, you will need to save your file with a number that makes this rule happen later in the udev rules process, for example 61-android.rules or 71-android.rules (the 51, 61, 71 indicates when the rule applies).
TEST TO SEE IF THE ADB SERVER WORKS
After saving the rules file above, check if it all works. Reboot your computer. Change your Cell Phone or Tablet to "Debug" mode, and also enable "unknown sources", then plug it into your computer's USB port. Then go to the command line and check:
1. 2. 3. 4. 5. 6. 7. |
|
It is great if you find this 51-android.rules file useful. If you have any comments, suggestions, or fixes, please send them using the comment section here, thanks!
If you want to know more about udev, you can read this very detailed guide writing udev rules.
Links To Sections Of This Page | ||||
---|---|---|---|---|
Top Of Page | Why Read This? | Get The File | Get USB ID | Add Your ID |
Group USB or Plugdev? | Mode Security | Symlink Setup | Insert Rules | Test Setup |