關於adb命令沒有權限訪問手機設備的問題

關於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 theOEM 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 audev 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, seeUSB Vendor IDs, below. To set up device detection onUbuntu Linux:
    1. 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 MODEassignment specifies read/write permissions, andGROUP defineswhich Unix group owns the device node.

      Note: The rule syntaxmay vary slightly depending on your environment. Consult theudevdocumentation for your system as needed. For an overview of rule syntax, seethis guide towriting udevrules.

    2. Now execute:
      chmod a+r /etc/udev/rules.d/51-android.rules
詳見http://developer.android.com/tools/device.html

我們只需要這樣在udev中訂製化我們自己的usb設備即可。


如下命令我們可以查看vendor idproduct 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命令將會正常被執行


轉載請著名出處

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章