最近由於內置的合作商比較多,本人使用的Ubuntu系統好多廠商的Android手機都無法正確的識別,經過一番折騰,和查閱SDK,現把Linux下ADB驅動配置的方法和當中會遇到的相關問題的解決方法整理出來貢獻給大家。

Linux下使用手機USB調試模式連接ADB進行Android程式的調試,配置驅動沒有Windows來的直觀。

具體步驟

首先確認手機連接上電腦,lsusb查看下設備記錄。

matthew@matthew-1230-laptop:~$ lsusb
Bus 007 Device 009: ID 18d1:4e12
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 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 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 004: ID 093a:2510 Pixart Imaging, Inc.
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

我這裡是:

Bus 007 Device 009: ID 18d1:4e12

然後在/etc/udev/rules.d/下創建一個設定檔: 51-android.rules

sudo vim /etc/udev/rules.d/50-android.rules

檔裡添加如下配置參數:

SUBSYSTEM=="usb", SYSFS{"High Tech Computer Corp."}=="0bb4", MODE="0666"

保存,給設定檔設置下許可權

sudo chmod a+rx /etc/udev/rules.d/50-android.rules

Restart

sudo /etc/init.d/udev restart

最後再重啟下adb服務,就可以了(沒配置環境變數的請進入Android SDK tools目錄執行sudo ./adb kill-server ./adb devices)

sudo adb kill-server
sudo adb devices

補充

SYSFS參數:

SYSFS{"idVendor"}="xxx"

針對Linux ADB驅動設定檔裡的SYSFS參數是指設備廠商。當初因為是HTC幫Google做的手機,所以官網一開始的用例上寫的是”High Tech Computer Corp.”。但現在Moto, 索愛, 三星等一批手機廠商的加入,Android生產廠商已不只HTC一家。而且且如果設備型號不是0bb4那該怎麼辦呢?

讀sdk説明文檔的時候,發現sdk已經提供了說明:
(詳見: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.

1. 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″
2. Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules

只要按照說明把創建的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

matthew@matthew-1230-laptop:~$ 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就可以看到你的設備已經連接

matthew@matthew-1230-laptop:/opt/android/android-sdk-linux_86/tools$ sudo ./adb devices
List of devices attached
0403502001011000    device

而在此之前,你可能看到的是

matthew@matthew-1230-laptop:/opt/android/android-sdk-linux_86/tools$ sudo ./adb devices
List of devices attached
????????????    no permissions

參考資料

http://androidappdocs.appspot.com/guide/developing/device.html
http://androidappdocs.appspot.com/guide/developing/device.html#VendorIds

 

 

 

FROM:http://www.aoandroid.com/node/2310

Posted by shadow at 痞客邦 PIXNET 留言(0) 引用(0) 人氣()