我是靠谱客的博主 可耐汉堡,最近开发中收集的这篇文章主要介绍Linux下面连接Android机器进行调试1. 总的步骤2. Step 1: 创建规则文件3. Step 2: 重启USB服务4. Step 4: adb命令验证配置是否生效 5. 参考资料 ,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

本文介绍在Linux环境下面,如何通过adb端口连接到手机设备,从而为接下来调试Android应用程序准备开发环境。


1. 总的步骤

主要包括如下几个步骤:

  • 以root用户为USB手机设备创建规则文件
  • 重启USB服务
  • adb devices检查设备是否可用


2. Step 1: 创建规则文件

这一步涉及以下几个要点:

1. 通过lsusb命令获取链接到计算机的手机设备的相关信息:vendor id, product id

2. 或者通过Android官方网站查阅手机设备的ID:http://developer.android.com/tools/device.html

3. 以root用户为手机创建一个规则文件


2.1 lsusb命令

lsusb查看的usb信息:

flying-bird@flyingbird:~$ lsusb
Bus 001 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 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 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 001 Device 003: ID 067b:2507 Prolific Technology, Inc. PL2507 Hi-speed USB to IDE bridge controller
Bus 001 Device 005: ID 058f:6377 Alcor Micro Corp. Multimedia Card Reader
Bus 003 Device 002: ID 046d:c062 Logitech, Inc. LS1 Laser Mouse, corded
Bus 004 Device 002: ID 046d:c52f Logitech, Inc. Wireless Mouse M305
Bus 001 Device 010: ID 19d2:0363 ZTE WCDMA Technologies MSM 
flying-bird@flyingbird:~$ 

以上输出结果的含义可以参考man lsusb:

lsusb(8)                                                Linux USB Utilities                                               lsusb(8)



NAME
       lsusb - list USB devices

SYNOPSIS
       lsusb [ options ]

DESCRIPTION
       lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.


OPTIONS
       -v, --verbose
              Tells  lsusb  to  be  verbose and display detailed information about the devices shown.  This includes configuration
              descriptors for the device's current speed.  Class descriptors will be shown, when available, for USB device classes
              including hub, audio, HID, communications, and chipcard.

       -s [[bus]:][devnum]
              Show only devices in specified bus and/or devnum.  Both ID's are given in decimal and may be omitted.

       -d [vendor]:[product]
              Show only devices with the specified vendor and product ID.  Both ID's are given in hexadecimal.

       -D device
              Do  not  scan  the  /dev/bus/usb  directory,  instead display only information about the device whose device file is
              given.  The device file should be something like /dev/bus/usb/001/001.  This option  displays  detailed  information
              like the v option; you must be root to do this.

       -t     Tells lsusb to dump the physical USB device hierarchy as a tree. This overrides the v option.

       -V, --version
              Print  version information on standard output, then exit successfully.


RETURN VALUE
       If the specified device is not found, a non-zero exit code is returned.


FILES
       /var/lib/usbutils/usb.ids
              A list of all known USB ID's (vendors, products, classes, subclasses and protocols).


SEE ALSO
       lspci(8), usbview(8).


AUTHOR
       Thomas Sailer, <sailer@ife.ee.ethz.ch>.



usbutils-005                                                6 May 2009                                                    lsusb(8)

现在只需要获取手机的vendor id,即手机厂商的ID号,上面lsusb显示的是ZTE 0x19d2.


2.2 直接从Android网站获取vendor id

网址是:http://developer.android.com/tools/device.html



2.3 编写规则文件

编写规则、示例,都在上面这个网站上详细描述了:


下面是作者的环境(root用户、并chmod):

root@flyingbird:/etc/udev/rules.d# cat ./51-android.rules 
SUBSYSTEMS=="usb", ATTR{idVendor}=="19d2", MODE="0666", OWNER="flying-bird"
root@flyingbird:/etc/udev/rules.d# ll
总用量 24
drwxr-xr-x 2 root root 4096  5月 27 20:39 ./
drwxr-xr-x 3 root root 4096  3月 31 21:02 ../
-rw-rw-rw- 1 root root   76  5月 27 20:39 51-android.rules
-rw-r--r-- 1 root root  812  5月 27 20:16 70-persistent-cd.rules
-rw-r--r-- 1 root root  484  3月 24 22:20 70-persistent-net.rules
-rw-r--r-- 1 root root 1157  4月  6  2012 README
root@flyingbird:/etc/udev/rules.d# 

3. Step 2: 重启USB服务

文件创建之后,重启usb服务:

root@flyingbird:/etc/udev/rules.d# /etc/init.d/udev restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service udev restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop udev ; start udev. The restart(8) utility is also available.
udev stop/waiting
udev start/running, process 15685
root@flyingbird:/etc/udev/rules.d#

4. Step 4: adb命令验证配置是否生效

然后adb devices验证是否起作用:

flying-bird@flyingbird:~/books/android/adt-bundle-linux-x86-20140321/sdk/platform-tools$ ./adb devices
List of devices attached 
????????????	no permissions

flying-bird@flyingbird:~/books/android/adt-bundle-linux-x86-20140321/sdk/platform-tools$ ./adb devices
List of devices attached 
ZTE_U807	device

flying-bird@flyingbird:

如果是前面的一串问号,说明配置有问题,如规则文件的语法错误;另外就是配置之后要restart。


之后,就可以运行在这个设备上了:



5. 参考资料

列出部分参考资料:

  • http://zwkufo.blog.163.com/blog/static/2588251201126113638144/
  • http://developer.android.com/tools/device.html

查阅资料时,总是一步步往官网靠近,最终以官网的为基准参考。


最后

以上就是可耐汉堡为你收集整理的Linux下面连接Android机器进行调试1. 总的步骤2. Step 1: 创建规则文件3. Step 2: 重启USB服务4. Step 4: adb命令验证配置是否生效 5. 参考资料 的全部内容,希望文章能够帮你解决Linux下面连接Android机器进行调试1. 总的步骤2. Step 1: 创建规则文件3. Step 2: 重启USB服务4. Step 4: adb命令验证配置是否生效 5. 参考资料 所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部