Run Android Emulator out of the box with GitHub Actions!

Amr Salem
Innovies Club
Published in
4 min readMar 8, 2023
Android emulator & GitHub actions workflow

This blog post may be short, but it’s packed with useful information! While exploring GitHub host runners, I discovered that it already includes many helpful tools and SDKs (here), including the Android SDK. This means that with just a few simple commands, you can easily configure your own Android emulator and have it up and running in no time without relying on any other service.

Running an Android emulator in a pipeline offers numerous benefits, such as automating testing, improving efficiency by running in headless mode without a GUI, and saving costs by avoiding the need for dedicated physical devices or servers. Having an Android emulator at your disposal can be a game-changer for development and testing, so be sure to take advantage of this powerful way!

Get started 🚀

When running an emulator in headless mode, it’s crucial to ensure that your host supports virtualization and the necessary graphical acceleration. After researching the options, I have concluded that using a macOS host runner is the best solution. So, let’s break down our workflow and get it work.

Step 1:

I’ve set up a regular workflow with Git hooks that are triggered as needed. To make it more reusable, I’ve included an environment section that can be easily edited to adjust the emulator configuration as needed. Additionally, I’ve selected macOS as the host runner for this workflow.

Defining required emulator config

Step 2:

To facilitate access to essential commands, it’s important to set up the required path system variables. This includes adding paths for essential tools like sdkmanager, avdmanager, emulator, and others, as shown below.

Setting up system path variables

Step 3:

We can use the sdkmanager command to install the necessary SDK for our emulator (AVD). However, we need to remember to accept the license agreement before proceeding with the installation.

Installing SDk

Step 4:

We can create an AVD that meets our specific requirements by selecting the desired installed SDK, system image, Android API level (version), target, and architecture.

Creating the emulator

Step 5:

Launching the emulator is a crucial step in the process, but it can be tricky because there are multiple flags that must be passed depending on the host configuration. For example, if the host supports hardware acceleration, we need to include the “-accel on” flag, and vice versa for non-accelerated hosts. It’s also important to select the appropriate type of GPU and ensure that the Android operating system is fully booted and running before proceeding to the next stages.

To avoid any issues, I’ve created a shell script that checks the host’s hardware acceleration support across different operating systems. This script includes functions for launching the emulator with the required options based on the host setup, as well as checking the booting status of Android to ensure that it’s ready for the next steps in the pipeline.

A code snippet from shell script
Launching emulator function

I will provide a link to the complete script at the end of the blog 👇🏽.

Last but not least we will need to execute this shell script in order to get our emulator ready

Launching emulator

Trigger workflow 🎉

Everything appears to be working properly. The command was executed with the appropriate arguments, and our shell script continuously checked the status of the emulator until it was confirmed to be fully booted and running.

Checking emulator booting status
Emulator is fully booted and ready to use

Your Android emulator is now prepared to perform any task that needs to be executed.

Link

https://github.com/amrsa1/android-emulator-workflow

Thank you for stopping by and reading my blog, hope it was useful & stay tuned for the new upcoming interesting blogs…

--

--