Android Emulator Setup for mobile app testing/automation

This article explains how to setup Android emulator for testing your apps or performing Mobile Automation which you can create, duplicate, customise, and launch Android virtual devices.

Android Emulator

The Android Emulator simulates Android devices on your Laptop or Desktop so that you can test your application on a variety of devices and Android API levels without needing to have each physical device. The emulator provides almost all of the capabilities of a real Android device.

Testing an application or automating/executing scripts on emulator is a popular reason to use android emulator.
For example if you install WhatsApp on your emulator it is possible to do all the stuff which we use as WhatsApp on our day to day life.

Prerequisite to setup Android emulator

  • Install Java on system
  • Download Android studio on system depending on the OS platform you want to install (link to download)

Here I have installed on Mac

Setup Environment variables for Mac and Linux Users.

   – JAVA_HOME and ANDROID_HOME Variable

Once the environment variable is setup properly, we can check through the terminal as shown below

Two ways through which you can create your virtual device

  • Through Android studio tool.
  • By using commands in terminal/command prompt.

Lets first do it via Android studio tool

Now open the Android Studio Application , which will look something like below.

Now go to Tools —-> AVD Manager

Then click on Create Virtual Device and then you can choose your device configuration like which category or name you have to go as shown below.

So here lets go with phone category and Pixel 2 device —> click on next

Here we get the option to select the system image . We can select the image which we want to go with and depending on that we can download the API level.

Here we will go with API Level 32 with arm64-v8a image. Click on download and get the image — > click on Next

Refer below image

Here we get the default AVD name  and if needed we can update the AVD name also— >  click on Finish.

Now you can see that your virtual device is ready and in Action section you can see what all operation you can perform with this virtual device.

Now you can click on launch the emulator.

As you can see your emulator is launched.

You can even view the ​​Extended control settings/options and will  see the options you want on the ellipse menu item on the side of the emulator as shown below.

To check the virtual device that is been attached to the system, you can check using below command in cmd/terminal.

Now if you wish to install any application on the virtual device, you can do it by using below command.

adb -s emulator-5554 install -r {Path of the apk file on your system} where emulator-5554 is the device name.

To uninstall any application from virtual device , you can do it by using below command.

adb -s emulator-5554 uninstall {Package Name} where emulator-5554 is the device name.

2) By using commands in terminal/command prompt.

Note:- I am doing it on Mac

When you want to deal with command line tool, then we have to enable the command line through Android studio tool, which can be done as shown below.

Need to enable the checkbox of Android sdk command line Tools (latest)To do that → Open android studio tool —> Go to tools —-> Go to sdk manager —> Under Android studio — Click on SDK tools –
Click on the checkbox for Android sdk command line Tools (latest) and click on Apply.

So that you can have access to android sdk via commands.

To launch the installed emulator(Virtual device)

To check the list of virtual device available on your system.

cd ~/Library/Android/sdk/emulator
emulator -list-avds

To Launch the emulator , pass below command.

cd ~/Library/Android/sdk/emulator
emulator -avd Pixel_2_API_32

To Install the new virtual device through commands

Here is the github URL, where you can find the list of System-image api level.

Install system images and google APIs.

cd ~/Library/Android/sdk/cmdline-tools/latest/bin/
sdkmanager --install "system-images;android-32;google_apis;arm64-v8a"

Now we have to use AVD MANAGER to create emulator. But before that we can check the list of AVD available .

It can be done using below command

sh avdmanager list

As shown in above diagram we have to pass the Name(emulatorDeviceName) in below command

Below command is used to create the virtual devices.

sh avdmanager --verbose create avd --force --name "{emulatorDeviceName}" --device "{emulatorDeviceName}" --package "system-images;android-32;google_apis;arm64-v8a" --tag "google_apis" --abi "arm64-v8a"

Below is the snapshot where i have passed the emulatorDeviceName as pixel_2.

Now we can list the created avds on your system.

Now we can launch the created avd by using below command

cd ~/Library/Android/sdk/emulator
Emulator -avd pixel_2

How did you like the article?