Coders' Guidebook

How to run an android app on a virtual device emulator

In this tutorial, we will explore how to set up a virtual device using Android Studio so you can test your app on your computer.

Setting up a virtual device

To set up a virtual device, press Tools > AVD Manager (AVD is short for Android Virtual Device).

set-up-a-virtual-device-emulator.png

Next, press 'Create Virtual Device...'.

create-virtual-device.png

You will see a list of possible virtual devices. Each device has a different screen size, resolution and pixel density. There is also a 'New Hardware Profile' button which allows you to customise the technical specifications of the device, but we will ignore that for now. Simply select the device you want to use then press Next. For this example, we will choose Pixel 3.

select-virtual-device.png

You will be prompted to select an API release. Simply select the most up-to-date version. At the time of writing, this is Q (API 29).

API-release.png

In the following screen, you will get the chance to verify the configuration. The default values are fine for our purposes so simply press Finish. The newly configured virtual device will now be listed in the Android Virtual Device Manager!

virtual-device-manager.png

You can now close the Android Virtual Device Manager window. In the action bar above the editor window, you will notice the virtual device is listed as one of the available devices. This means the virtual device is ready to be used.

virtual-device-emulator-available.png

Running your app on the virtual device

To run an app, simply press the green play button next to where the virtual device is listed.

run-virtual-device.png

Android Studio will do some work behind-the-scenes and load the app on the virtual device. In this example, the polaroid images app from a previous tutorial is being run. You can even interact with the app using your mouse and keyboard!

run-polaroid-images-app.png

When the app is running, you may notice some new buttons in the toolbar. The three buttons depicted below are useful when you need to restart the app after making some changes to the underlying code. Using them means you won't have to close and reopen the virtual device itself. There is also a red square 'stop' button. Pressing this button closes the app but not the virtual device. This is useful if you want to stop the app running in the background but not close the virtual device entirely.

virtual-device-toolbar.png

And there we have it! You can now run your app without the need for an actual phone or tablet. It is good practice to run your app regularly and check everything is working as you intended. We will look further at how to test our app (including what to do if it crashes) in future tutorials.

<<< Previous

Next >>>