在实际开发过程中,模拟器不一定能够满足我们测试要求,所以真机调试是许多 android developers 的选择,这里是根据android SDK 上关于真机调试实际可行的操作。
测试环境:Ubuntu10.10
版本:android 2.3.3
真机:HTC Desire G7
android SDK原文档如下:
Setting up a Device for Development
With an Android-powered device, you can develop and debug your Android applications just as you would on the emulator. Before you can start, there are just a few things to do:
Declare your application as "debuggable" in your Android Manifest.
In Eclipse, you can do this from the Application tab when viewing the Manifest (on the right side, set Debuggable to true). Otherwise, in the AndroidManifest.xml file, add android:debuggable="true" to the
(1) Turn on "USB Debugging" on your device.
On the device, go to the home screen, press MENU, select Applications > Development, then enable USB debugging.
(2) Setup your system to detect your device.
If you're developing on Windows, you need to install a USB driver for adb. See the Windows USB Driver documentation.
If you're developing on Mac OS X, it just works. Skip this step.
If you're developing on Ubuntu Linux, you need to add a rules file that contains a USB configuration for each type of device you want to use for development. Each device manufacturer uses a different vendor ID. The example rules files below show how to add an entry for a single vendor ID (the HTC vendor ID). In order to support more devices, you will need additional lines of the same format that provide a different value for the SYSFS{idVendor} property. For other IDs, see the table of USB Vendor IDs, below.
(3)Log in as root and create this file: /etc/udev/rules.d/51-android.rules.
For Gusty/Hardy, edit the file to read:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
For Dapper, edit the file to read:
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"
(4)Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
You can verify that your device is connected by executing adb devices from your SDK tools/ directory. If connected, you'll see the device name listed as a "device."
If using Eclipse, run or debug as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s). Select the device upon which you want to install and run the application.
If using the Android Debug Bridge (adb), you can issue commands with the -d flag to target your connected device.
那我们的实际需要在执行的操作是:
打开终端 ,首先,以 root 权限在 /etc/udev/rules.d/ 的目录下创建 .rules 配置文件。
命令:sudo touch 51-Android.rules
接下来,我么需要编辑刚刚创建的.rules文件
命令:gedit 51-Android.rules
在其中输入:SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
然后,赋予权限
命令:chmod a+r 51-Android.rules
重启udev
命令:sudo /etc/init.d/udev restart
到了这里基本就配置好了,我们可以拔掉手机usb 线后重新连接,在/android/sdk/tools/目录下执行 命令:adb devices
若列出设备即可开始调试
List of devices attached
HT069PL00679 device
也有可能还会遇到的问题就是
List of devices attached
?????? no permission
当然这也只是权限的问题,通过logcat查看系统日志,会发现给出了如下的提示:
will be removed in a future udev version, please use ATTR{}= to match the event device, or ATTRS{}= to match a parent device, in /etc/udev/rules.d/50-Android
问题明了,重新编辑.rules文件,将SYSFS 替换为 ATTR 即可
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666"
重复接下来操作。
第一篇博客,以真机调试为切入,将实际工作中遇到的个人认为比较重要的细节,已博文形式记下,供各位参考。文笔粗陋,望各位指正。