mingchen/docker-android-build-box

x86 or x86_64 Android emulator cannot run on the Docker machine

ozmium opened this issue · 1 comments

You can create an x86_64 Android emulator in this Docker image. But it cannot run at all. Example, using guidelines from Sam Edwards, with a custom bash script:

#!/bin/bash

# Create an x86 emulator from scratch, with a 100 MB SD card storage space. See
# https://handstandsam.com/2016/04/23/using-the-android-emulator-for-continuous-integration/
# You have to echo "no" because it will ask if you want to use a custom hardware profile,
# and you don't.
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd \
    -n Android_7.1_API_25 \
    -k "system-images;android-25;google_apis;x86_64" \
    -c 100M \
    --abi google_apis/x86_64 \
    --force

If you try to launch this emulator, it will not work:

# Verify that an AVD image is available
emulator -list-avds # This will output: Android_7.1_API_25

# Launch the emulator now
$ANDROID_HOME/tools/emulator -avd Android_7.1_API_25 &

It will just display this error:

ERROR: 32-bit Linux Android emulator binaries are DEPRECATED, to use them
       you will have to do at least one of the following:
       - Use the '-force-32bit' option when invoking 'emulator'.
       - Set ANDROID_EMULATOR_FORCE_32BIT to 'true' in your environment.
       Either one will allow you to use the 32-bit binaries, but please be
       aware that these will disappear in a future Android SDK release.
       Consider moving to a 64-bit Linux system before that happens.

Even if you try to use the 32-bit flags, as per these instructions, it will still not work:

export ANDROID_EMULATOR_FORCE_32BIT=true
# Launch the emulator now
$ANDROID_HOME/tools/emulator -avd Android_7.1_API_25 -force-32bit &

You will get this error:

[1234567890]: ERROR: ./android/qt/qt_setup.cpp:28:Qt library not found at ../emulator/lib/qt/lib
Could not launch '../emulator/qemu/linux-x86/qemu-system-x86_64': No such file or directory

And this problem is documented here: https://stackoverflow.com/questions/42554337/cannot-launch-avd-in-emulatorqt-library-not-found

There is an alternate 'emulator' binary located at $ANDROID_HOME/emulator/emulator

But even this will not work to launch an x86 image:

$ANDROID_HOME/emulator/emulator -avd Android_7.1_API_25 &

Or

$ANDROID_HOME/emulator/emulator -use-system-libs -avd Android_7.1_API_25 -no-skin -no-audio -no-window -force-32-bit &

This will result in the following error:

emulator: ERROR: x86_64 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: KVM requires a CPU that supports vmx or svm

And this problem is documented here: https://askubuntu.com/questions/564910/kvm-is-not-installed-on-this-machine-dev-kvm-is-missing and https://stackoverflow.com/questions/29136173/emulator-error-x86-emulation-currently-requires-hardware-acceleration

If you try to install the KVM software in the Docker machine, it will just fail at the sudo command -- sudo is not found, or not allowed.


The only thing that works for me is to use an ARM-based emulator instead of the x86 version, using the guidelines from https://medium.com/@AndreSand/android-emulator-on-docker-container-f20c49b129ef and https://paulemtz.blogspot.com/2013/05/android-testing-in-headless-emulator.html :

# Add missing folder to the PATH, to use sdkmanager
ANDROID_TOOLS=$ANDROID_HOME/tools/bin
PATH=$ANDROID_TOOLS:$PATH

# Download an ARM system image to create an ARM emulator.
sdkmanager "system-images;android-16;default;armeabi-v7a"

# Create an ARM AVD emulator, with 100MB SD card storage space.
echo "no" | avdmanager create avd \
    -n Android_4.1_API_16 \
    -k "system-images;android-16;default;armeabi-v7a" \
    -c 100M \
    --force

$ANDROID_HOME/emulator/emulator -avd Android_4.1_API_16 -no-skin -no-audio -no-window -no-boot-anim -gpu off &

So perhaps the x86 system images should not be included in the Docker image by default?

daonb commented

I just found this and I'm a bit confused. Can x86 emulators runs in docker? I read the this issue comments, code and README and I figured it can't.
IMO, this should be left open until there's support for x86.