Android SDK on docker - android

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

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

Debian 10 - Run android emulator with AVD Manager

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.

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.

How to create and start the emulator using Jenkins

I am new to the docker and Jenkins. First i create the docker image file. In that image install sdk and start the emulator. when i am start the emulator i am getting a following error.
Here is my code
FROM openjdk:8
# Install Git and dependencies
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y file git curl zip libncurses5:i386 libstdc++6:i386 zlib1g:i386 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists /var/cache/apt
# Set up environment variables
ENV ANDROID_HOME="/opt/android-sdk" \
SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip" \
GRADLE_URL="https://services.gradle.org/distributions/gradle-4.5.1-all.zip"
# Create a non-root user
RUN chmod 777 -Rf /opt
# Download Android SDK
RUN 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
RUN chmod 777 -Rf /opt/*
# Install Gradle
RUN wget $GRADLE_URL -O gradle.zip \
&& unzip gradle.zip \
&& mv gradle-4.5.1 gradle \
&& rm gradle.zip \
&& mkdir .gradle
ENV PATH="/home/user/gradle/bin:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${PATH}"
RUN echo y | android update sdk --no-ui
RUN echo y | android update sdk --filter tools,platform-tools,build-tools-19.0.3
RUN echo y | android update sdk --filter tools,platform-tools,build-tools-25.0.3
RUN echo y | android update sdk --filter tools,platform-tools,build-tools-26.0.2
RUN echo y | android update sdk --filter tools,platform-tools,build-tools-27.0.3
RUN echo y | android update sdk --filter tools,platform-tools,build-tools-28.0.1
RUN cd /opt/android-sdk/ && mkdir platforms
RUN cd /opt/android-sdk/tools/bin && ./sdkmanager "system-images;android-23;google_apis;x86" && echo y | ./avdmanager create avd -n test -k "system-images;android-23;google_apis;x86" -b x86 -c 100M -d 7 -f
Here is my error.

Fail to execute command using Docker

I have a docker container, which purpose is to build android NDK project.
This container is build by this tutorial http://ainoya.io/docker-android-walter. Here is the Docker file:
# based on https://registry.hub.docker.com/u/samtstern/android-sdk/dockerfile/ with openjdk-8
FROM java:8
MAINTAINER Lebedevsd <lebedevsd#gmail.com>
ENV DEBIAN_FRONTEND noninteractive
# Install dependencies
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install -yq libstdc++6:i386 zlib1g:i386 libncurses5:i386 --no-install-recommends && \
apt-get install zip && \
apt-get -y install --reinstall locales && \
apt-get clean
# Download and setup android NDK
ENV ANDROID_NDK_URL http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
RUN cd /usr/local && \
curl -L "${ANDROID_NDK_URL}" > file.zip && \
unzip -q file.zip && \
rm file.zip
ENV ANDROID_NDK_HOME /usr/local/android-ndk-r12b
ENV PATH ${ANDROID_NDK_HOME}/:$PATH
# Download and untar SDK
ENV ANDROID_SDK_URL http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
RUN curl -L "${ANDROID_SDK_URL}" | tar --no-same-owner -xz -C /usr/local
ENV ANDROID_HOME /usr/local/android-sdk-linux
ENV ANDROID_SDK /usr/local/android-sdk-linux
ENV PATH ${ANDROID_HOME}/tools:$ANDROID_HOME/platform-tools:$PATH
# Install Android SDK components
ONBUILD COPY android_sdk_components.env /android_sdk_components.env
ONBUILD RUN (while :; do echo 'y'; sleep 3; done) | android update sdk --no-ui --all --filter "$(cat /android_sdk_components.env)"
# Support Gradle
ENV TERM dumb
ENV JAVA_OPTS -Xms512m -Xmx768m
The output is
docker run -t -v $(pwd)/app:/project/app lebedevsd/android_sdk_build:latest ./gradlew clean assemblePRelease -PversionCode=24 -PversionName=0.0.24
docker: Error response from daemon: oci runtime error: exec: "./gradlew": stat ./gradlew: no such file or directory.
The problem was that I was mounting wrong directory: $(pwd)/app instead of $(pwd).
the right way is:
docker run -i -v $(pwd):/project -w /project lebedevsd/android_sdk_build:latest ./gradlew clean

Categories

Resources