日期:2014-05-16  浏览次数:20479 次

adb shell 无法启动 (insufficient permissions for device
环境:Ubuntu 10.04 LTS ,Ophone SDK
关键字:insufficient permissions for device

出现如下错误信息:
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,所以修改起来不方便。但是我不经常下载文件修改,也就忍了。

2010-06-21 重要更新

读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.

    Log in as root and create this file: /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"
    Now execute:
    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"