Skip to content

Replace default emulator by custom emulator

This is experimental functionality

  • Might be unstable
  • Use it at your own risk
  • The emulator performance is not guarantee because of the emulator snapshot feature fragility

If you want to use your own emulators instead of the default/dynamic emulators, you can substitute the default emulators with your own.

You can achieve this by creating a new Docker image based on the Emcee image and replacing the emulators.

An important part here is to prepare a custom emulator with the same settings as the default emulator.

Prepare custom emulator#

To create a custom emulator, you must execute a few console commands and then customize your emulator.

It is important to perform these operations in the same environment and under the same requirements that the default worker uses. The best approach is to carry out these operations in the worker container and then create the emulator archive.

Lets see how to create custom emulator. I will do all operations inside Emcee worker container.

Firstly, create emulator:

avdmanager create avd --name emulator_27 --package "system-images;android-27;google_apis;x86" --abi "google_apis/x86" --device pixel

Important notes:

  • The Emcee worker uses predefined emulator names, such as emulator_27 or emulator_31. Therefore, you must create an emulator with the same name. Use the same emulator name which you want to replace
  • Starting from SDK version 28, you must use x86_64 architecture instead of x86

Then launch and stop the emulator with exactly these commands:

emulator -avd emulator_27 -sdcard /sdcard.img -no-window -snapshot ci -no-boot-anim -no-audio -partition-size 2048 -gpu swangle_indirect -verbose
adb emu kill

After that launch emulator again and do your customize operations:

emulator -avd emulator_27 -sdcard /sdcard.img -no-window -snapshot ci -no-boot-anim -no-audio -partition-size 2048 -gpu swangle_indirect -verbose

Once the emulator is ready, you can install additional applications or make various customizations.

Important notes:

  • Launching it twice is important because it will allow to create the correct snapshot
  • It is okay to see log messages about a missing snapshot; we will create it later
  • For advanced users: Inside the emulator directory you can manipulate the emulator's config.ini file. For example, you can set up a custom device screen resolution and so on. However, do this before you save the snapshot and when emulator is stopped

Create emulator snapshot and then stop the emulator:

adb emu avd snapshot save ci
adb emu kill

Important notes:

  • Creating snapshot is important because it will give significant emulator start time improvement

Finally, you can create emulator archive. Find directory with emulators and zip emulator directory and emulator .ini file:

tar -czvf emulator_27.tar.gz emulator_27.avd emulator_27.ini

Now you have an archive with a custom emulator that you can use instead of the default Emcee emulator. Get and save this archive outside of the container.

Build Docker image with your own emulator#

When the archive with the custom emulator is ready, we can build a custom Docker image.

Here is an example of the Dockerfile where we replace the default emulator with Android SDK 27 by a custom emulator of the same SDK version.

Dockerfile
FROM avitotech/emcee-worker:latest

# remove default emulator
RUN rm -rf /root/.android/avd/emulator_27.avd
RUN rm /root/.android/avd/emulator_27.ini

# copy your custom emulator archive
COPY custom_emulator_27.tar.gz ./

# unzip custom emulator to emulators directory
RUN tar -xvf custom_emulator_27.tar.gz -C /root/.android/avd

Then create a new Docker image:

docker build -t custom_emcee_worker:0.0.1 .

After that, you can use this custom worker image instead of the Emcee worker image.