If you're developing on Ubuntu Linux, you need to add a udev
rules file that contains a USB configuration for each type of deviceyou want to use for development. In the rules file, each device manufactureris identified by a unique vendor ID, as specified by theATTR{idVendor}
property. For a list of vendor IDs, see USB Vendor IDs, below. To set up device detection onUbuntu Linux:
- Log in as root and create this file:
/etc/udev/rules.d/51-android.rules
.Use this format to add each vendor to the file:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for HTC. TheMODE
assignment specifies read/write permissions, andGROUP
defineswhich Unix group owns the device node.Note: The rule syntaxmay vary slightly depending on your environment. Consult the
udev
documentation for your system as needed. For an overview of rule syntax, seethis guide to writing udevrules. - Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
- 如何查看device id,root帐号运行lsusb
[root@zlf rules.d]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 413c:2107 Dell Computer Corp.
Bus 001 Device 004: ID 192f:0416 Avago Technologies, Pte.
Bus 002 Device 005: ID 22b8:41da Motorola PCS其中红色一行是我们要的目标设备信息,按照步骤a的格式添加到android.rules的配置文件中即可
d. 重起adb,adb需要配置对应的PATH环境变量,把sdk中对应的platform-tools目录加到PATH环境变量即可
下面是网上别人在ubantu的一篇博文
sdk文档上有推荐方法是:
1. 新建 /etc/udev/rules.d/51-android.rules,该文件内容可模仿下面的内容:
# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600",OWNER=="username"
这个是让系统识别Nexus One android机器的内容,如果要加你自己的机器,只要知道你目标机的 VendorId, ProductId即可。
2. 如何得到VendorId, ProducId?将目标机用usb与电脑相连,在命令行窗口输入lsusb,即可显示与本机相连的所有usb设备。如:
michelle@michelle-ThinkPad-Edge:~$ lsusb
Bus 002 Device 007: ID 0489:c001 Foxconn / Hon Hai
Bus 002 Device 003: ID 17ef:4815 Lenovo Integrated Webcam [R5U877]
其中 Bus 002 Device 007: ID 0489:c001 Foxconn / Hon Hai
是我的android设备. 它的VendorId是0489,ProductId是c001。
3.在 /etc/udev/rules.d/51-android.rules文件中加入刚才lsusb中查到的内容既可。如:
# adb protocol on FM6 (Foxconn FM6)
SUBSYSTEM=="usb", ATTR{idVendor}=="0489", ATTR{idProduct}=="c001", MODE="0666", OWNER="michelle"
这里的OWNER就是你登录ubuntu的用户。
4. 在命令行执行
sudo chmod a+rx 51-android.rules
sudo service udev restart
这样就重启了udev service,让刚才新加的51-android.rules生效
5.执行
adb kill-server
adb devices
即可看到找到对应的设备,adb可用。
6. 如果这样做后还是不能连上adb, 则要在 ~/.android 目录下的adb_usb.ini文件中添加你所查到的设备的vendor id. 如本例中 vendorID = 0489, 则在该文件下添加一行:
0x0489
7.然后重新执行步骤5即可