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:
- (Windows Only) Install this ADB Driver
- Plug-in your Android Device to Computer via USB
- Open the "Settings" App on the Device
- Scroll down to bottom to find "About phone" item
- Scroll down to bottom to find "Build number" section
- Tap on "Build Number" 7 times in quick succession
- You should see the message "You are now a developer!"
- Go back to main "Settings" page
- Scroll down bottom to find "Developer options" item
- Turn on "USB Debugging" switch and hit "OK"
- Unplug and re-plug the device
- Dialog appears "Allow USB Debugging?"
- 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:
- Select one of your projects and click "Run" from the toolbar.
- 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.
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.