Deploying Android Emulators on AWS EC2 [2/3] | Bare Metal instances and Hardware acceleration| Solutions for an organization
By: Uddeshya Singh
Tags: Android, Coding, Emulator, AWS, Cloud

Deploying Android Emulators on AWS EC2 [2/3] | Bare Metal instances and Hardware acceleration| Solutions for an organization Uddeshya Singh Follow Nov 29 · 5 min read

“You can invest more into android emulator hosting hardware (i.e. get bare metal instances) and reap the benefits later” will be the tagline I would start with because that really is the gist of this entire post (minus some really cool demonstration scripts I’ve got for you)

This post is a part of the series Deploying Android Emulators on AWS EC2.

Link to part 1 (ARM Architecture and Genymotion | Solutions for a Solo Developer)

You are at part 2.

Part 3 under draft editing.

Psst. This post with code embeddings is also available at dev.to!

Photo by Sven on Unsplash

Make your emulators Faster! 💥

Let’s pick up from where we left off and talk about making your emulators faster. In the normal t2 instances, as we know, there is a hypervisor layer on top of the instance hardware, hence abstracting the hardware layer from the emulator we want to run on it, and thus, we can’t use out good old hardware acceleration on top of it.

But what if, we take away the hypervisor layer? No, you can’t do it with a piece of code but you can definitely get it by investing some odd $4 per hour and get a machine that can run 40 emulators at once (tried and tested statistic).

How virtualization works in bare metal

That’s exactly how we pulled off a mass testing fleet with a variety of emulators all running simultaneously on a single machine. Since the hypervisor layer is stripped away, you get an emulator which is at least 10 times faster than the old armeabi 64bit models.

Isn’t it too costly? 💸

It’ll definitely take investment and on-demand instances are really costly by amazon (or really any cloud provider) as far as bare metal instances are concerned, but let’s really do the math.

some financial math :P

A high performing Genymotion PaaS setup would cost you: $ 0.7 per emulator

A bare metal instance at maximum load would cost you: $ 4.8/40 = $0.12 per emulator.

See? Simple maths. To get a profitable testing fleet, you really do need to splash the cash (hence the title, solutions for an organization)

Soo, which system image to pick? 🤔

I’ll recommend android-28’s google API version (that too x86 64-bit version) for further checking out the emulators. To get that system image, please run the following commands

$ sdkmanager "system-images;android-28;default;x86_64"

But why?

This system image has a fairly functioning Google Apps support.

Enabling root access isn’t much of a pain, a simple command (adb root) would do the trick.

You can play around with your emulator configurations and convert this AVD into whatever device you wish (I mean the identity, of course)

Enabling hardware acceleration in bare metal 🏃‍♂️

In any bare metal instance (let’s say m5.metal), we need to follow the old instructions which we did so far in the first post. Now follow the following commands to set up the KVM hypervisor in ubuntu 18.

$ sudo apt-get install qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker $ sudo usermod --append --groups kvm 'echo $USER'

$ echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \

| sudo tee /etc/udev/rules.d/99-kvm4all.rules

$ sudo udevadm control --reload-rules

$ sudo udevadm trigger --name-match=kvm

and this should be it. Now you can start any emulator by a simple command

$ emulator @emulatorName

and this will automatically utilize KVM hypervisor to boot your emulator (PS, if you are using the system image of android-28 and x86_64 architecture, you should see your emulator booting up within 20 seconds).

And this wraps us our parts on how to run fast emulators, how about, we try how to maybe install, run and uninstall apps in our emulator programmatically?