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

linux和Ubuntu下连接Android 的unkonw问题
[原贴]http://blog.csdn.net/jayaaaiii/article/details/6603746

概述

最近由于内置的合作商比较多,本人使用的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 LinuxFoundation 2.0 roothub
Bus 006 Device 001: ID 1d6b:0001 LinuxFoundation 1.1 roothub
Bus 005 Device 001: ID 1d6b:0001 LinuxFoundation 1.1 roothub
Bus 003 Device 001: ID 1d6b:0002 LinuxFoundation 2.0 roothub
Bus 002 Device 001: ID 1d6b:0001 LinuxFoundation 1.1 roothub
Bus 001 Device 001: ID 1d6b:0001 LinuxFoundation 1.1 roothub
Bus 004 Device 004: ID 093a:2510 PixartImaging, Inc.
Bus 004 Device 001: ID 1d6b:0001 LinuxFoundation 1.1 roothub

我这里是:
Bus 007 Device 009: ID 18d1:4e12

然后在/etc/udev/rules.d/下创建一个配置文件:51-android.rules
sudovim/etc/udev/rules.d/50-android.rules

文件里添加如下配置参数:
SUBSYSTEM=="usb",SYSFS{"HighTech Computer Corp."}=="0bb4", MODE="0666"

保存,给配置文件设置下权限
sudochmod a+rx /etc/udev/rules.d/50-android.rules

Restart
sudo/etc/init.d/udevrestart

最后再重启下adb服务,就可以了(没配置环境变量的请进入AndroidSDK tools目录执行sudo ./adb kill-server ./adb devices)
sudo adb kill-server
sudo adb devices
补充

SYSFS参数:
SYSFS{"idVendor"}="xxx"

针对LinuxADB驱动配置文件里的SYSFS参数是指设备厂商。当初因为是HTC帮Google做的手机,所以官网一开始的用例上写的是”HighTech Computer Corp.”。但现在Moto, 索爱,三星等一批手机厂商的加入,Android生产厂商已不只HTC一家。而且且如果设备型号不是0bb4那该怎么办呢?

读sdk帮助文档的时候,发现sdk已经提供了说明:
(详见:docs/guide/developing/device.html)

If you’re developing on UbuntuLinux, you need to add a rules file that contains a USBconfiguration for each type of device you want to use fordevelopment. Each device manufacturer uses a different vendor ID.The example rules files below show how to add an entry for a singlevendor ID (the HTC vendor ID). In order to support more devices,you will need additional lines of the same format that provide adifferent value for the SYSFS{idVendor} property. For other IDs,see the table of USBVendor IDs, below.

1. Log in as root and create thisfile: /etc/udev/rules.d/51-android.rules.

For Gusty/Hardy, edit the file toread: [注: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{i