Debian 10 - Run android emulator with AVD Manager - android

My dockerfile is here:
FROM openjdk:8
RUN apt-get update && \
apt-get install -y wget unzip && \
rm -rf /var/lib/apt/lists/*
ENV ANDROID_HOME /android-sdk-linux
ENV PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
RUN wget -q https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -O android-sdk-tools.zip \
&& unzip -q android-sdk-tools.zip -d ${ANDROID_HOME} \
&& rm android-sdk-tools.zip
RUN yes | sdkmanager --licenses
RUN touch /root/.android/repositories.cfg
RUN sdkmanager "tools" "platform-tools"
# 0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary)
RUN yes | sdkmanager --update --channel=3
RUN sdkmanager \
"system-images;android-29;google_apis;x86" \
"system-images;android-28;google_apis;x86" \
"system-images;android-26;google_apis;x86" \
"system-images;android-25;google_apis;armeabi-v7a" \
"system-images;android-24;default;armeabi-v7a" \
"system-images;android-22;default;armeabi-v7a" \
"system-images;android-19;default;armeabi-v7a" \
"extras;android;m2repository" \
"extras;google;m2repository" \
"extras;google;google_play_services" \
"extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" \
"extras;m2repository;com;android;support;constraint;constraint-layout;1.0.1" \
"add-ons;addon-google_apis-google-23" \
"add-ons;addon-google_apis-google-22" \
"add-ons;addon-google_apis-google-21"
OS version: PRETTY_NAME="Debian GNU/Linux 10 (buster)". To create an android emulator, I run below commands.
$sdkmanager "emulator"
$echo "yes" | sdkmanager --licenses
$sdkmanager "--verbose" "--channel=0" "emulator"
$emulator -list-avds
$sdkmanager --install "system-images;android-29;default;x86"
$echo "no" | avdmanager --verbose create avd --force --name "my_local_emulator" --package "system-images;android-29;default;x86" --tag "default" --abi "x86"
$emulator -list-avds
my_local_emulator
Set LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=${ANDROID_HOME}/tools/lib64:${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib
I get an error when I start the emulator
$ANDROID_HOME/emulator/emulator #my_local_emulator "-no-audio" "-no-window" "-no-boot-anim" "-netdelay" "none" "-no-snapshot" "-wipe-data" "-gpu" "swiftshader_indirect" "-camera-back" "none" "-camera-front" "none" &
emulator: ERROR: x86 emulation currently requires hardware
acceleration! Please ensure KVM is properly installed and usable. CPU
acceleration status: /dev/kvm is not found: VT disabled in BIOS or KVM
kernel module not loaded More info on configuring VM acceleration on
Linux:
https://developer.android.com/studio/run/emulator-acceleration#vm-linux
General information on acceleration:
https://developer.android.com/studio/run/emulator-acceleration.
To solve this error, I run below command:
echo "yes" | apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils ia32-libs-multiarch
Reading package lists... Building dependency tree... Reading state
information... Package libvirt-bin is not available, but is referred
to by another package. This may mean that the package is missing, has
been obsoleted, or is only available from another source E: Package
'libvirt-bin' has no installation candidate E: Unable to locate
package ubuntu-vm-builder E: Unable to locate package
ia32-libs-multiarch
I have tried many commands and possible solutions, but none of them doesn't work for me.
How can I run the emulator without android studio on debian 10?

Try the -no-accel flag when you start the emulator, maybe this will help.
https://developer.android.com/studio/run/emulator-commandline
Disable emulator VM acceleration when using an x86 or x86_64 system image. It's useful for debugging only and is the same as specifying -accel off.

Related

Running Android emulator in docker container

We are building an app in React Native using wix/Detox for writing e2e tests.
We are using Docker for doing builds and running tests. Specifically, we're using community react-native-android Docker image.
I have added fastlane to the image for building / publishing our app and now trying to add an emulator so that we can run tests as well.
This is our Dockerfile:
# reactnativecommunity/react-native-android:4.0
FROM reactnativecommunity/react-native-android#sha256:c3ad9b8ed5caac0718b1c1b8f10469eb75b0ac77c86143c94f9616ee46b80b4b
RUN gem install fastlane -NV
RUN sdkmanager --install "system-images;android-31;google_apis;arm64-v8a"
RUN echo no | avdmanager create avd --name default -k "system-images;android-31;google_apis;arm64-v8a"
However, when I run the container and attempt to start the emulator, I get the following:
root#7b862aa149c8:/# emulator -no-audio -no-boot-anim -no-window -use-system-libs #default
emulator: Android emulator version 30.7.5.0 (build_id 7491168) (CL:N/A)
emulator: INFO: ignore sdcard for arm at api level >= 30
emulator: feeding guest with passive gps data, in headless mode
emulator: ERROR: AdbHostServer.cpp:102: Unable to connect to adb daemon on port: 5037
cannot add library /opt/android/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
added library /opt/android/emulator/lib64/vulkan/libvulkan.so
emulator: INFO: ignore sdcard for arm at api level >= 30
emulator: INFO: userspace-boot-properties.cpp:242: Sending adb public key [QAAAACG/f/Yfe1MON5LKVoRU+iuzZRCKQTvsqLWcWh8i5ii03oHLY7y7U+0uKSE5x84OrGS0g6G9HTU7Mazh18yhbmPAQociSCfrSRIWg3IAdduFDgYPnY2G3Lj11ZLQoyRt4+xXO7zVcUPtwERpgpYQXEN5KkkEZBUxxWvrejENPAffPp4DHFqJf63sAUPh9qo6cwfSMylnl7RTBicxZ+tuDwrxA1JgcvklAs38E9gzxjNDed+1VibNUjzCtRl4DnPPmIk1OqhvjU0xZV//YXDrdhb++jQOpcKAzkCvVks4RUjJ1okytnmDfh+YUH4thQYuqNdEBnGM4wz8cPQH0YjO1SsK2sOrD0VJaGjSDAwsjne2QCFy5ET+HOUcMNKCaC60MAcCgWXLm8MdoaVLgjoG0jbUEkr/BJ2hpN7/p+qi8qMSg3Vv2M/4kdHmIEzDpJTd8TFD1bbrRjdUIheDzE1b00SKhQzDJ39sQim31IqWGuRIJ4Cb39VaHCFK6ZwZPpG9KKLSV1ww5KCKVgSsJ5zaAvhagCjXXXVrtl40v72zYq/c0BtUG4LhLixtz/zuT1WFKq8HoGFkJBvw5fBVqcvOn6yN7xI3DAuzAlQcHPyRQdHm72+//KimCVHnkxlL3hpRMir06QhMk2DsKTntXjbYuhCCn0aetEUUpai6gl1NuCbv92QlDgEAAQA= #unknown]
emulator: INFO: GrpcServices.cpp:315: Started GRPC server at 127.0.0.1:8554, security: Local
WARNING. Using fallback path for the emulator registration directory.
emulator: INFO: EmulatorAdvertisement.cpp:93: Advertising in: /root/.android/avd/running/pid_9.ini
qemu-system-aarch64-headless: PCI bus not available for hda
saving arm snapshot.... !!!
saving done.... !!!
root#7b862aa149c8:/#
This is what worked in the end BUT required bare metal machine
# reactnativecommunity/react-native-android:4.0
FROM reactnativecommunity/react-native-android#sha256:c3ad9b8ed5caac0718b1c1b8f10469eb75b0ac77c86143c94f9616ee46b80b4b
ARG IMAGE="system-images;android-31;google_apis;x86_64"
RUN sdkmanager --install "${IMAGE}"
RUN echo no | avdmanager create avd --name emulator_for_e2e_testing -k "${IMAGE}"
ENTRYPOINT adb start-server && emulator -avd emulator_for_e2e_testing -no-audio -no-window -no-boot-anim
So,
Is it possible to run the (Android) emulator through Docker? yes.
I don't know much about Fastlane|wix/Detox, but I made this in a e2e/Appium project
If so, how?
Do you need a hardware that support virtualization
In Linux find out if CPU Support Intel VT/AMD-V Virtualization For KVM
lscpu | grep Virtualization
Virtualization: VT-x (if 'Intel VT-x' or 'VT-x' feature supported)
or
Virtualization: full (if 'full' not supported)
On AWS, you need a bare metal instance (supported x86) like c5.metal
Android Emulator Container Scripts
https://github.com/google/android-emulator-container-scripts
Follow this git, create an image with google API (I my case, 27-google-x86) and put in docker repo, like AWS ECR.
And, I created an image too to Appium (I believe with is possible with wix/detox)
To SDK
Dockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
# Installs i386 architecture required for running 32 bit Android tools
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get dist-upgrade -y && \
apt-get install -y --no-install-recommends openjdk-8-jdk && \
apt-get install -y --no-install-recommends git wget unzip curl make && \
rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \
apt-get clean
ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre" \
PATH=$PATH:$JAVA_HOME/bin
# Installs Android SDK
ENV ANDROID_HOME=/android-sdk
ENV ANDROID_SDK_HOME $ANDROID_HOME
ARG ANDROID_SDK_VERSION=6514223
ARG ANDROID_BUILD_TOOLS_VERSION=27.0.0
ARG ANDROID_PLATFORM_VERSION="android-27"
RUN mkdir -p ${ANDROID_SDK_HOME}/cmdline-tools && \
wget -q https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_VERSION}_latest.zip && \
unzip *tools*linux*.zip -d ${ANDROID_SDK_HOME}/cmdline-tools && \
rm *tools*linux*.zip
ENV PATH ${PATH}:${ANDROID_SDK_HOME}/tools:${ANDROID_SDK_HOME}/platform-tools
RUN mkdir -p ~/.android && \
touch ~/.android/repositories.cfg && \
echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager --licenses && \
echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager "platform-tools" && \
echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" && \
echo y | ${ANDROID_SDK_HOME}/cmdline-tools/tools/bin/sdkmanager "platforms;$ANDROID_PLATFORM_VERSION"
# Installs Node
ARG NODE_VERSION=12.x
RUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION} | bash
RUN apt-get install --yes nodejs
Finally, I orchestrated everything a Jenkinsfile

Android SDK on docker

Im trying to run android emulator on docker but I get the following error, I have done some research but none of the answers helped me in achieving my goal, here is the error that I get and my docker file, I have tried armeabi and system-images;android-29;google_apis;x86 and both did not work.
# emulator -avd device
emulator: WARNING: encryption is off
emulator: INFO: QtLogger.cpp:68: Warning: could not connect to display ((null):0, (null))
emulator: INFO: QtLogger.cpp:68: Info: Could not load the Qt platform plugin "xcb" in "/opt/android-sdk/emulator/lib64/qt/plugins" even though it was found. ((null):0, (null))
Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
((null):0, (null))
emulator: INFO: QtLogger.cpp:68: Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
((null):0, (null))
Aborted
Im doing the same steps on my MAC and it's working fine, here is my docker file:
FROM ubuntu:18.04
RUN dpkg --add-architecture i386 && \
apt-get update -y && \
apt-get install -y --no-install-recommends libncurses5:i386 libc6:i386 libstdc++6:i386 lib32gcc1 lib32ncurses5 lib32z1 zlib1g:i386 && \
apt-get install -y --no-install-recommends openjdk-8-jdk && \
apt-get install -y --no-install-recommends git wget unzip && \
apt-get install -y --no-install-recommends qt5-default
ARG GRADLE_VERSION=5.2.1
ARG GRADLE_DIST=bin
RUN cd /opt && \
wget -q https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-${GRADLE_DIST}.zip && \
unzip gradle*.zip && \
ls -d */ | sed 's/\/*$//g' | xargs -I{} mv {} gradle && \
rm gradle*.zip
# download and install Android SDK
# https://developer.android.com/studio/#downloads
ARG ANDROID_SDK_VERSION=4333796
ENV ANDROID_HOME /opt/android-sdk
RUN mkdir -p ${ANDROID_HOME} && cd ${ANDROID_HOME} && \
wget -q https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_VERSION}.zip && \
unzip *tools*linux*.zip && \
rm *tools*linux*.zip
# set the environment variables
ENV APK_SIGNER=/opt/android-sdk/build-tools/29.0.2/
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV ANDROID_SDK_ROOT /opt/android-sdk
ENV GRADLE_HOME /opt/gradle
ENV PATH ${PATH}:${GRADLE_HOME}/bin:${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools/bin/apksigner:${APK_SIGNER}
ENV _JAVA_OPTIONS -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
# WORKAROUND: for issue https://issuetracker.google.com/issues/37137213
ENV LD_LIBRARY_PATH ${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib
# accept the license agreements of the SDK components
ADD docker/license_accepter.sh /opt/
RUN chmod +x /opt/license_accepter.sh && /opt/license_accepter.sh $ANDROID_HOME
# setup adb server
EXPOSE 5037
# install and configure SSH server
EXPOSE 22
ADD docker/sshd-banner /etc/ssh/
ADD docker/authorized_keys /tmp/
RUN apt-get update -y && \
apt-get install -y --no-install-recommends openssh-server supervisor locales && \
mkdir -p /var/run/sshd /var/log/supervisord && \
locale-gen en en_US en_US.UTF-8 && \
apt-get remove -y locales && apt-get autoremove -y && \
FILE_SSHD_CONFIG="/etc/ssh/sshd_config" && \
echo "\nBanner /etc/ssh/sshd-banner" >> $FILE_SSHD_CONFIG && \
echo "\nPermitUserEnvironment=yes" >> $FILE_SSHD_CONFIG && \
ssh-keygen -q -N "" -f /root/.ssh/id_rsa && \
FILE_SSH_ENV="/root/.ssh/environment" && \
touch $FILE_SSH_ENV && chmod 600 $FILE_SSH_ENV && \
printenv | grep "JAVA_HOME\|GRADLE_HOME\|ANDROID_HOME\|LD_LIBRARY_PATH\|PATH" >> $FILE_SSH_ENV && \
FILE_AUTH_KEYS="/root/.ssh/authorized_keys" && \
touch $FILE_AUTH_KEYS && chmod 600 $FILE_AUTH_KEYS && \
for file in /tmp/*.pub; \
do if [ -f "$file" ]; then echo "\n" >> $FILE_AUTH_KEYS && cat $file >> $FILE_AUTH_KEYS && echo "\n" >> $FILE_AUTH_KEYS; fi; \
done && \
(rm /tmp/*.pub 2> /dev/null || true)
ADD docker/supervisord.conf /etc/supervisor/conf.d/
ADD docker/supervisord.conf /etc/supervisor/conf.d/
ADD docker/android.keystore /Android-APK/
ADD app/build/outputs/apk/release/ /Android-APK/
RUN sdkmanager "platform-tools" "platforms;android-29" "build-tools;29.0.2" "add-ons;addon-google_apis-google-24"
RUN apksigner sign --ks /Android-APK/android.keystore --ks-pass pass:android --key-pass pass:android --in /Android-APK/app-release-unsigned.apk --out /Android-APK/signed-app.apk
RUN zipalign -f 4 /Android-APK/signed-app.apk /Android-APK/aligned-app.apk
#RUN sdkmanager "system-images;android-23;google_apis;x86"
#RUN adb install /Android-APK/aligned-app.apk
#RUN sdkmanager "system-images;android-25;google_apis;arm64-v8a"
#RUN avdmanager create avd --force --name "device" --abi "arm64-v8a" --package 'system-images;android-25;google_apis;arm64-v8a' --device "Nexus 10"
CMD ["/usr/bin/supervisord"]
I had a similar problem, and it ended up being that our script was running the incorrect version of the emulator (26, which doesn't have good support for headless yet)
It should be running
$ANDROID_HOME/emulator/emulator -avd avd-name -no-skin -no-audio -no-window
and not the emulator in the tools folder.
Check the version of the emulator by just running the executable. My output (that works) is
emulator: Android emulator version 30.4.5.0 (build_id 7140946) (CL:N/A)
emulator: ERROR: No AVD specified. Use '#foo' or '-avd foo' to launch a virtual device named 'foo'
first run
xhost +
then run your docker container like this
docker run -i -t --net=host --privileged --env="DISPLAY" \
-v $HOME/.Xauthority:/root/.Xauthority:rw \
-v ~/disk1/android_docker:/home/android \
android-image /bin/bash
then you can run
emulator

Connect to Android Emulator in a Docker Container through VNC (error with API 28)

I'm using a VNC client (Remmina) to connect to an Android Emulator running in a Docker container, and it worked with APIs from 19 to 27, but 28 errors when using with the VNC option (but works without VNC):
qemu-system-x86_64: VNC supports only guest GPU, add "-gpu guest" option
My environment:
myrepo/app-tools:android-dev-1.0.2
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
RUN echo "debconf shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections && \
echo "debconf shared/accepted-oracle-license-v1-1 seen true" | debconf-set-selections
ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" \
ANDROID_HOME="/usr/local/android-sdk" \
ANDROID_VERSION="28" \
ANDROID_BUILD_TOOLS_VERSION="28.0.3" \
GRADLE_VERSION="5.0"
ENV GRADLE_URL="https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip" \
GRADLE_HOME="/opt/gradle/gradle-${GRADLE_VERSION}" \
PATH="/opt/gradle/gradle-${GRADLE_VERSION}/bin:${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools"
COPY android/repositories.cfg /root/.android/
# Download JDK-8 and fix certificate issues
RUN apt-get update \
&& apt-get install -y openjdk-8-jdk \
&& apt-get install -y ant \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/cache/oracle-jdk8-installer \
&& apt-get update \
&& apt-get install -y ca-certificates-java \
&& apt-get clean \
&& update-ca-certificates -f \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/cache/oracle-jdk8-installer
# Download Android SDK
RUN cd /tmp \
&& apt-get update \
&& apt-get install -y nano zip curl net-tools socat \
&& curl -o gradle.zip -L "$GRADLE_URL" \
&& unzip -d /opt/gradle gradle.zip \
&& rm gradle.zip \
&& mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& yes | "$ANDROID_HOME/tools/bin/sdkmanager" --licenses \
&& "$ANDROID_HOME/tools/bin/sdkmanager" --update \
&& "$ANDROID_HOME/tools/bin/sdkmanager" \
"build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
"platforms;android-${ANDROID_VERSION}" \
"platform-tools" \
"emulator"
RUN mkdir /main
WORKDIR /main
android/repositories.cfg
### User Sources for Android SDK Manager
#Fri Nov 03 10:11:27 CET 2017 count=0
android-dev.dockerfile
FROM myrepo/app-tools:android-dev-1.0.2
ENV ANDROID_SDK="/usr/local/android-sdk"
ENV PATH="$ANDROID_SDK/emulator:$ANDROID_SDK/tools:$PATH"
RUN /usr/local/android-sdk/tools/bin/sdkmanager "system-images;android-19;google_apis;x86" \
&& /usr/local/android-sdk/tools/bin/sdkmanager --licenses
RUN /usr/local/android-sdk/tools/bin/sdkmanager "system-images;android-23;google_apis;x86" \
&& /usr/local/android-sdk/tools/bin/sdkmanager --licenses
RUN /usr/local/android-sdk/tools/bin/sdkmanager "system-images;android-28;google_apis;x86" \
&& /usr/local/android-sdk/tools/bin/sdkmanager --licenses
RUN /usr/local/android-sdk/tools/bin/avdmanager create avd -n avd19 -k "system-images;android-19;google_apis;x86" -b x86 -d 7 -f \
&& /usr/local/android-sdk/tools/bin/avdmanager create avd -n avd23 -k "system-images;android-23;google_apis;x86" -b x86 -d 7 -f \
&& /usr/local/android-sdk/tools/bin/avdmanager create avd -n avd28 -k "system-images;android-28;google_apis;x86" -b x86 -d 7 -f
COPY scripts/android-dev-startup.sh /root/start.sh
scripts/android-dev-startup.sh
#!/bin/bash
set -eou pipefail
socat tcp-listen:5037,bind=android-dev,fork tcp:127.0.0.1:5037 &
socat tcp-listen:5554,bind=android-dev,fork tcp:127.0.0.1:5554 &
socat tcp-listen:5555,bind=android-dev,fork tcp:127.0.0.1:5555 &
sleep infinity
docker-compose
android-dev:
build:
context: ./
dockerfile: android-dev.dockerfile
hostname: android-dev
volumes:
- .:/main:rw
devices:
- "/dev/kvm:/dev/kvm"
ports:
- "5037:5037"
- "5554:5554"
- "5555:5555"
- "5900:5900"
command: /root/start.sh
Then, if I run the command to start the emulator, it works in all cases except when using the emulator with android-28 (when using VNC):
# works
emulator -memory 4096 -avd avd19 -noaudio -no-window -gpu off -verbose -qemu -vnc :0
# works
emulator -memory 4096 -avd avd23 -noaudio -no-window -gpu off -verbose -qemu -vnc :0
# works
emulator -memory 4096 -avd avd28 -noaudio -no-window -gpu off -verbose -qemu
# doesn't work
# qemu-system-x86_64: VNC supports only guest GPU, add "-gpu guest" option
emulator -memory 4096 -avd avd28 -noaudio -no-window -gpu off -verbose -qemu -vnc :0
# doesn't work
# qemu-system-x86_64: VNC supports only guest GPU, add "-gpu guest" option
emulator -memory 4096 -avd avd28 -noaudio -no-window -gpu guest -verbose -qemu -vnc :0
I think the error comes from this file:
https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/vl.c
Is there a way to make it work with VNC?
I found something interesting in the output of the emulator-headless:
emulator: WARNING: Your AVD has been configured with an in-guest renderer, but the system image does not support guest rendering.Falling back to 'swiftshader_indirect' mode.
emulator: GPU emulation enabled using 'swiftshader_indirect' mode
emulator: Initializing hardware OpenGLES emulation support
https://androidstudio.googleblog.com/2018/11/emulator-28016-stable.html?m=1
-gpu guest (software rendering in the guest) has been deprecated. API 28+ system images will now auto switch to using Swiftshader (-gpu swiftshader_indirect).
So it switches to swiftshader_indirect, which makes it unable to use vnc. Uh oh.
So now I wonder if one can use environmental variable DISPLAY to make emulator-headless render the graphics into virtual display that one will create with some another VNC server...
Edit:
Yes, it seems to be working well on 2 Xeon cores 3.3Ghz each and 4GB RAM.
echo 'no' | avdmanager create avd --force --name android-28-x86 --abi google_apis_playstore/x86 --package 'system-images;android-28;google_apis_playstore;x86'
apt install tightvnc
apt install xfonts-base
sudo apt-get install gnome-core xfce4 firefox nano -y --force-yes
# ~/.vnc/xstatup
unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS startxfce4 & [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic &
vncserver :2 -geometry 1080x1920 -depth 24
export DISPLAY=:2.0
emulator #android-28-x86 -verbose -memory 2048 -gpu swiftshader_indirect -no-audio -no-snapshot -wipe-data -no-boot-anim -skin 768x1280
I still have no idea why the android emulator developers decided to disable vnc support in their product if everything works well with gpu software emulation on standalone vnc server..?
Edit2:
It always loads CPU 100% though. Apparently it requires a fix. https://gist.github.com/yazinsai/652f0e6e77c9594a2356dd6314a9c3d8
LMK if you want to implement it.

Docker GitLab Error running Android Emulator: Cannot decide host bitness. 32 bits assumed

I am trying to automate Android Builds and Tests. The instrumentation test is not working because I get the following error while starting the android emulator in the Docker Runner:
Running with gitlab-ci-multi-runner 9.4.2 (6d06f2e) ...
Using Docker executor with image kmindi/android-ci:latest ...
...
$ chmod +x ./gradlew
$ echo no | avdmanager -v create avd --force --name test --abi google_apis/x86_64 --package 'system-images;android-25;google_apis;x86_64'
Do you wish to create a custom hardware profile? [no] $ export SHELL=/bin/bash && echo "no" | emulator -avd test -noaudio -no-window -gpu off -verbose -qemu
sh: 1: file: not found
sh: 1: file: not found
WARNING: Cannot decide host bitness because $SHELL is not properly defined; 32 bits assumed.
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.
ERROR: Job failed: exit code 1
I created the following Dockerfile (https://hub.docker.com/r/kmindi/android-ci/)
FROM openjdk:8-jdk
ENV ANDROID_BUILD_TOOLS "26.0.1"
ENV ANDROID_SDK_TOOLS "25.2.5"
ENV ANDROID_HOME "/android-sdk"
ENV PATH=$PATH:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
# Prepare dependencies
RUN mkdir $ANDROID_HOME \
&& apt-get update --yes \
&& apt-get install --yes wget tar unzip lib32stdc++6 lib32z1 libqt5widgets5 expect \
&& apt-get clean \
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install sdk tools
RUN wget -O android-sdk.zip https://dl.google.com/android/repository/tools_r${ANDROID_SDK_TOOLS}-linux.zip \
&& unzip -q android-sdk.zip -d $ANDROID_HOME \
&& rm android-sdk.zip
# Workaround for
# Warning: File /root/.android/repositories.cfg could not be loaded.
RUN mkdir /root/.android \
&& touch /root/.android/repositories.cfg
# Workaround for host bitness error with android emulator
# https://stackoverflow.com/a/37604675/455578
RUN mv /bin/sh /bin/sh.backup \
&& cp /bin/bash /bin/sh
# Add tools from travis
ADD https://raw.githubusercontent.com/travis-ci/travis-cookbooks/ca800a93071a603745a724531c425a41493e70ff/community-cookbooks/android-sdk/files/default/android-wait-for-emulator /usr/local/bin/android-wait-for-emulator
RUN chmod +x /usr/local/bin/android-wait-for-emulator
# Add own tools
COPY assure_emulator_awake.sh /usr/local/bin/assure_emulator_awake.sh
RUN chmod +x /usr/local/bin/assure_emulator_awake.sh
# Update platform and build tools
RUN echo "y" | sdkmanager "tools" "platform-tools" "build-tools;${ANDROID_BUILD_TOOLS}"
# Update SDKs
RUN echo "y" | sdkmanager "platforms;android-26" "platforms;android-25"
# Update emulators
RUN echo "y" | sdkmanager "system-images;android-25;google_apis;x86_64"
# Update extra
RUN echo "y" | sdkmanager "extras;android;m2repository" "extras;google;m2repository" "extras;google;google_play_services"
# Constraint Layout
RUN echo "y" | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
RUN echo "y" | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"
In GitLab I use the following .gitlab-ci.yml:
image: kmindi/android-ci:latest
variables:
ANDROID_COMPILE_SDK: "25"
before_script:
- chmod +x ./gradlew
stages:
- build
- test
build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
name: "App_{$CI_BUILD_ID}"
expire_in: 1 week
paths:
- "app/build/outputs/apk/**/*.apk"
except:
- tags
test:unit:
stage: test
script:
- ./gradlew test jacoco
artifacts:
name: "tests-unit-${CI_BUILD_NAME}_${CI_COMMIT_REF_NAME}_${CI_BUILD_REF}"
expire_in: 1 week
paths:
- "**/build/reports/**"
test:instrumentation:25:
stage: test
script:
- echo no | avdmanager -v create avd --force --name test --abi google_apis/x86_64 --package 'system-images;android-25;google_apis;x86_64'
- export SHELL=/bin/bash && echo "no" | emulator -avd test -noaudio -no-window -gpu off -verbose -qemu &
- adb wait-for-device
- android-wait-for-emulator
- export TERM=${TERM:-dumb}
- assure_emulator_awake.sh "./gradlew cAT"
- ./gardlew createDebugCoverageReport
artifacts:
name: "tests-instrumentation-${ANDROID_COMPILE_SDK}-${CI_BUILD_NAME}"
expire_in: 1 week
paths:
- "**/build/reports/**"
The workaround proposed in https://stackoverflow.com/a/37604675/455578 (chaning of bash/sh) is not working (applied in the Dockerfile). Also setting the SHELL variable does not help. If I use emulator64-x86 instead of emulator I get the error command not found.
What am I missing?
Do I have to install other packages via apt?
Maybe it originates in the used openjdk-8 / debian stretch docker image?
Thanks :)
With SDK Revision 25.3.0 (March 2017) emulator was released separately from the SDK Tools (https://developer.android.com/studio/releases/emulator.html#25-3).
Practically it means that now there is a new ${ANDROID_HOME}/emulator folder which you have to add to PATH. (NOTE: it has to be added before tools folder, because for whatever reason old tools/emulator binary is still there). Example:
ENV PATH ${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}

Android SDK tools install in Docker fails

I am trying to make a docker image that I can use to build Android projects, using Shippable.
The problem is the android update sdk command, which gives the following error:
Installing Android SDK Tools, revision 24.2
Failed to rename directory /opt/android-sdk-linux/tools to /opt/android-sdk-linux/temp/ToolPackage.old01.
Failed to create directory /opt/android-sdk-linux/tools
I found somewhat of a solution here: https://stackoverflow.com/a/8839359/867099 but it's for Windows, and does not seem to fix the problem on linux. It appears that during the update command, the current directory is in use and therefore cannot be renamed.
My workaround sofar, using that workaroundsuggestion, is this:
RUN cp -r /opt/android-sdk-linux/tools /opt/android-sdk-linux/tools_copy
RUN cd /opt/android-sdk-linux/tools && echo 'y' | /opt/android-sdk-linux/tools_copy/android update sdk --no-ui -a --filter tools,platform-tools,build-tools-22.0.1,android-21,extra-android-support,extra-google-google_play_services --force
In order to automatically accept the license, I echo 'y' to the android command.
But I think the android command should also run in the correct directory, which is why I cd into it first.
But, it still fails. I'm rather stumped on how to fix this issue, so any help is appreciated.
------ UPDATE --------
I run the android sdk update command without the tools filter, and in the end, my gradle builds are successful. So I don't know for sure whether it's a problem to not update them...
This can be solved by combining all Android SDK commands in a single Dockerfile's RUN command. It has something to do with Docker's file system.
For a detailed explanation from a post on Issue Tracker for the Android Open Source Project:
The problem is caused when you run the SDK update in a Docker
container. Docker uses a special filesystem which works like a version
control system (e.g. git) and records all changes made to the
filesystem. The problem is that the SDK update uses a hardlink move
operation to move the 'tools' directory, which is not supported by the
underlying Docker filesystem.
The solution for this is to simply run all Android SDK commands in a
single 'RUN' command in Docker. That way, the hardlink move works as
normal, as long as you don't use the 'hardlink move' operation between
multiple RUN command (snapshots). The advantage of this is also that
your Docker layers will be smaller (compared to running multiple
seperate RUN commands).
Here is the line from the Dockerfile:
RUN wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz && \
tar xzf android-sdk_r24.4.1-linux.tgz && \
rm android-sdk_r24.4.1-linux.tgz && \
(echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter platform-tools,tools -a ) && \
(echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository -a) && \
(echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter build-tools-23.0.2,android-24 -a)
This is what's currently working for me, you can see the update command successfully running below. In my environment these are 3 different docker images in one FROM hierarchy so you can likely combine a lot of the apt-gets if that's not your case.
FROM ubuntu:14.04
# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
python \
rsync \
software-properties-common \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install the JDK
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections && \
add-apt-repository -y ppa:webupd8team/java && \
apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -qqy --force-yes oracle-java7-installer && \
rm -rf /var/lib/apt/lists/* /var/cache/oracle-jdk7-installer
# Install Android Dev Tools
RUN apt-get update && apt-get install -y -q --no-install-recommends \
lib32ncurses5 \
lib32stdc++6 \
lib32z1 \
libswt-gtk-3-java \
unzip \
&& rm -rf /var/lib/apt/lists/*
RUN wget -qO- "http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz" | tar -zxv -C /opt/
RUN cd /opt/android-sdk-linux/tools/ && \
echo y | ./android update sdk --all --filter platform-tools,build-tools-20.0.0,android-17,sysimg-17,system-image,extra-android-support --no-ui --force
ENV PATH /opt/android-sdk-linux/build-tools/20.0.0:$PATH

Categories

Resources