I am trying to run an Android emulator in a Docker container.
/opt/android-sdk/emulator/emulator -avd "Android_API_29" -noaudio -no-boot-anim -netdelay none -accel on $no_window -no-snapshot -memory 4096 -partition-size 4096 &
But I get this error:
/opt/android-sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64: error while loading shared libraries: libpulse.so.0: cannot open shared object file: No such file or directory
I then attempt to wait for the emulator to start:
while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done
But adb
can't find the device:
adb: no devices/emulators found
Before running the emulator, I set it up with the following commands.
# Download Android Platform Tools
sdkmanager --install "platform-tools" "platforms;android-29"
# Download Android System Image
sdkmanager --install "system-images;android-29;google_apis;x86"
# Create Emulator
echo "no" | avdmanager --verbose create avd --name "Android_API_29" --package "system-images;android-29;google_apis;x86" --force
# Configure Emulator Settings
echo "hw.lcd.width=1080" >> ~/.android/avd/Android_API_29.avd/config.ini
echo "hw.lcd.height=1920" >> ~/.android/avd/Android_API_29.avd/config.ini
echo "hw.lcd.density=440" >> ~/.android/avd/Android_API_29.avd/config.ini
echo "hw.initialOrientation=Portrait" >> ~/.android/avd/Android_API_29.avd/config.ini
echo "hw.keyboard=yes" >> ~/.android/avd/Android_API_29.avd/config.ini
echo "hw.mainKeys=yes" >> ~/.android/avd/Android_API_29.avd/config.ini
The Docker image is running openjdk:11.0.13-slim
and has Android command line tools installed.
What am I missing? Why isn't the emulator starting correctly?
It appears that you were trying to run the emulator with the -no-window
flag but you used it incorrectly.
Replace $no_window
with -no-window
.
# Before
/opt/android-sdk/emulator/emulator -avd "Android_API_29" -noaudio -no-boot-anim -netdelay none -accel on $no_window -no-snapshot -memory 4096 -partition-size 4096 &
# After
/opt/android-sdk/emulator/emulator -avd "Android_API_29" -noaudio -no-boot-anim -netdelay none -accel on -no-window -no-snapshot -memory 4096 -partition-size 4096 &
The -no-window
flag will reduce the number of dependencies needed to run the emulator.
Disable graphical window display on the emulator. This option is useful when running the emulator on servers that have no display. You'll still be able to access the emulator through adb or the console.
https://developer.android.com/studio/run/emulator-commandline#advanced