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
Related
Hi currently I am try to run Android instrumental test in Gitlab CI, but i am facing "emulator: ERROR: Not enough disk space to run AVD 'testAVD'. Exiting..." when try to run the emulator, then the CI process will just stuck there.
Gitlab CI result
$ echo n | android-sdk-linux/tools/bin/avdmanager create avd -f -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86_64"
Loading local repository...
[========= ] 25% Loading local repository...
[========= ] 25% Fetch remote repository...
[========= ] 25% Fetch remote repository...
[========= ] 25% Fetch remote repository...
[=======================================] 100% Fetch remote repository...
Auto-selecting single ABI x86_64
Do you wish to create a custom hardware profile? [no] $ android-sdk-linux/emulator/emulator -avd testAVD -no-audio -no-window &
$ adb wait-for-device
* daemon not running; starting now at tcp:5037
* daemon started successfully
emulator: ERROR: Not enough disk space to run AVD 'testAVD'. Exiting...
.gitlab-ci.yml
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.3"
ANDROID_SDK_TOOLS: "4333796"
CMAKE: "3.10.2.4988404"
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "ndk-bundle" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "cmake;${CMAKE}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux/
- export CMAKE_HOME=$PWD/android-sdk-linux/cmake/${CMAKE}/bin/
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/:$CMAKE_HOME
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
stages:
- test
instrumentationTest:
stage: test
script:
- echo y | android-sdk-linux/tools/bin/sdkmanager "emulator" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86_64"
- echo n | android-sdk-linux/tools/bin/avdmanager create avd -f -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86_64"
- android-sdk-linux/emulator/emulator -avd testAVD -no-audio -no-window &
- adb wait-for-device
- adb shell input keyevent 82 &
- android list target
- ./gradlew connectedAndroidTest
How can i setup the Gitlab to run Android emulator with sufficient disk space?
How can i setup the Gitlab to run Android emulator with sufficient disk space?
If we are talking about public gitlab.com repositories with their public shared runner then according to documentation we had only 25GB disk space on runner:
All your CI/CD jobs run on n1-standard-1 instances with 3.75GB of RAM, CoreOS and the latest Docker Engine installed. Instances provide 1 vCPU and 25GB of HDD disk space.
The gitlab-shared-runners-manager-X.gitlab.com fleet of Runners are dedicated for GitLab projects as well as community forks of them. They use a slightly larger machine type (n1-standard-2) and have a bigger SSD disk size.
— in other words if your project not fork of official GitLab-org repository then runner will have only 25gb space
Other opportunity to increase runner disk space is setup your own runner:
Install GitLab Runner
Specify the gitlab url during the Runner setup: https://gitlab.com/ (or you custom gitlab installation host)
Go to http://your-repository -> Settings -> CI/CD -> expand Runners section and take registration token which you will be asked during setup
Start the Runner
Also notice that you can debug runner disk free space by put next command df -h after each operation. Like this:
instrumentationTest:
stage: test
script:
- df -h
- echo y | android-sdk-linux/tools/bin/sdkmanager "emulator" >/dev/null
- df -h
- echo y | android-sdk-linux/tools/bin/sdkmanager "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86_64"
- df -h
- echo n | android-sdk-linux/tools/bin/avdmanager create avd -f -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86_64"
- df -h
- android-sdk-linux/emulator/emulator -avd testAVD -no-audio -no-window &
- df -h
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?
I require some assistance in setting up an emulator on CircleCI to test my Android instrumented test.
general:
artifacts:
- /home/ubuntu/buildtest/app/build/outputs/apk/
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
dependencies:
override:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-26.0.2,android-26,extra-google-google_play_services
- chmod +x gradlew
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
test:
pre:
- android list targets
- echo no | android create avd -n emulatorwithgoogleapi22 -t 12 --tag google_apis
- echo 'vm.heapSize=512' >> ~/.android/avd/emulatorwithgoogleapi22.ini
- echo 'hw.ramSize=1024' >> ~/.android/avd/emulatorwithgoogleapi22.ini
- cat ~/.android/avd/emulatorwithgoogleapi22.ini
- emulator -avd emulatorwithgoogleapi24 -no-audio -no-window :
background: true
parallel: true
- circle-android wait-for-boot
- adb shell input keyevent 82
- adb shell svc power stayon true
- adb shell settings put global window_animation_scale 0
- adb shell settings put global transition_animation_scale 0
- adb shell settings put global animator_duration_scale 0
override:
- ./gradlew assembleDebug
- ./gradlew connectedAndroidTest
post:
- cp -r app/build/outputs $CIRCLE_ARTIFACTS
- cp -r app/build/outputs/androidTest-results/ $CIRCLE_TEST_REPORTS
Above is the YAML file that i use to build on the server. I tried the previous solutions from various forums, but i am still stuck.
Help?
I want to build and test an Android app using an emulator in Travis CI.
On my local machine I can create emulator with both android and avdmanager tools, examples:
echo no | android create avd --force --name test01 --package 'system-images;android-27;google_apis_playstore;x86'
echo no | avdmanager create avd --force --name test02 --package 'system-images;android-27;google_apis_playstore;x86'
But on Travis there's no avdmanager in $ANDROID_HOME/tools/bin
When I tried to create emulator with android tool (which isn't desired because it's deprecated) it turned out that it's different from version installed on my mac and requires different parameters
My .travis.yml file (vars and build steps removed for clarity):
sudo: true
os: linux
dist: trusty
language: android
android:
components:
- build-tools-26.0.2
- android-26
before_script:
- echo no | android create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'
#- echo no | avdmanager create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'
script:
- echo "DEBUG searching for avdmanager" && ls -lAp $ANDROID_HOME/tools/bin
So could you please advice how should I create Android emulator in Travis CI?
After playing around the official ways, the simplest way I found to launch one emulator on travis has at least this in travis.xml
before_install:
# Install SDK license so Android Gradle plugin can install deps.
- mkdir "$ANDROID_HOME/licenses" || true
- echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
# Install the rest of tools (e.g. avdmanager)
- sdkmanager tools
# Install the system image.
- sdkmanager "system-images;android-24;default;armeabi-v7a"
# Create and start emulator for the script. Meant to race the install task.
- echo no | avdmanager create avd --force -n emulatorApi24 -k "system-images;android-24;default;armeabi-v7a"
- $ANDROID_HOME/emulator/emulator -avd emulatorApi24 -no-audio -no-window &
before_script:
- android-wait-for-emulator
# Disable animations
- adb shell settings put global window_animation_scale 0 &
- adb shell settings put global transition_animation_scale 0 &
- adb shell settings put global animator_duration_scale 0 &
- adb shell input keyevent 82 &
script: ./gradlew connectedAndroidTest # Run emulator tests
Now my travis build takes 20 minutes :D
As a reference, a good place to check a working example is the U+2020 project.
I have python wrapper-library for adb where I have unit-test which depend on emulator or real device (since they execute adb commands).
I want also to use Travis CI as build environment along with executing those unit tests for each build.
Is there a way to have android emulator available somewhow in Travis CI, so that unit tests can execute adb commands?
Thanks in advance!
According to the Travis CI documentation, you can start an emulator with the following script in your .travis.yml:
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
Just specify the system image you need in components.
Bruno Parmentier's answer includes what Travis-CI is currently recommending, but I had issues with the VM running out of memory. So instead of running the emulator while the build is running, I changed my config to run the build, then start the emulator, then run the tests.
sudo: false
language: android
env:
global:
# switch glibc to a memory conserving mode
- MALLOC_ARENA_MAX=2
# wait up to 10 minutes for adb to connect to emulator
- ADB_INSTALL_TIMEOUT=10
android:
components:
- platform-tools
- extra-android-m2repository
- build-tools-22.0.1
- android-22
- sys-img-armeabi-v7a-android-22
script:
- ./gradlew assemble lint
after_script:
# Emulator Management: Create, Start and Wait
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
# now run the tests
- ./gradlew connectedCheck