A GitHub Action for installing, configuring and running hardware-accelerated Android Emulators on macOS virtual machines.
The old ARM-based emulators were slow and are no longer supported by Google. The modern Intel Atom (x86 and x86_64) emulators can be fast, but rely on two forms of hardware acceleration to reach their peak potential: Graphics Acceleration, e.g. emulator -gpu host
and Virtual Machine(VM) Acceleration, e.g. emulator -accel on
. Note: GPU and VM Acceleration are two different and non-mutually exclusive forms of Hardware Acceleration.
This presents a challenge when running emulators on CI especially when running emulators within a docker container, because Nested Virtualization must be supported by the host VM which isn't the case for most cloud-based CI providers due to infrastructural limits. If you want to learn more about Emulators on CI, here's an article Yang wrote: Running Android Instrumented Tests on CI.
According to this documentation, "on Mac OS X v10.10 Yosemite and higher, the Android Emulator uses the built-in Hypervisor.Framework by default, and falls back to using Intel HAXM if Hypervisor.Framework fails to initialize." This means that HAXM is only needed to achieve VM Acceleration if this default Hypervisor is not available on macOS machines.
Note: Manually enabling and downloading HAXM is not recommended because it is redundant and not needed (see above), and for users of macOS 10.13 High Sierra and higher: macOS 10.13 disables installation of kernel extensions by default. Because Intel HAXM is a kernel extension, we would need to manually enable its installation on the base runner VM. Furthermore, manually trying to install HAXM on a Github Runner brings up a popup which further hinders tests from running.
This action helps automate and configure the process of setting up an emulator and running your tests by doing the following:
- Install / update the required Android SDK components including
build-tools
,platform-tools
,platform
(for the required API level),emulator
andsystem-images
(for the required API level). - Create a new instance of AVD with the provided configurations.
- Launch a new Emulator with the provided configurations.
- Wait until the Emulator is booted and ready for use.
- Run a custom script provided by user once the Emulator is up and running - e.g.
./gradlew connectedCheck
. - Kill the Emulator and finish the action.