When building an Android app, it's important that you always test your app on a real device before releasing it to users. This page describes how to set up your development environment and Android device for testing and debugging.
Set up a device for development
Before you can start debugging on your device, there are a few things you must do:
- In the
build.gradlefile, set thedebuggableproperty of the debug build type totrue:android { buildTypes { debug { debuggable true } } - On the device, open the Settings app, select Developer options, and then enable USB debugging.
- Set up your system to detect your device.
- Windows: Install a USB driver for Android Debug Bridge (adb). For an installation guide and links to OEM drivers, see the Install OEM USB Drivers document.
- Mac OS X: It just works. Skip this step.
- Ubuntu Linux: Add a
udevrules 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 theATTR{idVendor}property. For a list of vendor IDs, see USB vendor IDs.To set up device detection on Ubuntu Linux, do the following:
- Log in as root and create this file:
/etc/udev/rules.d/51-android.rules. - Use the following 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
MODEassignment specifies read/write permissions, andGROUPdefines which Unix group owns the device node. - Run the following command:
chmod a+r /etc/udev/rules.d/51-android.rules
- Log in as root and create this file:
Connect to your device
When you are set up and plugged in over USB, you can click Run
in Android Studio
to build and run your app on the device.
You can also use adb to issue commands, as follows:
- Verify that your device is connected by running the
adb devicescommand from yourandroid_sdk/platform-tools/directory. If connected, you'll see the device listed. - Issue any adb command
with the
-dflag to target your device.
RSA security key
When you connect a device running Android 4.2.2 (API level 17) or higher to your computer, the system shows a dialog asking whether to accept an RSA key that allows debugging through this computer. This security mechanism protects user devices because it ensures that USB debugging and other adb commands cannot be executed unless you're able to unlock the device and acknowledge the dialog.
USB vendor IDs
This table provides a reference to the vendor IDs needed in order to add USB
device support on Linux. The USB vendor ID is the value given to the
ATTR{idVendor} property in the rules file, as described
above.
| Company | USB vendor ID |
|---|---|
| Acer | 0502 |
| ASUS | 0b05 |
| Dell | 413c |
| Foxconn | 0489 |
| Fujitsu | 04c5 |
| Fujitsu Toshiba | 04c5 |
| Garmin-Asus | 091e |
18d1 |
|
| Haier | 201E |
| Hisense | 109b |
| HP | 03f0 |
| HTC | 0bb4 |
| Huawei | 12d1 |
| Intel | 8087 |
| K-Touch | 24e3 |
| KT Tech | 2116 |
| Kyocera | 0482 |
| Lenovo | 17ef |
| LG | 1004 |
| Motorola | 22b8 |
| MTK | 0e8d |
| NEC | 0409 |
| Nook | 2080 |
| Nvidia | 0955 |
| OTGV | 2257 |
| Pantech | 10a9 |
| Pegatron | 1d4d |
| Philips | 0471 |
| PMC-Sierra | 04da |
| Qualcomm | 05c6 |
| SK Telesys | 1f53 |
| Samsung | 04e8 |
| Sharp | 04dd |
| Sony | 054c |
| Sony Ericsson | 0fce |
| Sony Mobile Communications | 0fce |
| Teleepoch | 2340 |
| Toshiba | 0930 |
| ZTE | 19d2 |