Cannot start Android emulator x86_64 in Docker container (in VM) Cannot start Android emulator x86_64 in Docker container (in VM) docker docker

Cannot start Android emulator x86_64 in Docker container (in VM)


We're using (or trying to use) this exact same scenario for automated testing.

The problem: The x86 and x86_64 emulator requires hardware acceleration. Hardware acceleration (VT-X or AMD-V) is not typically available inside a virtual environment (See: https://askubuntu.com/questions/328748/how-to-enable-nested-virtualization-in-ubuntu)

This means your best option is to use the ARM emulator, which is really slow. Running this inside Docker inside a VM will be even slower.

You can create the emulator like this:

# NOTE: Must use ARM, since x86 requires hardware acceleration, which is not available inside# a docker container running inside a virtual machineecho no | ${ANDROID_HOME}/tools/bin/avdmanager create avd \ --abi "armeabi-v7a" \ --device 'Nexus 4' \ --force \ --name arm_emulator \ --package "system-images;android-25;google_apis;armeabi-v7a" \ --sdcard 64M

You can then start the emulator like this:

${ANDROID_HOME}/emulator/emulator \ -avd arm_emulator \ -gpu swiftshader_indirect \ -memory 512 \ -no-audio \ -no-boot-anim \ -no-window &

Running this inside Docker on my local machine takes the emulator about 4-5 minutes to finish booting. When the Docker environment runs inside VirtualBox expect it to be even slower.

Even with this working, some commands like app installation through ADB fail because they take simply too long.

If possible, it may be a better option to start the emulator parallel to the virtual machine (e.g. on the same host) and then connect to the emulator through network.