Codepath

Running Apps on Your Device

Overview

When building an Android app, it's important that you always test your application on a real device in addition to emulators. This page describes how to set up your development environment and Android-powered device for testing and debugging on the device.

If you want an ideal SIM-unlocked phone to test on, then you might consider a Pixel phone.

Connect your Phone to Computer

Plug in your device to your computer with a USB cable. If you're developing on Windows, you might need to install this universal ADB USB driver or find your specific USB driver for your device.

Enable USB Debugging

The next step is to enable USB debugging so your phone can interact with your computer in a developer mode.

The following steps are needed:

  1. (Windows Only) Install this ADB Driver
  2. Plug-in your Android Device to Computer via USB
  3. Open the "Settings" App on the Device
  4. Scroll down to bottom to find "About phone" item
  5. Scroll down to bottom to find "Build number" section
  6. Tap on "Build Number" 7 times in quick succession
  7. You should see the message "You are now a developer!"
  8. Go back to main "Settings" page
  9. Scroll down bottom to find "Developer options" item
  10. Turn on "USB Debugging" switch and hit "OK"
  11. Unplug and re-plug the device
  12. Dialog appears "Allow USB Debugging?"
  13. Check "Always allow from this computer" and then hit "OK"

Watch this video tutorial for a visual guide to getting USB debugging enabled.

Running your App

Now, we can launch apps from Android Studio onto our device:

  1. Select one of your projects and click "Run" from the toolbar.
  2. In the "Choose Device" window that appears, select the "Choose a running device" radio button, select the device, and click OK.

Once Gradle finishes building, Android Studio should install the app on your connected device and start it.

Troubleshooting

Not seeing your device in the "Choose Device" window? Try the following:

  • Unplug your device from the USB port on the computer
  • Restart the device by powering off and back on
  • Verify that Settings => Developer options => USB Debugging is enabled
  • Quit and re-launch Android Studio
  • Force restart ADB from the "Android Device Monitor"
  • Plug your device back into the USB port on the computer
  • Unlock the device and press "OK" on any dialog displayed

Now the phone should work as a debugging device as expected!

Still Not Working?

If after plugging the device into the computer and you don't see any message about authorizing the device, then you may need to purchase another USB cable. Not all USB cables are enabled for data transfer. If there's a chance that your cable may be a charging only cable, you can purchase a USB-C cable for Pixel or the micro-USB cable for Nexus 6 and prior.

References

Fork me on GitHub