Android 如何在真实设备上调试(使用 Eclipse/ADT)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2714400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug on a real device (using Eclipse/ADT)
提问by jgauffin
I'm trying to figure out how to debug applications directly on my phone (HTC Desire).
我想弄清楚如何直接在我的手机上调试应用程序(HTC Desire)。
I've installed the USB driver that came with the phone and the phone is listed when using "adb devices".
我已经安装了手机附带的 USB 驱动程序,并且在使用“adb 设备”时会列出手机。
How do I configure eclipse/ADT to launch on the phone instead of launching the emulator/virtual device?
如何配置 eclipse/ADT 在手机上启动而不是启动模拟器/虚拟设备?
回答by Sachin Gurnani
With an Android-powered device, you can develop and debug your Android applications just as you would on the emulator.
使用 Android 驱动的设备,您可以像在模拟器上一样开发和调试 Android 应用程序。
1. Declare your application as "debuggable" in AndroidManifest.xml
.
1. 在AndroidManifest.xml
.
<application
android:debuggable="true"
... >
...
</application>
2. On your handset, navigate to Settings > Security and check Unknown sources
2. 在您的手机上,导航至设置 > 安全并检查 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 on Build number
several times until you are notified that it has been unlocked.
3. 转到设置> 开发人员选项并检查USB debugging
请注意,如果Developer Options
不可见,您将需要导航到设置> 关于手机并点击Build number
几次,直到您收到已解锁的通知。
4. Set up your system to detect your device.
Follow the instructions below for your OS:
4. 设置您的系统以检测您的设备。
请按照以下适用于您的操作系统的说明进行操作:
Windows Users
视窗用户
Install the Google USB Driver from the ADT SDK Manager
(Support for: ADP1, ADP2, Verizon Droid, Nexus One, Nexus S).
从 ADT SDK 管理器安装 Google USB 驱动程序
(支持:ADP1、ADP2、Verizon Droid、Nexus One、Nexus S)。
For devices not listed above, install an OEM driver for your device
对于上面未列出的设备,请为您的设备安装 OEM 驱动程序
Mac OS X
Mac OS X
Your device should automatically work; Go to the next step
您的设备应该会自动工作;进入下一步
Ubuntu Linux
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:
添加一个udev
规则文件,其中包含要用于开发的每种类型的设备的 USB 配置。在规则文件中,每个设备制造商都由唯一的供应商 ID 标识,由 ATTR{idVendor} 属性指定。如需供应商 ID 列表,请单击此处。在 Ubuntu Linux 上设置设备检测:
- Log in as root and create this file:
/etc/udev/rules.d/51-android.rules
. - Use this format to add each vendor to the file:
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. - Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules
- 以 root 身份登录并创建此文件:
/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
Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentationfor your systemas needed. For an overview of rule syntax, see this guide to writing udev rules.
注意:规则语法可能因您的环境而略有不同。咨询的udev文档为您的系统的需要。有关规则语法的概述,请参阅本指南以编写 udev 规则。
5. Run the project with your connected device.
5. 使用连接的设备运行项目。
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).
使用 Eclipse/ADT:像往常一样运行或调试您的应用程序。您将看到一个设备选择器对话框,其中列出了可用的模拟器和连接的设备。
With ADB:issue commands with the -d flag to target your connected device.
使用 ADB:发出带有 -d 标志的命令以定位您连接的设备。
Still need help? Click here for the full guide.
还需要帮助吗?单击此处获取完整指南。
回答by Tom
Sometimes you need to reset ADB. To do that, in Eclipse, go:
有时您需要重置 ADB。为此,请在 Eclipse 中执行以下操作:
Window>> Show View >> Android (Might be found in the "Other" option)>>Devices
窗口>>显示视图>>Android(可能在“其他”选项中找到)>>设备
in the device Tab, click the down arrow, and choose reset adb.
在设备选项卡中,单击向下箭头,然后选择重置 adb。
回答by Sasa
in devices which has Android 4.3 and above you should follow these steps:
在具有 Android 4.3 及更高版本的设备中,您应该按照以下步骤操作:
How to enable Developer Options:
如何启用开发者选项:
Launch Settings menu.
Find the open the ‘About Device' menu.
Scroll down to ‘Build Number'.
Next, tap on the ‘build number' section seven times.
After the seventh tap you will be told that you are now a developer.
Go back to Settings menu and the Developer Options menu will now be displayed.
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.
为了启用 USB 调试,您只需打开开发人员选项,向下滚动并勾选“USB 调试”框。就是这样。