这几天在做机型适配,发现有部分安卓手机在ubuntu下无法debug调试,adb识别设备全是问题。
搜索了一下,是ubuntu udev设备识别的问题。从官网看到如下方法

查询手机参数

我这里有几款比较偏的型号,huawei C8388 ,vivo S7t ,现在命令行查询

lsusb

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 003: ID 19d2:0249 ZTE WCDMA Technologies MSM

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 003 Device 002: ID 17ef:6019 Lenovo

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

其中 Bus 001 Device 003: ID 19d2:0249 则是中兴手机的idVendor码。相对的,其他厂商的idVendor码可以在官方中查询

配置udev

sudo gedit /etc/udev/rules.d/51-android.rules/

将查到的idVendor变成以下内容加入到文件中

SUBSYSTEM”usb”, ATTR{idVendor}”19d2″, MODE=”0666″, GROUP=”plugdev”

我将google官方的都整进去了,免得麻烦。也加了个 vivo 手机的。如果还有无法识别的,想上面那样弄把。

# Acer SUBSYSTEM"usb", ATTR{idVendor}"0502", MODE="0666", GROUP="plugdev" # ASUS SUBSYSTEM"usb", ATTR{idVendor}"0b05", MODE="0666", GROUP="plugdev" # Dell SUBSYSTEM"usb", ATTR{idVendor}"413c", MODE="0666", GROUP="plugdev" # Foxconn SUBSYSTEM"usb", ATTR{idVendor}"0489", MODE="0666", GROUP="plugdev" # Fujitsu SUBSYSTEM"usb", ATTR{idVendor}"04c5", MODE="0666", GROUP="plugdev" # Fujitsu Toshiba SUBSYSTEM"usb", ATTR{idVendor}"04c5", MODE="0666", GROUP="plugdev" # Garmin-Asus SUBSYSTEM"usb", ATTR{idVendor}"091e", MODE="0666", GROUP="plugdev" # Google SUBSYSTEM"usb", ATTR{idVendor}"18d1", MODE="0666", GROUP="plugdev" # Haier SUBSYSTEM"usb", ATTR{idVendor}"201E", MODE="0666", GROUP="plugdev" # Hisense SUBSYSTEM"usb", ATTR{idVendor}"109b", MODE="0666", GROUP="plugdev" # HTC SUBSYSTEM"usb", ATTR{idVendor}"0bb4", MODE="0666", GROUP="plugdev" # Huawei SUBSYSTEM"usb", ATTR{idVendor}"12d1", MODE="0666", GROUP="plugdev" # Intel SUBSYSTEM"usb", ATTR{idVendor}"8087", MODE="0666", GROUP="plugdev" # K-Touch SUBSYSTEM"usb", ATTR{idVendor}"24e3", MODE="0666", GROUP="plugdev" # KT Tech SUBSYSTEM"usb", ATTR{idVendor}"2116", MODE="0666", GROUP="plugdev" # Kyocera SUBSYSTEM"usb", ATTR{idVendor}"0482", MODE="0666", GROUP="plugdev" # Lenovo SUBSYSTEM"usb", ATTR{idVendor}"17ef", MODE="0666", GROUP="plugdev" # LG SUBSYSTEM"usb", ATTR{idVendor}"1004", MODE="0666", GROUP="plugdev" # Motorola SUBSYSTEM"usb", ATTR{idVendor}"22b8", MODE="0666", GROUP="plugdev" # MTK SUBSYSTEM"usb", ATTR{idVendor}"0e8d", MODE="0666", GROUP="plugdev" # NEC SUBSYSTEM"usb", ATTR{idVendor}"0409", MODE="0666", GROUP="plugdev" # Nook SUBSYSTEM"usb", ATTR{idVendor}"2080", MODE="0666", GROUP="plugdev" # Nvidia SUBSYSTEM"usb", ATTR{idVendor}"0955", MODE="0666", GROUP="plugdev" # OTGV SUBSYSTEM"usb", ATTR{idVendor}"2257", MODE="0666", GROUP="plugdev" # Pantech SUBSYSTEM"usb", ATTR{idVendor}"10a9", MODE="0666", GROUP="plugdev" # Pegatron SUBSYSTEM"usb", ATTR{idVendor}"1d4d", MODE="0666", GROUP="plugdev" # Philips SUBSYSTEM"usb", ATTR{idVendor}"0471", MODE="0666", GROUP="plugdev" # PMC-Sierra SUBSYSTEM"usb", ATTR{idVendor}"04da", MODE="0666", GROUP="plugdev" # Qualcomm SUBSYSTEM"usb", ATTR{idVendor}"05c6", MODE="0666", GROUP="plugdev" # SK Telesys SUBSYSTEM"usb", ATTR{idVendor}"1f53", MODE="0666", GROUP="plugdev" # Samsung SUBSYSTEM"usb", ATTR{idVendor}"04e8", MODE="0666", GROUP="plugdev" # Sharp SUBSYSTEM"usb", ATTR{idVendor}"04dd", MODE="0666", GROUP="plugdev" # Sony SUBSYSTEM"usb", ATTR{idVendor}"054c", MODE="0666", GROUP="plugdev" # Sony Ericsson SUBSYSTEM"usb", ATTR{idVendor}"0fce", MODE="0666", GROUP="plugdev" # Sony Mobile Communications SUBSYSTEM"usb", ATTR{idVendor}"0fce", MODE="0666", GROUP="plugdev" # Teleepoch SUBSYSTEM"usb", ATTR{idVendor}"2340", MODE="0666", GROUP="plugdev" # Toshiba SUBSYSTEM"usb", ATTR{idVendor}"0930", MODE="0666", GROUP="plugdev" # Vivo SUBSYSTEM"usb", ATTR{idVendor}"9bb5", MODE="0666", GROUP="plugdev" # ZTE SUBSYSTEM"usb", ATTR{idVendor}"19d2", MODE="0666", GROUP="plugdev"

最后给配置文件执行权限。

sudo chmod a+x /etc/udev/rules.d/51-android.rules/

重启服务

重启udev

sudo service udev restart

重启adb

{SDK}/platform-tools/adb kill-server {SDK}/platform-tools/adb start-server

特殊情况

在设置上面的操作之后,还会有手机识别不了,或者识别成问号。则需要给 adb_usb.ini 添加相应的标识

gedit ~/.android/adb_usb.ini

比如我的vivo手机的 idVendor 为 9bb5
则在这个文件夹的最后一行添加上

0x9bb5

重启adb,重新连接手机usb即可。