文章目錄
【摘錄自】http://blog.csdn.net/zhenwenxian/archive/2010/09/23/5901350.aspx
Linux下Android ADB驅動安裝詳解
概述
最近由於內建的合作商比較多,本人使用的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資訊即可。
比如My Phone是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