关于adb命令没有权限访问手机设备
的
问题
在使用Ubuntu的朋友应该
碰到过在执行adb
相关
命令的时候会
提示
如下的错误:
liubzh@liubzh-PC:/$ adb shell
error: insufficient permissions for device
liubzh@liubzh-PC:/$ adb devices
List of devices attached
???????????? no permissions
在
网络上搜索
解决方案,发现最多的是如下的建议:
更改用户和组为root,
此
方法摘自
此处
。
转到adb所在的目录
shily@hh-desktop:~$cd ~/sdk/android-sdk_eng.sdk_linux-x86/tools
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$ls -ladb
-rwxr-xr-x 1 shily shily 341694 2010-05-11 05:46 adb
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$sudo chown root:root adb
[sudo] password for shily:
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$ls -ladb
-rwxr-xr-x 1root root 341694 2010-05-11 05:46 adb
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$sudo chmod u+s adb
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$ls -ladb
-rwsr-xr-x 1 root root 341694 2010-05-11 05:46 adb
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$
或者直接以root启动adb
-server,此方法摘自
此处
:
So you probably need to do “adb start-server” as root first:
ubuntu$ sudo ./out/host/linux-x86/bin/adb kill-server
ubuntu$ sudo ./out/host/linux-x86/bin/adb start-server
* daemon not running. starting it now *
* daemon started successfully *
ubuntu$ ./out/host/linux-x86/bin/adb shell
但是
,这样还是很麻烦,我们应该通过Android官方网站的方式来解决这个问题:
Set up your system to detect your device.
-
If you’re developing on Windows, you need to install a USB driver for adb. For aninstallation guide and links to OEM drivers, see the
OEM USBDrivers
document. - If you’re developing on Mac OS X, it just works. Skip this step.
-
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 the
ATTR{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. The
MODE
assignment specifies read/write permissions, and
GROUP
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
-
Log in as root and create this file:
详见
http://developer.android.com/tools/device.html
。
我们只需要这样在udev中
订制化我们自己的usb设备即可。
如下
命令我们可以
查看
vendor id
和
product id:
liubzh@liubzh-PC:~$ lsusb
Bus 002 Device 009: ID 24e3:7112
Bus 002 Device 003: ID 064e:c108 Suyin Corp.
Bus 005 Device 002: ID 192f:0916 Avago Technologies, Pte.
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 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
另见
http://source.android.com/source/initializing.html#configuring-usb-access
:
Configuring USB Access
Under GNU/linux systems (and specifically under Ubuntu systems),regular users can’t directly access USB devices by default. Thesystem needs to be configured to allow such access.
The recommended approach is to create a file
/etc/udev/rules.d/51-android.rules
(as the root user) and to copythe following lines in it.
<username>
must be replaced by theactual username of the user who is authorized to access the phonesover USB.
如:
SUBSYSTEM=="usb", ATTR{idVendor}=="24e3", ATTR{idProduct}=="7112", MODE="0600", OWNER="liubzh"
重新插拔USB
设备,
adb命令将会
正常被执行
。
转载请著名出处
。