What You Can Do if the Android Studio Emulator Doesn’t Behave
The emulator that comes with Android Studio swallows up lots of resources on your development computer. If you’re like a lot of developers and don’t always have the latest, most powerful hardware, you may have trouble running apps in the emulator.
If, after five minutes or so, you don’t see Android’s home screen and you don’t see your app running, here are several things you can try:
- Lather, rinse, repeat.
Close the emulator and launch your application again. Sometimes, the second or third time’s a charm. On rare occasions, a fourth attempt succeeds.
- If you have access to a computer with more RAM, try running your app on it.
- Try a different AVD.
AVD with an x86 system image is better than an AVD with an armeabi image. (Fortunately, when a dialog box lets you choose between x86 and armeabi, you don’t have to know what x86 or armeabi means.)
AVDs with lower resolution and screen density consume fewer resources on your development computer. So, if the AVD that you’re running drags you down, make yourself a lower-resolution AVD (one that satisfies your app’s minimum SDK requirement). Then, when you run an app, Android Studio prompts you with the Select Deployment Target dialog box. Pick the lower-resolution AVD from the dialog box’s list, and you’ll be on your way.
If you’ve tried these tricks and you’re still having trouble, you might try abandoning the emulator that comes with Android Studio.
Running third-party emulators
Android’s standard emulator and AVDs (the software that you get when you install Android Studio) don’t run flawlessly on every computer. If you don’t have at least 16GB of RAM, the emulator’s start-up may be very slow. Even after start-up, the emulator’s response may be painfully sluggish. If you don’t like the standard emulator, you can try one of the third-party emulators.
- At Genymotion.com, you can download an alternative to the standard Android emulator.
This alternative is available for Windows, Macintosh, and some Linux systems. Genymotion’s product is free for personal use, but costs $135 per year for commercial use.
- At Android’s Developer site, you can download Visual Studio Emulator for Android.
This alternative is free to use, but it runs only on Windows computers.
If you have trouble running the emulator that comes with Android Studio, these third-party emulators are definitely worth considering.
Testing apps on a physical device
You can bypass emulators and test your apps on a real phone, a tablet device, or even an Android-enabled coffee pot. To do so, you have to prepare the device, prepare your development computer, and then hook together the two.
Your device’s Android version must be at least as high as your project’s minimum SDK version.
To test your app on a physical device, follow these steps:
- On your Android device, find the USB Debugging option:
- If your Android device runs version 3.2 or older, choose Settings → Applications → Development.
- If your Android device runs version 4.0, 4.0.3, or 4.1, choose Settings → Developer Options.
- If your Android device runs version 4.2 or higher, choose Settings → About. In the About list, tap the Build Number item seven times. (Yes, seven times.) Then press the Back button to return to the Settings list. In the Settings list, tap Developer Options.Now your Android device displays the Development list (also known as the Developer Options list).
- In the Development (or Developer Options) list, turn on USB debugging. Here’s an example of what a device displays when you mess with this setting:
USB debugging is intended for development purposes.
Use it to copy data between your computer and your device,
install apps on your device without notification, and read log data.
The stewards of Android will warn you that the USB Debugging option can expose the device to malware.
You can keep USB debugging on all the time. But if you’re nervous about security, turn off USB debugging whenever you’re not using the device to develop apps.
- For Windows users only:) Visit Android’s Developer site to download your Android device’s Windows USB driver. Install the driver on your Windows development computer.
- When you start running an app, make sure that your development computer displays the Select Deployment Target dialog box.
If you don’t see the Select Deployment Target dialog box, from Android Studio’s main menu choose Run → Edit Configurations. On the left side of the resulting dialog box, select Android Application → App. In the main body of the dialog box, under Deployment Target Options, choose the Open Select Deployment Target Dialog option and deselect the Use Same Device for Future Launches check box. Seal the deal by clicking OK.
- Make sure that your Android device’s screen is illuminated.
This particular step might not be necessary.
While you follow the next step, keep an eye on your Android device’s screen.
- With a USB cable, connect the device to the development computer.
Not all USB cables are created equal. Some cables have wires and metal in places where other cables (with compatible fittings) have nothing except plastic. Try to use whatever USB cable came with your Android device. If you can’t find the cable that came with your device or you don’t know which cable came with your device, try more than one cable. When you find a cable that works, label that able cable. (If the cable always works, label it Stable Able Cable.)
When you plug in the cable, you see a pop-up dialog box on the Android device’s screen. The pop-up asks: Allow USB Debugging?
- In response to the Allow USB Debugging? question, click the screen’s OK button.
If you’re not looking for it, you can miss the Allow USB Debugging? pop-up dialog box. Be sure to look for this pop-up when you plug in your device. If you definitely don’t see the pop-up, you might be okay anyway. But if the message appears and you don’t respond to it, you definitely won’t be okay.
- In Android Studio, run your project.
Android Studio offers you the Select Deployment Target dialog box. Select your connected device, and (lickety-split) your app starts running on your Android device.