Run your first app on the Android Emulator

1. Before you begin

In this codelab, you'll take the Greeting Card app you built in the Create your first Android app codelab , set up an Android Virtual Device (AVD), and see your code in action on an Android Emulator.

Prerequisites

  • Knowledge of how to set up, configure, and use apps, such as a word processor or a spreadsheet.

What you'll learn

  • How to create an AVD and run an app on the Android Emulator

What you'll build

  • A basic Android app from a template

What you'll need

  • A computer with Android Studio installed

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. In the video player, click the Full screen icon This symbol shows 4 corners on a square highlighted, to indicate full screen mode. 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. Run your app on the Android Emulator

In this task, you'll use the Device Manager to create an Android Virtual Device (AVD). An AVD is a software version, also called an emulator, of a mobile device that runs on your computer and mimics the configuration of a particular type of Android device. This could be any phone, tablet, TV, watch, or Android auto device. You'll use the AVD to run the Greeting Card app.

Create an AVD

To run an Android app in an emulator on your computer, you first create a virtual device.

  1. In Android Studio, select Tools > Device Manager.

5f936f312c2dd4bd.png

The Device Manager dialog opens. If you created a virtual device previously, it's listed in this dialog.

ce77f609ac05754c.png

  1. Click Create virtual device.

The Virtual Device Configuration dialog appears.

b79c82bf0a068686.png

The dialog shows a list of pre-configured devices, organized by category, from which you can choose. For each device, the table provides a column for its display size (in inches), screen resolution (in pixels), and pixel density (number of pixels per inch).

  1. Select Phone as the category.
  2. Select a phone, such as the Pixel 5, and then click Next.

This step opens another screen where you can choose the version of Android to run on your virtual device. This lets you test your app on different versions of Android.

87e81ed9e47fbc85.png

  1. If there's a download link next to S, click Download > Accept > Next > Finish. The presence of the download link indicates that the image isn't installed on your computer, in which case you must install the image before you can configure the virtual device. Expect the download to take some time to complete.

dca196de91530326.png

30286f0543d58317.png

  1. In the Recommended tab, choose S as the version of Android to run on the virtual device.

Android S is the latest version of Android at the time of writing, but you can choose any later stable version. For a list of stable versions, see Platform codenames, versions, API levels, and NDK releases.

This action opens another screen, where you can choose additional configuration details for your device.

c59d1e4d6874cd8c.png

  1. In the AVD Name field, enter a name for your AVD or use the default. Leave the rest of the fields unchanged.
  2. Click Finish.

This action returns to the Android Virtual Device Manager pane.

102842cfc3d3e05d.png

  1. Close the Device Manager dialog.

Run your app on the Android Emulator

  1. Select the virtual device that you created from the dropdown menu at the top of the Android Studio window.

8d0cf49cae5c873f.png

  1. Click 9dbf17c1342cd95.png.

The virtual device starts just like a physical device. Expect this to take a while—potentially several minutes—for the emulator to start for the first time. The virtual device should open beside the code editor.

c490ccdd97359779.png

When your app is ready, it opens on the virtual device.

7cacf7088add1845.png

Great job! Your virtual device is now up and running. The app launches, and you can see the background color and greeting text on the screen.

4. Conclusion

Congratulations! You ran your app on the Android Emulator!

Summary

  • To create an AVD, open your project, click Tools > Device Manager, and use the Device Manager to select a hardware device and system image.
  • To run your app on a virtual device, ensure that you created a device, select the device from the toolbar menu, and click 9dbf17c1342cd95.png.

Learn more