今天測試程序,在虛擬機上運行出問題,於是用真機來測試,但是發現Ubuntu下不認。。調用./adb devices顯示如下。。結果無法用真機測試。
List of devices attached
emulator-5554 device
???????????? no permissions
google小米真機測試無果,google ubuntu Android 真機測試找到了線索(http://www.linuxidc.com/Linux/2011-04/34131.htm),可是又納悶了,他列出的設備代碼沒有小米手機,繼續google,無果,然後自己想辦法,先列出解決辦法:
首先手機不連電腦,運行一下命令lsusb,結果如下:
- alfredtofu@alfredtofu-laptop:~/myapp/eclipse/android-sdk-linux_x86/platform-tools$ lsusb
- Bus 002 Device 002: ID 8087:0024
- Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
- Bus 001 Device 009: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
- Bus 001 Device 004: ID 058f:b002 Alcor Micro Corp.
- Bus 001 Device 002: ID 8087:0024
- Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
手機連上電腦,再一次lsusb,結果如下:
- alfredtofu@alfredtofu-laptop:/$ lsusb
- Bus 002 Device 005: ID 18d1:9025
- Bus 002 Device 002: ID 8087:0024
- Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
- Bus 001 Device 009: ID 093a:2510 Pixart Imaging, Inc. Hama Optical Mouse
- Bus 001 Device 004: ID 058f:b002 Alcor Micro Corp.
- Bus 001 Device 002: ID 8087:0024
- Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
對比發現,多了Bus 002 Device 005: ID 18d1:9025,跟那個參考網站一對比,發現18d1正是設備ID,接下來問題就輕松解決了。
sudo vim /etc/udev/rules.d/51-android.rules
添加一下內容:
UBSYSTEM=="usb", SYSFS{idVendor}=="18d1", MODE="0666"
以上命令不同手機只需要改SYSFS{idVendor}=="18d1",中的18d1,至於這個代碼怎麼找,上面介紹了。
sudo chmod a+r /etc/udev/rules.d/51-android.rules
sudo /etc/init.d/udev restart
sudo ./adb kill-server
sudo ./adb devices
最終結果顯示如下:
- * daemon not running. starting it now on port 5037 *
- * daemon started successfully *
- List of devices attached
- emulator-5554 device
- 00c49bd2 device
於是可以用真機測試了。