测试组的同事要在测试机上安装android studio,adb直接调试手机。

这下麻烦了,测试机实际是个lxc的虚机,需要把插在宿主机usb上的手机直接过给虚机。

说下做法: 首先在宿主机上执行lsusb,查出

[root@localhost]# lsusb
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub  
Bus 002 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 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub  
Bus 001 Device 014: ID 04e8:6860 Samsung Electronics Co., Ltd GT-I9100 Phone [Galaxy S II], GT-I9300 Phone [Galaxy S III], GT-P7500 [Galaxy Tab 10.1] , GT-I9500 [Galaxy S 4]  
Bus 001 Device 004: ID 0624:0248 Avocent Corp. Virtual Hub  
Bus 001 Device 005: ID 0624:0249 Avocent Corp. Virtual Keyboard/Mouse  

看GT-I9100那一行,ID 04e8:6860,VendorID:ProdID,说明Vendor=04e8 ProdID=6860,记下来。

并且记下来Bus 001,Device 014

一切设备皆文件,看看具体的文件吧:

ls -l /dev/bus/usb/001/014  
crw-rw-r--. 1 root root 189, 13 8月  29 10:31 /dev/bus/usb/001/014  

记下来这个189

然后去虚机的配置文件里 注意,我们的lxc虚机配置文件在/var/lib/docker/containers/bc2c9887fa72a59ab59f78b50677612608d40a2b73e8fd8fe0ffe25baa35edaa/config.lxc中,我们的rootfs是:

lxc.rootfs = /var/lib/docker/devicemapper/mnt/bc2c9887fa72a59ab59f78b50677612608d40a2b73e8fd8fe0ffe25baa35edaa/rootfs  

So,在config.lxc中增加2行,让usb设备直通虚机:

lxc.cgroup.devices.allow = c 189:* rwm  
lxc.mount.entry = /dev/bus/usb/001/014 /var/lib/docker/devicemapper/mnt/bc2c9887fa72a59ab59f78b50677612608d40a2b73e8fd8fe0ffe25baa35edaa/rootfs/dev/bus/usb/001/014 none bind,optional,create=file  

还没完: 重启虚机,进入容器,写个udev的rules,这个没测试是否有必要,因为其实udev服务根本没在容器里跑啊

vi /etc/udev/rules.d/51-android.rules  
SUBSYSTEMS=="usb", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="6860", MODE="0666", OWNER="root"  

继续,修改adb_usb.ini,把VendorID加进去

vi ~/.android/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.
0x04e8  

重启容器,adb被装在/opt/sdk/platform-tools/路径下,进去后执行:

/opt/sdk/platform-tools/adb start-server
/opt/sdk/platform-tools/adb devices
List of devices attached  
0376b638    unauthorized  

搞定。

comments powered by Disqus