Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Run apps on a hardware device

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:

  1. On the device, open the Settings app, select Developer options, and then enable USB debugging.
  2. 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 install to install the android-tools-adb package. This gives you a community-maintained default set of udev rules 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

      Use id to see what groups you are in. Use sudo usermod -aG plugdev $LOGNAME to 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 devices command from your android_sdk/platform-tools/ directory. If connected, you'll see the device listed.
  • Issue any adb command with the -d flag 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.