What is an Android Emulator? How to Start and use it?

Mohammad Faisal Khatri
9 min readDec 3, 2022

--

Mobile Automation is the buzzword everywhere. As the mobile businesses are flourishing, more and more need arises to deliver quality application to the end users who can make the most out of it.

When it comes to quality, Testing directly comes in to the picture as without testing, you cannot make out whether the application is working as expected. To test the application, Automated testing is carried out in almost every project that is developing the mobile application, as it helps in delivering the application with quality in the fastest way possible to the market.

Automated testing also helps in bringing down the manual efforts of testing the application by running the regression test cycles quickly. That said, it helps with faster feedback on the builds as well. So, anything in the code that is broken can be fixed quickly.

Checkout this blog where I have provided some useful tips and tricks for Mobile Testing.

Now, as we are talking about Mobile application and Automated testing, one of the useful resource around this is using Emulators for testing the mobile application, as it is always difficult to get latest mobile device for testing the application.

What is an Emulator?

An Emulator is a software program that emulates or mimics another computer or software program. For example, using an emulator you can run a virtual device same which will behave in the same way a mobile phone does. So, using Android Studio, we can create a virtual mobile device say for example, Google Pixel 5 and use it to install and test our mobile application. This helps in testing the application without having to get the real device.

How to Start Android Emulator?

Installing Android Studio

The first step we need to do is download and install Android Studio. It can be downloaded from here

Download Android studio

Once the Android Studio executable file is downloaded successfully, you can install it by double clicking on the exe file. Checkout this user guide to install Android Studio on different OS’s like Windows, Mac, Linux etc.

Setting ANDROID_HOME Path in Windows

Once the installation is complete, we need to set the ANDROID_HOME and Path variable for SDK Tools.

Open the Edit System Variable Setting window by pressing the Windows key and type “env” in the search box. Click on the Edit the System environment variables option displayed in search.

It will open a System Properties windows dialog box as seen in the screenshot below:

System Properties dialog box

Click on the “Environment Variables..” button to open the Environment Variables dialog box.

In the System Variables section, click on “New…” button and add the ANDROID_HOME variable and provide the path to Android SDK in it.

Once this is done, we need to edit the “Path” variable and add the paths to Android platform tools, tools, emulator and bin folders as shown in the screenshot below:

  1. Platform tools Path: %ANDROID_HOME%\platform-tools
  2. Emulator Path: %ANDROID_HOME%\emulator
  3. Tools Path: %ANDROID_HOME%\tools
  4. Bin folder Path: %ANDROID_HOME%\bin

Click on OK button to confirm the changes made to the Environment Variables.

Next, open the command prompt and type the command “adb” and press Enter Key.

If everything is set successfully, you should be able to see the adb version along with Android commands as a result.

Setting ANDROID_HOME Path in Mac

For setting the ANDROID_HOME path in macOS. The following steps needs to be followed —

  1. Open Terminal and run the following command -
nano ~/.zshrc

2. Update the following lines in the ~/.zshrc file, press Ctrl + X and press Y to save the changes.

export ANDROID_HOME=/Users/<username of your mac>/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH

3. Source the ~/.zhrc file using the following command -

source ~/.zshrc

To check that the ANDROID_HOME path is set correctly, run the echo command in the terminal -

echo $ANDROID_HOME

Congratulations! We are now all set to start working with Android Emulators!

How to Start Android Emulator?

Following steps needs to be performed to start Android Emulator:

  1. Start Android Studio

2. Click on three dots displayed next to the Get from VCS button, it will open a menu as displayed in the screenshot below, click on Virtual Device Manager menu:

Virtual Device Manager

We can create multiple emulators as per our requirement using this window. For creating a virtual device click on Create Device button and follow the steps as directed by the Virtual Device Manager.

Click on Create Device button will open a new window and prompt you to select the hardware for the emulator:

Using this window, we can create different virtual devices with different screen sizes and resolutions. Also, there is an option to select the device having Play Store installed in it.

There is an option to select the Category like Phone, Tablet, Wearable device, TV or Automotive. Here, since we are focusing on mobile testing, we would be selecting the Category as Phone.

Lets Select the following options:

  1. Category: Phone
  2. Name: Pixel XL
  3. Size: 5.5"
  4. Resolution: 1440x2560
  5. Density: 560dpi

Click on Next button to further configure the virtual device

Selecting System Image on Windows

