I have a virtual machine running in Azure Cloud, CentOS 7
I want to run an android app in this server, so I need an android emulator
I have tried Google Official Android Emulator, but no lucks
arm architecture, zygote always receive signal 11, and then killed, and then restart, and then killed, always loop like this, emulator never start successfully
x86 architecture, emulator won't start either
configure shell:
yum -y install update
yum -y install java-1.8.0-openjdk
yum -y install pulseaudio-libs
echo 'export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/jre' | sudo tee -a ~/.bashrc
echo 'export PATH=$PATH:$JAVA_HOME/bin' | sudo tee -a ~/.bashrc
echo 'export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar' | sudo tee -a ~/.bashrc
echo '' | sudo tee -a ~/.bashrc
echo 'export ANDROID_SDK_ROOT=/root/AndroidSDK' | sudo tee -a ~/.bashrc
echo 'export ANDROID_HOME=/root/AndroidSDK' | sudo tee -a ~/.bashrc
echo 'export PATH=$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/tools/bin' | sudo tee -a ~/.bashrc
source .bashrc
mkdir -p /root/AndroidSDK/cmdline-tools
wget --tries=0 --retry-connrefused --waitretry=5 --read-timeout=20 https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip -O commandlinetools-linux.zip
unzip -o -d /root/AndroidSDK/cmdline-tools commandlinetools-linux.zip
echo yes | sdkmanager platform-tools emulator
sdkmanager "platforms;android-25"
sdkmanager "platforms;android-28"
sdkmanager "build-tools;30.0.1"
echo yes | sdkmanager --channel=3 "emulator"
sdkmanager "system-images;android-28;default;x86"
sdkmanager "system-images;android-28;default;x86_64"
sdkmanager "system-images;android-25;google_apis;arm64-v8a"
sdkmanager "system-images;android-25;google_apis;armeabi-v7a"
adb start-server
echo no | avdmanager create avd --force --name androidARM7 --package "system-images;android-25;google_apis;armeabi-v7a" | echo no
emulator -avd androidARM7 -no-skin -noaudio -no-window -camera-back none -camera-front none -no-boot-anim -gpu off -screen touch -verbose -debug all -show-kernel
echo no | avdmanager create avd --force --name androidARM8 --package "system-images;android-25;google_apis;arm64-v8a" | echo no
emulator -avd androidARM8 -no-skin -noaudio -no-window -camera-back none -camera-front none -no-boot-anim -gpu off -screen touch -verbose -debug all -show-kernel
echo no | avdmanager create avd --force --name androidX86 --package "system-images;android-28;default;x86" | echo no
emulator -avd androidX86 -no-skin -noaudio -no-window -camera-back none -camera-front none -no-boot-anim -gpu swiftshader_indirect -screen touch -verbose -debug all -show-kernel
echo no | avdmanager create avd --force --name androidX64 --package "system-images;android-28;default;x86_64" | echo no
emulator -avd androidX64 -no-skin -noaudio -no-window -no-accel -camera-back none -camera-front none -no-boot-anim -gpu off -screen touch -verbose -debug all -show-kernel
Logs too long, can't post it here
arm log:
https://pastebin.com/wh230NN6
x86 log:
https://pastebin.com/V4p2GBk8
Just want to know is it possible to run Android Emulator in a headless CentOS server?
I need to try others android emulator?
What emulator can run in linux and support headless?
Related
Context
While trying to simulate a phone and unit test adb and uiautomator interactions with the phone, in Python, I am experiencing some difficulties in finding a MWE that:
Simulates an Android phone
Simulates that Android phone over adb.
In a .gitlab-ci.yml file.
Most of the examples 1, 2, 3, 4, 5 I that I found, also compile an Android app and build it, however, I am not interested in that. I merely would like to simulate and test the interaction with the phone. Hence, I would like to ask:
Question
How can one simulate an Android phone with adb in GitLab CI and run (two files, one Bash, one Python) that contain:
adb install some_app.apk
And:
from uiautomator import device
device.screenshot("/some_path/some_file.png")
?
Approach I
I found this script to be automatically installing Android Emulator, installing an Android phone, and running it with GUI:
# Source: https://github.com/Uirado/linux-bash-install/blob/a150a462d2f9d095734f10a7b8c6c39871e5df71/batch-install.sh
# Worked.
yes | sudo apt install openjdk-8-jdk
echo 'export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")' >> ~/.profile
sudo update-java-alternatives --set java-1.8.0-openjdk-amd64
. ~/.profile
sudo apt update
sudo apt upgrade
#installLog "Android SDK"
mkdir -p ~/Android/Sdk
wget -O ~/Android/Sdk/android-sdk.zip "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
unzip -o -qq ~/Android/Sdk/android-sdk.zip -d ~/Android/Sdk
rm ~/Android/Sdk/android-sdk.zip
mv ~/Android/Sdk/tools/emulator ~/Android/Sdk/tools/emulator2
wget -O ~/gradle-4.10.3.zip https://downloads.gradle-dn.com/distributions/gradle-4.10.3-all.zip
unzip -o -qq ~/gradle-4.10.3.zip -d ~/
echo 'export GRADLE_HOME=$HOME/gradle-4.10.3' >> ~/.profile
echo 'export ANDROID_HOME=$HOME/Android/Sdk' >> ~/.profile
echo 'export ANDROID_SDK_ROOT=$ANDROID_HOME' >> ~/.profile
echo 'export PATH=$PATH:$ANDROID_HOME/tools' >> ~/.profile
echo 'export PATH=$PATH:$ANDROID_HOME/tools/bin' >> ~/.profile
echo 'export PATH=$PATH:$GRADLE_HOME/bin' >> ~/.profile
. ~/.profile
mkdir -p ~/.android
touch ~/.android/repositories.cfg
installLog "Android SDK packages"
sdkmanager --install "platform-tools"
sdkmanager --install "build-tools;29.0.2"
sdkmanager --install "extras;google;google_play_services"
sdkmanager --install "system-images;android-28;google_apis_playstore;x86_64"
sdkmanager --install emulator
echo 'export PATH=$PATH:$ANDROID_HOME/emulator' >> ~/.profile
. ~/.profile
# create android VMs android-small and #android-large
avdmanager create avd -n "android-small" -k "system-images;android-28;google_apis_playstore;x86_64"
# avdmanager create avd -n "android-small" -k "system-images;android-28;google_apis_playstore;x86_64" -d "Nexus S" -c 512
# Show installed android devices:
emulator -list-avds
# Launch emulated phone:
emulator -avd android-small -netdelay none -netspeed full
However, I was not yet able to interact with it from Python nor bash.
I am trying to run the below shell script:
#!/usr/bin/env bash
sdkmanager "emulator" "system-images;android-28;google_apis_playstore;x86_64"
echo no | avdmanager create avd -n "Android" -k "system-images;android-28;google_apis_playstore;x86_64" --device 'Nexus 6P'
$ANDROID_HOME/tools/emulator -avd Android -no-audio -no-boot-anim -no-snapshot -timezone Asia/Phnom_penh
I have added the ANDROID_HOME, ANDROID_AVD_HOME to my PATH (Note: I am using macos with zsh) and i have sourced the zshrc file and also restarted the terminal but keep getting the below error:
./start_emulator.sh: line 3: sdkmanager: command not found
./start_emulator.sh: line 4: avdmanager: command not found
PANIC: Unknown AVD name [ANDROID], use -list-avds to see valid list. ANDROID_AVD_HOME
is defined but there is no file Android.ini in $ANDROID_AVD_HOME/.android/avd (Note:
Directories are searched in the order $ANDROID_AVD_HOME,
$ANDROID_SDK_HOME/avd, and $HOME/.android/avd)
Changing the shell script to below does the job:
#!/bin/zsh
cd $ANDROID_HOME/tools/bin
./sdkmanager "emulator" "system-images;android-28;google_apis_playstore;x86_64"
echo no | ./avdmanager create avd -n "Android" -k "system-images;android-28;google_apis_playstore;x86_64" --device 'Nexus 6P'
$ANDROID_HOME/tools/emulator -avd Android -no-audio-no-boot-anim -no-snapshot -timezone Asia/Phnom_penh
Also running the commands individually(after moving to the folder) seem to work.Not sure if its a permission issue.
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.
I am trying to setup https://github.com/Fuzion24/AndroidKernelExploitationPlayground on Linux, the repository contains a vulnerable patch for 3.4 goldfish kernel. I have setup an android SDK revision 19 environment as follows : -
mkdir -p android-sdk-19/platforms
cd android-sdk-19/platforms
wget https://dl-ssl.google.com/android/repository/android-19_r04.zip
unzip *
rm android-19_r04.zip
cd ../
wget http://dl-ssl.google.com/android/repository/platform-tools_r19.0.1-linux.zip
unzip platform-tools_r19.0.1-linux.zip
rm platform-tools_r19.0.1-linux.zip
wget http://dl-ssl.google.com/android/repository/build-tools_r19.0.1-linux.zip
unzip build-tools_r19.0.1-linux.zip
rm build-tools_r19.0.1-linux.zip
wget http://dl-ssl.google.com/android/repository/tools_r19-linux.zip
unzip tools_r19-linux.zip
rm tools_r19-linux.zip
mkdir -p system-images/android-19
cd system-images/android-19
wget http://dl-ssl.google.com/android/repository/sys-img/x86/sysimg_x86-19_r02.zip
unzip sysimg_x86-19_r02.zip
rm *.zip
mkdir -p ../../sources/android-19
cd ../../sources/android-19
wget https://dl-ssl.google.com/android/repository/sources-19_r02.zip
unzip sources-19_r02.zip
rm sources-19_r02.zip
cd ../../
tools/android create avd --force -t "android-19" -n kernel_challenges --abi "x86"
After applying the patch and building the kernel image, I used the following command to run it on the emulator : -
android-sdk-19/tools/emulator \
-show-kernel -kernel goldfish/arch/arm/boot/zImage \
-avd kernel_challenges -no-boot-anim -no-skin -no-audio -no-window \
-qemu -monitor unix:/tmp/qemuSocket,server,nowait -s
But I receive the following error:
qemu: linux kernel too old to load a ram disk
goldfish/arch/arm/boot/zImage,
android-sdk-19/system-images/android-19/x86//ramdisk.img,
qemu.gles=0 qemu=1 console=ttyS0 android.qemud=ttyS1 androidboot.hardware=goldfish
clocksource=pit android.checkjni=1 android.bootanim=0 ndns=1
Has anyone managed to build a stable CI server with an emulator? I've spent most of yesterday on it.
I'm using GitLab CI on a Docker container running on Core OS inside VirtualBox, inside Windows 8.1. Right now the emulator does not start and gives me no obvious message. When I try to run tests it simply tells me that there are no running devices.
My current script does this:
- echo yes | android update sdk -a --no-ui --filter android-22
- echo yes | android update sdk -a --no-ui --filter sys-img-armeabi-v7a-google_apis-22
- echo no | android create avd --name test -t 1 -c 1000M --abi "google_apis/armeabi-v7a" --force
- emulator -avd test -partition-size 2000 -no-skin -no-audio -no-window -force-32bit &
Lastly I run
- ./gradlew :breathcount:connectedBetaDebugAndroidTest
it just tells me that no devices are available, so I added something I found on SO in five minutes.
#!/bin/bash
adb wait-for-device
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
while [ "$A" != "1" ]; do
sleep 2
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
done
adb shell input keyevent 82
This just waits for 20 minutes and no device was found.
Right now I'm considering forwarding the ADB port into Docker and running the emulator directly on the machine. VMs all the way down might be the issue.
You should wait until emulator is booted up before running gradle script. Snippet I have been using so far:
- echo y | android update sdk --all --no-ui --filter "sys-img-armeabi-v7a-google_apis-23"
- echo "no" | android -v create avd --force -n arm -t "android-23" --abi "google_apis/armeabi-v7a"
- emulator64-arm -avd arm -no-audio -no-window -no-boot-anim & adb wait-for-device
- chmod +x ./gradlew
- ./gradlew connectedDebugAndroidTest