小米手机利用USB连接到Ubuntu 12.04系统。运行下面的命令:
longskywang@bjb0503:~$ lsusb
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 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 001 Device 004: ID 138a:0008 Validity Sensors, Inc. VFS300 Fingerprint Reader
Bus 002 Device 007: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 002 Device 008: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 002 Device 025: ID 0461:4d22 Primax Electronics, Ltd
Bus 002 Device 005: ID 0c45:6481 Microdia
Bus 001 Device 005: ID 413c:8161 Dell Computer Corp. Integrated Keyboard
Bus 001 Device 006: ID 413c:8162 Dell Computer Corp. Integrated Touchpad [Synaptics]
Bus 002 Device 028: ID 2717:904e
Bus 001 Device 007: ID 413c:8160 Dell Computer Corp. Wireless 365 Bluetooth
拔掉手机的USB连接线,再运行:
longskywang@bjb0503:~$ lsusb
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 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 001 Device 004: ID 138a:0008 Validity Sensors, Inc. VFS300 Fingerprint Reader
Bus 002 Device 007: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 002 Device 008: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 002 Device 025: ID 0461:4d22 Primax Electronics, Ltd
Bus 002 Device 005: ID 0c45:6481 Microdia
Bus 001 Device 005: ID 413c:8161 Dell Computer Corp. Integrated Keyboard
Bus 001 Device 006: ID 413c:8162 Dell Computer Corp. Integrated Touchpad [Synaptics]
Bus 001 Device 007: ID 413c:8160 Dell Computer Corp. Wireless 365 Bluetooth
对比发现,Bus 002 Device 028: ID 2717:904e 就是小米手机的
sudo gedit /etc/udev/rules.d/50-android.rules在打开的文件中增加以下文本:
SUBSYSTEM=="usb", SYSFS{idVendor}=="2717", MODE=="0666"
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="2717", MODE=="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="2717", ATTR{idProduct}=="9039", SYMLINK+="android_adb"
sudo chmod a+rx /etc/udev/rules.d/50-android.rules
注意,这个50-android.rules 文件名字应该是随意命名的,试过 51-android.rules ,52-android.rules 似乎是都可以的。
注意 "SUBSYSTEM=="usb", SYSFS{idVendor}=="2717", MODE=="0666" "这句是给 ubuntu 7.01 以后的系统识别用的
而"SUBSYSTEM=="usb_device", SYSFS{idVendor}=="2717", MODE=="0666""是给 Ubuntu 7.01之前的系统识别用的。相当于系统兼容。
longskywang@bjb0503:/etc/udev/rules.d$ sudo service udev restart //or restart udev
udev start/running, process 7147
在 android sdk 的 tools 目录下运行 (这一步很重要,必须要sudo,否则没效果)
longskywang@bjb0503:~/android-sdk/platform-tools$ sudo ./adb kill-server
longskywang@bjb0503:~/android-sdk/platform-tools$ sudo ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
到这一步了,结果发现 List of devices attached 下面没有设备出现,这就意味着 adb不识别新的USB 设备,纠结了。
如果跟我一样悲惨,请执行如下操作
longskywang@bjb0503:~$ cd ~
longskywang@bjb0503:~$ cd .android/
longskywang@bjb0503:~/.android$ ls
adbkey adb_usb.ini~ avd debug.keystore repositories.cfg
adbkey.pub androidtool.cfg cache default.keyset sites-settings.cfg
adb_usb.ini androidwin.cfg ddms.cfg modem-nv-ram-5554
请注意这个 adb_usb.ini(如果没有,可以自己建立一个)
longskywang@bjb0503:~/.android$ gedit adb_usb.ini
里面的内容一般如下:
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
我们在其中加一行
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x2717
请注意,这个 0x2717 就是我们得到的设备号码
保存,关掉,然后
longskywang@bjb0503:~/android-sdk/platform-tools$ sudo ./adb kill-server
longskywang@bjb0503:~/android-sdk/platform-tools$ sudo ./adb devices
List of devices attached
9109ce53 device
注意 9109ce53 device 这行就是我们的识别到的小米手机了。哈哈