如何在真实设备上调试(使用Eclipse/ADT)
我正在尝试弄清楚如何直接在我的手机(HTC Desire)上调试应用程序。
我已经安装了手机附带的 USB 驱动程序,并且使用“adb devices”时会列出手机。
如何配置 eclipse/ADT 在手机上启动而不是启动模拟器/虚拟设备?
I'm trying to figure out how to debug applications directly on my phone (HTC Desire).
I've installed the USB driver that came with the phone and the phone is listed when using "adb devices".
How do I configure eclipse/ADT to launch on the phone instead of launching the emulator/virtual device?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意:此答案是 本指南曾经存在于developer.android.com。其中部分内容是从原文中逐字引用的,没有注明所引用的特定部分的出处。
使用 Android 设备,您可以像在模拟器上一样开发和调试 Android 应用程序。
1.在
AndroidManifest.xml
中将您的应用程序声明为“可调试”。2.在手机上,导航至“设置”>“安全性和检查
未知来源
3.转到设置>开发者选项并选中
USB调试
请注意,如果
开发者选项
不可见,您将需要导航到“设置”>“开发者选项”。关于手机,然后多次点击版本号
,直到您收到手机已解锁的通知。4.设置您的系统以检测您的设备。
请按照以下适用于您的操作系统的说明进行操作:
Windows 用户
从 ADT SDK 管理器安装 Google USB 驱动程序
(支持:ADP1、ADP2、Verizon Droid、Nexus One、Nexus S)。
对于上面未列出的设备,为您的设备安装 OEM 驱动程序
Mac OS X
您的设备应该自动工作;转到下一步
Ubuntu Linux
添加一个
udev
规则文件,其中包含要用于开发的每种类型设备的 USB 配置。在规则文件中,每个设备制造商都由唯一的供应商 ID 进行标识,如 ATTR{idVendor} 属性所指定。如需供应商 ID 列表,单击此处。要在 Ubuntu Linux 上设置设备检测:/etc/udev/rules.d/51-android.rules
。SUBSYSTEM==“usb”,ATTR{idVendor}==“0bb4”,MODE =“0666”,GROUP =“plugdev”
在此示例中,供应商 ID 是 HTC 的。 MODE 指定指定读/写权限,GROUP 定义哪个 Unix 组拥有设备节点。
chmod a+r /etc/udev/rules.d/51-android.rules code>
注意:规则语法可能会因您的环境而略有不同。请参阅udev 文档 适合您的系统需要。有关规则语法的概述,请参阅本 udev 规则编写指南。
5.使用连接的设备运行项目。
使用 Eclipse/ADT: 像往常一样运行或调试您的应用程序。您将看到一个设备选择器对话框,其中列出了可用的模拟器和连接的设备。
使用 ADB: 发出带有 -d 标志的命令来定位目标您连接的设备。
Note: This answer is a heavily modified version of this guide that used to exist at developer.android.com. Portions of it are quoted verbatim from the original text without attribution for the specific parts that are quoted.
With an Android-powered device, you can develop and debug your Android applications just as you would on the emulator.
1. Declare your application as "debuggable" in
AndroidManifest.xml
.2. On your handset, navigate to Settings > Security and check
Unknown sources
3. Go to Settings > Developer Options and check
USB debugging
Note that if
Developer Options
is invisible you will need to navigate to Settings > About Phone and tap onBuild number
several times until you are notified that it has been unlocked.4. Set up your system to detect your device.
Follow the instructions below for your OS:
Windows Users
Install the Google USB Driver from the ADT SDK Manager
(Support for: ADP1, ADP2, Verizon Droid, Nexus One, Nexus S).
For devices not listed above, install an OEM driver for your device
Mac OS X
Your device should automatically work; Go to the next step
Ubuntu Linux
Add a
udev
rules file that contains a USB configuration for each type of device you want to use for development. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property. For a list of vendor IDs, click here. To set up device detection on Ubuntu Linux:/etc/udev/rules.d/51-android.rules
.SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.
chmod a+r /etc/udev/rules.d/51-android.rules
Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules.
5. Run the project with your connected device.
With Eclipse/ADT: run or debug your application as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s).
With ADB: issue commands with the -d flag to target your connected device.
有时您需要重置 ADB。
为此,在 Eclipse 中,转到:
Window>>
显示视图>>
安卓
(可能在“其他”选项中找到)>>
设备选项卡中的设备,单击向下箭头,然后选择重置 adb。
Sometimes you need to reset ADB.
To do that, in Eclipse, go:
Window>>
Show View >>
Android
(Might be found in the "Other" option)>>Devices
in the device Tab, click the down arrow, and choose reset adb.
在具有 Android 4.3 及更高版本的设备中,您应该按照以下步骤操作:
如何启用开发人员选项:
为了启用 USB 调试,您只需打开开发人员选项,向下滚动并勾选“USB 调试”框。就是这样。
in devices which has Android 4.3 and above you should follow these steps:
How to enable Developer Options:
In order to enable the USB Debugging you will simply need to open Developer Options, scroll down and tick the box that says ‘USB Debugging’. That’s it.