In this window, we will be selecting System Image or the OS version we would want to install in our phone. Here, we will be selecting Android 11.0, The Release name of this version is R , API Level version is 30.

There are other versions as well like S, which is Android 12.0 and you see a down arrow mark beside it, which says that this version will need to be downloaded into our system before we could use it.

Also, Other images are also available in the window which are lower versions of Android and that too can be used for creating virtual device.

System Image — Lower versions — Windows

I had already downloaded the versions R, Q and Pie in my system, hence we will select the latest of the them and use R.

Click Next button once you select the Release Version.

Selecting System Image on Mac

While selecting system image when you are on Mac make sure to select the image having arm64 architecture. We will be selecting the image with API Level 33 — Android 13.0 here.

Android Virtual Device(AVD) verify configuration screen

Clicking on the Next button will take us to the final configuration screen where we need to provide the AVD Name and if needed, update/modify the Hardware and System image before creating virtual device.

Options are also available to set the Startup Orientation — this is the orientation that the device will set on start up, i.e. Portrait or Landscape. We will select Portrait here, which is the default value.

AVD Configuration

Advanced Settings option is also available which can be expanded by clicking on the Show Advanced Settings button.

Using Advanced Settings we can configure the following:

  1. Front as well as Back Camera
  2. Network Latency and Speed

3. Graphics Rendering

4. Memory and Storage

5. Device Frame

For now, we will be keeping the Advanced Settings value as default as provided by Android Studio and lets click on Finish button to create the virtual device.

The virtual device named Pixel XL API 30 is created successfully as per the configuration we had set and can be seen in the Device Manager screen.

Let’s now start the emulator by click on the Play icon displayed under the Actions column.

Android Emulator — Pixel XL

Emulator has been started successfully and we can see the Pixel XL Virtual phone on our screen. This behaves likes the mobile device but its virtual and we can install/uninstall applications and play around with this virtual device.

Installing an APK file on the Emulator

Now, lets learn to install an apk file to this virtual device and see how the application behaves.

It is pretty simple, we just need to drag and drop the APK file from our desktop machine to this device and the virtual device will take care of the further installation process.

For this demo, we will be using the SauceLabs APK file which can be downloaded from here

As soon as we drag and drop the file, the emulator starts installing it. Once installation is complete, we can see the application in Installed Apps in the device.

Lets tap on the app and open the application.

We can see the application opening successfully on the emulator. Now, we can play around it. Similarly, we can also install our application under test and perform manual exploratory testing of the application using the Android Emulator.

Starting the emulator using Command Line Interface

We just saw how to start the Emulator using Android Studio. Now, let’s discuss about how to list the already created AVDs and Start the AVD using Command Prompt:

Listing the available AVDs:

emulator -list-avds — This will list all the already created AVDs in your machine.

We just created the AVD Pixel_XL_API_30 and when we run the emulator -list-avdscommand, it prints the AVD name in the output.

Starting the Emulator using CLI

emulator @<AVD_NAME>- This command will start the already existing AVD in your machine. Let’s start the emulator, we already created by running the command emulator @PIXEL_XL_API_30

Congratulation! The AVD started successfully and we can now play with it.

To shut the AVD from Command line gracefully press Ctrl + C.

Using Emulators for running Automated Tests

Emulators can also be used for running Automated tests as it provides us with multiple varieties of System images and different hardware profiles. We can create virtual mobile device as per our need, connect it to the automation scripts and run the automated tests.

Check out this blog where I have explained about starting the Appium server programmatically and launching the application under test on the emulator.

Conclusion

With the increasing demand for mobile applications, businesses need quality applications to be delivered to the end users. For testing mobile applications Emulators can help us by mimicking different Android devices and using them for testing mobile applications. It also provides different system images so we can use them as per our requirement to test the mobile application in lower version or latest versions. Also, it has different Category like Phone, Tablet, Wearable devices, TV, etc, which can be created virtually and used for testing. Emulators can also be used to run automated mobile tests.

Try your hands now on the Android Virtual devices and explore the all new world and test your mobile applications like a pro.

Happy Testing!

Freelance Work / Paid Trainings/Mentoring

Contact me for Paid trainings/Mentoring related to Test Automation and Software Testing, ping me using any of the social media site listed on LinkTree or email me @mohammadfaisalkhatri@gmail.com.

References

https://developer.android.com/studio/run/emulator-commandline

--

--

Mohammad Faisal Khatri

QA with 14+ years of experience in automation as well as manual testing. Freelancer, blogger and open source contributor.