adb shell 出现 insufficient permissions for device

参考网址:http://hi.baidu.com/iceliushuai/blog/item/1e506160c5d01f48eaf8f801.html

出现如下错误信息:
shily@hh-desktop:~$adb shell
error: insufficient permissions for device
shily@hh-desktop:~$ adb devices
List of devices attached
????????????    no permissions
// ====暂时解决办法==============================================================
使用root权限来启动adb server
shily@hh-desktop:~$ sudo -s
[sudo] password for shily:
root@hh-desktop:~# adb kill-server ; adb start-server
* daemon not running. starting it now *
* daemon started successfully *
root@hh-desktop:~# exit
exit
shily@hh-desktop:~$
再次执行adb shell就可以了。

可是这样也不是办法,因为这个错误太频繁了,在开发的过程中,很容易执行adb kill-server,然后再切换到root启动adb start-server太不方便。

这个时候就是setuid起作用的时候了。
转到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 -l adb
-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 -l adb
-rwxr-xr-x 1 root 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 -l adb
-rwsr-xr-x 1 root root   341694 2010-05-11 05:46 adb
shily@hh-desktop:~/sdk/android-sdk_eng.sdk_linux-x86/tools$
这样无论哪个用户启动adb 使用的都是root权限,就不会提示权限不足的错误了。
---------------------------------------------
在使用的过程中发现adb pull下来的文件属主权限为root:root,所以修改起来不方便。但是我不经常下载文件修改,也就忍了。

// ====最终解决办法==============================================================
http://developer.android.com/guide/developing/device.html

在ubuntu系统下开发的话,添加下面这一句到/etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
(之前的写法是:SYSFS{idVendor}=="0bb4" 现在已经改为ATTR{idVendor}=="0bb4")
对应不同的设备需要不同的idVendor,开发手册上列出了一些设备的idVendor,不过仍然有些没有列出来的设备,这时可使用lsusb得到
将设备通过usb连接到pc上,执行
ray@ray-desktop:/etc/udev/rules.d$ lsusb
Bus 004 Device 001: ID 0000:0000  
Bus 005 Device 001: ID 0000:0000  
Bus 003 Device 001: ID 0000:0000  
Bus 002 Device 001: ID 0000:0000  
Bus 001 Device 005: ID 0502:3389 Acer, Inc.
Bus 001 Device 002: ID 0bda:0151 Realtek Semiconductor Corp.
Bus 001 Device 001: ID 0000:0000  

那么要连接这一台设备就要在51-android.rules中添加一行:
SUBSYSTEM=="usb", ATTR{idVendor}=="0502", MODE="0666", GROUP="plugdev"

修改/etc/udev/rules.d/51-android.rules不需要重启Linux机器,重新插拔一下设备就可以了。再次运行adb devices就可以看到你的设备已经连接

// ====终极解决办法==============================================================
如果你是一个开发人员,而且USB设备很多的话,使用以下方式会很方便:
清空51-android.rules,添加如下一行,一劳永逸(因我需要测试好几种设备,每次都添加一个会很麻烦)。
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666"
我并不是很清楚具体的含义,只是模仿10-vboxdrv.rules来写的,这个是virtualbox的udev规则文件,因为名字开头数字大文件中记录的规则会覆盖名字开头数字小的文件中的规则,所以你需要尽可能设置的文件名大一些,51已经够用了(我原来想写在10-vboxdrv.rules,让他们用一个文件,但是失败了)

=================================================================================
另外,在通过USB调试之前,不要忘记启动设备的usb侦错。
然后在项目的AndroidManifest.xml文件中的<application>下添加 android:debuggable="true"。项目发布的时候要记得去掉。
对于windows和Mac OS X开发环境,在开发手册上还有如下的说明:
#If you're developing on Windows, you need to install a USB driver for adb. For an installation guide and links to OEM drivers, see the OEM USB Drivers document.
#If you're developing on Mac OS X, it just works. Skip this step.

posted @ 2012-04-26 12:42  日光之下无新事  阅读(10407)  评论(0编辑  收藏  举报