How to run an app in an Android Emulator - Main image

Intermediate

How to run an app in an Android Emulator

Using Android studio we will take a look at how we can test our Android app by running it in an Android emulator.

 

Miha Cirman - CodeBrainer
Miha Cirman
4 min read

While building apps we want to run them frequently, to check the design or to test if everything is working perfectly. We will show you how to run an app in an Android emulator. We will start without a virtual device to show you, how you can create it.

We have already created our new app, if you want to know how we do it check our video and article about it as well. 

We are using an empty app to remove any possibilities of an error. We only have an empty activity ready for us, named MainActivity.

Learn how you can start creating apps with Flutter.

Learn more

You can run the app with an Android Emulator in two ways:

  1. Using the menu Run and then the Run App option
    Run app in Android emulator
  2. Using the Play icon from the toolbar
    Run Icon

 

This is how the “Select Deployment Target” window will look like if you do not have any virtual devices ready to run yet. We need to create it first, click “Create New Virtual Device” button to add a new one.
Create new Virtual Device

In window “Select Hardware” you will choose a virtual device we will create.
Select Harware

We recommend that you choose a Nexus 5X or Nexus 5, since it is easier to place on you desktop due to the window size.
Nexus 5X

Choose it and click Next

Next you will see a recommended selection of an Android versions.
System image

You can see the name and the API Level in the list. This choice is just like picking your new phone. Depending on the version you choose it will have different features available. You also have a button for recommended, x86 Images and Other Images. Most of the time you will want to choose x86 Images and we will too. So click that button.

Learn how you can start creating apps with Flutter.

Learn more

In the list you will also see the column target (this is actual Android version, that will be on your Android emulator) and in brackets Google Play, Google APIs or without. We recommend using Google APIs
Select Android Version

Even though Andorid P is already available we would recommend to choose an older version, to check if everything is working for users with older versions. But you can also add a new virtual device and check it on newer versions as well. You can have more than one virtual device.
So we will choose Marshmallow (you can see, that there is no “Download” link beside it, this means that the SDK (Software Development Kit) is already downloaded). If you have a Download button beside it, click it.
Marshmallow

Choose it and click Next

The last window lets us choose details about our new virtual device.
AVD verify configuration

That is it, we just need to finish and we will have a new virtual device available for us to use. We need to wait for Android Studio to finish.

Now we can choose a virtual device when running our app.
Select deployment target

When we click OK, the Android emulator will load and it will have all the features of a normal Android device. The app will run automatically for us, but it can take some time. So check if Android Studio is still working, building an APK and installing it on your Android emulator. Status is shown on the bottom of the Android Studio screen.
Restart application

 

Error if Virtualization is not turned ON

You might get an error because your Virtualization is not turned ON in your BIOS. To turn it ON just google “How to turn on virtualization in BIOS” + add your computer model or motherboard model (as your knowledge in coding grows so will your skills with google search :)).

 

You can also run on your device

If you are not ready to change the settings in your BIOS or you would like to see how this small program looks on your phone, click this link to see how you can connect your phone to Android Studio https://developer.android.com/studio/run/device