读sdk帮助文档的时候,发现sdk已经提供了说明。使用这种方式就可以避免adb pull下来的文件权限为root。
详见:docs/guide/developing/device.html
If you're developing on Ubuntu Linux, you need to add a rules file that contains a USB configuration for each type of device you want to use for development. Each device manufacturer uses a different vendor ID. The example rules files below show how to add an entry for a single vendor ID (the HTC vendor ID). In order to support more devices, you will need additional lines of the same format that provide a different value for the SYSFS{idVendor}
property. For other IDs, see the table of USB Vendor IDs, below.
/etc/udev/rules.d/51-android.rules
. For Gusty/Hardy, edit the file to read: [注:ubuntu 7.10及以后版本]
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
For Dapper, edit the file to read: [注:ubuntu 6.06及以前版本]
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"
chmod a+r /etc/udev/rules.d/51-android.rules
只要按照说明在/etc/udev/rules.d/目录下创建51-android.rules,把其中的0bb4修改为相应的USB,供应商ID信息即可。
比如我的手机是motorola,idVender是22b8
那么这一行就是
SUBSYSTEM=="usb", SYSFS{idVendor}=="
22b8
", MODE="0666"
不过,你可以写多行,以使用各种设备。比如我就写了所有的,我的文件如下:
#Acer 0502
SUBSYSTEM=="usb", SYSFS{idVendor}=="0502", MODE="0666"
#Dell 413c
SUBSYSTEM=="usb", SYSFS{idVendor}=="413c", MODE="0666"
#Foxconn 0489
SUBSYSTEM=="usb", SYSFS{idVendor}=="0489", MODE="0666"
#Garmin-Asus 091E
SUBSYSTEM=="usb", SYSFS{idVendor}=="091e", MODE="0666"
#HTC 0bb4
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
#Huawei 12d1
SUBSYSTEM=="usb", SYSFS{idVendor}=="12d1", MODE="0666"
#Kyocera 0482
SUBSYSTEM=="usb", SYSFS{idVendor}=="0482", MODE="0666"
#LG 1004
SUBSYSTEM=="usb", SYSFS{idVendor}=="1004", MODE="0666"
#Motorola 22b8
SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", MODE="0666"
#Nvidia 0955
SUBSYSTEM=="usb", SYSFS{idVendor}=="0955", MODE="0666"
#Pantech 10A9
SUBSYSTEM=="usb", SYSFS{idVendor}=="10A9", MODE="0666"
#Samsung 04e8
SUBSYSTEM=="usb", SYSFS{idVendor}=="04e8", MODE="0666"
#Sharp 04dd
SUBSYSTEM=="usb", SYSFS{idVendor}=="04dd", MODE="0666"
#Sony Ericsson 0fce
SUBSYSTEM=="usb", SYSFS{idVendor}=="0fce", MODE="0666"
#ZTE 19D2
SUBSYSTEM=="usb", SYSFS{idVendor}=="19D2", MODE="0666"
但是我要说明的是,根据上面的这些ID,并不能包括所有的,我手上就有一台设备的USB ID都不在上述之列。
你可以很方便的使用lsusb命令查看自己的USB ID
shily@hh-desktop:~$ lsusb
Bus 002 Device 003: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 002 Device 002: ID 0461:4d22 Primax Electronics, Ltd
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 010: ID 18a1:0002
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
找到上面的id是18a1,在文件中添加我的设备就可以了。
SUBSYSTEM=="usb", SYSFS{idVendor}=="18a1", MODE="0666"
修改/etc/udev/rules.d/51-android.rules
不需要重启Linux机器,重新插拔一下设备就可以了。再次运行adb devices就可以看到你的设备已经连接
shily@hh-desktop:~$ adb devices
List of devices attached
0403502001011000 device
而在此之前,你看到的是
shily@hh-desktop:~$ adb devices
List of devices attached
???????????? no permissions
读adb 命令的帮助文档,详细的了解一些adb命令。