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 over an Android Debug Bridge (ADB) connection.
Set up a device for development
Before you can start debugging on your device, there are a few things you must do:
- 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: Use
apt-get installto install the
android-tools-adbpackage. This gives you a community-maintained default set of
udevrules for all Android devices.
Make sure that you are in the plugdev group. If you see the following error message, adb did not find you in the plugdev group:
error: insufficient permissions for device: udev requires plugdev group membership
idto see what groups you are in. Use
sudo usermod -aG plugdev $LOGNAMEto add yourself to the plugdev group.
The following example shows how to install the Android adb tools package.
apt-get install android-tools-adb
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 your
android_sdk/platform-tools/directory. If connected, you'll see the device listed.
- Issue any adb command
-dflag to target your device.
Troubleshoot device connection with the Connection Assistant
The Connection Assistant provides step-by-step instructions to help you set up and use a device over the Android Debug Bridge (ADB) connection.
To start the assistant, choose Tools > Connection Assistant.
The Connection Assistant provides instructions, in-context controls, and a list of connected devices in a series of pages in the Assistant panel. Use the Next and Previous buttons at the bottom of the Assistant panel to work through the pages as needed:
- Connect your device over USB: The Connection Assistant begins by prompting you to connect your device over USB, and it provides a Rescan USB devices button with which you can start a new scan for connected devices.
- Enable USB debugging: The Connection Assistant then tells you how to enable USB debugging in the on-device developer options.
- Restart the ADB (Android Debug Bridge) server: Finally, if you still don't see your device on the list of available devices, you can use the Restart ADB server button on the last page of the Connection Assistant. Restarting the ADB server also causes ADB to scan for devices again. If you still don't see your device on the list of available devices, you can use the submit a bug report link to report the problem.
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.