How to connect your Android device

1. Before you begin

In this codelab, you learn how to connect your app in Android Studio to your physical Android device. You can either connect your device with a cable or with Wi-Fi. This codelab will cover both cases. Note that Android Studio gets updated and sometimes the UI changes so it is okay if your Android Studio looks a little different than what is shown on the screen.

Prerequisites

  • Basic knowledge of how to use Android Studio.
  • Ability to open and adjust settings on your Android device.

What you'll learn

  • How to enable your Android device to run apps from Android Studio.
  • How to connect and run an app in Android Studio on a physical Android device.

What you'll need

  • Android Studio downloaded and installed on your computer.
  • An app project set up in Android Studio.
  • An Android device, such as a phone or tablet running Lollipop or later.
  • (Optional) A USB cable to connect your Android device to your computer through their USB ports.

2. Watch the code-along video (Optional)

If you'd like to watch one of the course instructors complete the codelab, play the below video.

It's recommended to expand the video to full screen (with this icon This symbol shows 4 corners on a square highlighted, to indicate full screen mode. in the lower right corner of the video) so you can see Android Studio and the code more clearly.

This step is optional. You can also skip the video and start the codelab instructions right away.

3. Enable USB debugging

To let Android Studio communicate with your Android device, you must enable USB debugging in the Developer options settings of the device.

To show developer options and enable USB debugging:

  1. On your Android device, tap Settings > About phone.
  2. Tap Build number seven times.
  3. If prompted, enter your device password or pin. You know you succeeded when you see a You are now a developer! message.

fc5ee039dab58109.png

  1. Return to Settings and then tap System > Developer options.
  2. If you don't see Developer options, tap Advanced options.

This image shows the System page with Developer options boxed in red.

  1. Tap Developer options and then tap the USB debugging toggle to turn it on.

This image shows the Options page with USB debugging toggled on and boxed in red.

Install the Google USB Driver (Windows only)

If you installed Android Studio on Windows, you must install a USB device driver before you can run your app on a physical device.

  1. In Android Studio, click Tools > SDK Manager. The Preferences > Appearance & Behavior > System Settings > Android SDK dialog opens.
  2. Click the SDK Tools tab.
  3. Select Google USB Driver and then click OK.

3a5910f5cf07382f.png

When done, the driver files are downloaded into the android_sdk\extras\google\usb_driver directory. Now you can connect and run your app from Android Studio.

4. Run your app on the Android device with a cable

There are two ways to connect your device to Android Studio, through a cable or through Wi-Fi. You can choose whichever you like more.

To run your app from Android Studio on your Android device:

  1. Connect your Android device to your computer with a USB cable. A dialog should appear on your device, which asks you to allow USB debugging.

ade9c70a580ffbee.png

  1. Select the Always allow from this computer checkbox and then tap OK.
  2. In Android Studio on your computer, make sure your device is selected in the dropdown. Click This is the Android Studio Run icon.

d180c23e4e73e5d2.png

  1. Select your device and then click OK. Android Studio installs the app on your device and runs it.
  1. If your device runs an Android platform that isn't installed in Android Studio and you see a message that asks whether you want to install the needed platform, click Install > Continue > Finish. Android Studio installs the app on your device and runs it.

5. Run your app on the Android device with Wi-Fi

If you don't have a cable, you can also connect and run your app on your device with Wi-Fi.

Get started

  1. Ensure that your computer and device are connected to the same wireless network.
  2. Ensure that your device runs Android 11 or higher. For more information, see Check & update your Android version.
  3. Ensure that your computer has the latest version of Android Studio. To download it, see Android Studio.
  4. Ensure that your computer has the latest version of the SDK Platform Tools.

Pair your device

  1. In Android Studio, select Pair Devices Using Wi-Fi from the run configurations drop-down menu.

This image shows a drop-down menu with Pair Devices Using Wi-Fi selected.

The Pair devices over Wi-Fi dialog opens.

4715f95a3d2be595.png

  1. Go to Developer options, scroll down to the Debugging section and turn on Wireless debugging.

1a7a69258cf2a132.png

  1. On the Allow wireless debugging on this network? popup, select Allow.

5da578d4c08b3c3b.png

  1. If you want to pair your device with a QR code, select Pair device with QR code and then scan the QR code on your computer. Alternatively, if you want to pair your device with a pairing code, select Pair device with pairing code and then enter the 6-digit code.
  2. Click run and you can deploy your app to your device.

6. Troubleshooting

  • If your computer runs Linux or Windows, and you can't run your app on a physical Android device, see Run apps on a hardware device for additional steps.
  • If your computer runs Windows and the emulator installation doesn't work, see Install OEM USB Drivers for the appropriate USB driver for your device.
  • If Android Studio doesn't recognize your device: try unplugging the USB cable and plug it back in or restarting Android Studio.
  • If your computer still doesn't find the device or declares it unauthorized: disconnect the USB cable. On the device, tap Settings > Developer options > Revoke USB debugging authorizations. Reconnect the device to your computer. When prompted, grant authorizations.

7. Conclusion

You learned how to run an app in Android Studio on your physical Android device!

Summary

  • You can run Android apps on your physical device through a cord or through Wi-Fi.
  • Windows users need to install a USB debugging driver to run apps on their physical device.
  • If you are running your app through Wi-Fi, you can pair using a QR code or a 6 digit code.

Learn more