CircleCI - Android Emulator Setup times out - android

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?

Related

./ci/android-wait-for-emulator.sh: No such file or directory

I got a gitlab-ci yaml with a build stage and a test stage. The build stage runs successfully but the test stage keeps trowing the next error:
gitlab-ci:
image: jangrewe/gitlab-ci-android
stages:
- build
- test
- export GRADLE_USER_HOME=$(pwd)/.gradle
- chmod +x ./gradlewbefore_script:
cache:
key: ${CI_PROJECT_ID}
paths:
- .gradle/
build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/apk/app-debug.apk
instrumentation_tests:
stage: test
script:
- emulator -avd testAVD -no-audio -no-window &
- ./android-wait-for-emulator.sh
- adb devices
- 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 &
- ./gradlew connectedAndroidTest
- ./ci/stop-emulators.sh
artifacts:
name: "reports_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}"
when: on_failure
expire_in: 4 days
paths:
- app/build/reports/androidTests/connected/
I've tried a couple of things but nothing seems to work, i can`t get the emulator to work correctly so if anyone has any idea or advice.

Travis CI + Android: Not accepting licenses (build timeout)

When I push to remote Travis CI starts a build, but it does never finish because licences are not accepted. I get to Accept? (y/N): line in the Travis build and it waits until timeout.
Travis file:
sudo: required
language: android
jdk: oraclejdk8
dist: trusty
android:
components:
- tools
- tools
- platform-tools
- build-tools-28.0.3
- android-28
- add-on
- extra
before_install:
- echo yes | sdkmanager "build-tools;28.0.3"
- echo yes | sdkmanager "platforms;android-28"
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo -e "\ " > "$ANDROID_HOME/licenses/android-sdk-preview-license"
- sdkmanager "system-images;android-28;google_apis;x86"
- echo no | avdmanager create avd --force -n emulatorApi28 -k "system-images;android-28;google_apis;x86"
- emulator -avd test -no-audio -no-window &
- ./gradlew dependencies || true
before_script:
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew build connectedCheck
- "./gradlew clean build connectedCheck -PdisablePreDex --stacktrace"
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
Any suggestions on why it never accepts licenses?
Just add - yes | sdkmanager --licenses >/dev/null to your before_install stage.

Travis CI cant find our gradlew file

We are trying to integrate our android app with travis CI. But it always fails with cannot access ‘gradlew’: No such file or directory. We can run the gradlew script from our local computer and the file is tracked by git. What can the problem be?
Our .travis.yml file:
sudo: false
language: android
jdk: oraclejdk8
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
before_script:
- cd TreasurePleasure
- echo no | android create avd --force -n test -t "android-"$ANDROID_EMULATOR_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
android:
components:
- tools
- tools # Running this twice get's the latest build tools (https://github.com/codepath/android_guides/wiki/Setting-up-Travis-CI)
- platform-tools
- build-tools-27.0.3
- android-27
- android-$ANDROID_EMULATOR_LEVEL
- sys-img-armeabi-v7a-google_apis-$ANDROID_EMULATOR_LEVEL
licenses:
- '.+'
env:
global:
- ANDROID_API_LEVEL=27
- ANDROID_EMULATOR_LEVEL=21
- ANDROID_BUILD_TOOLS_VERSION=27.0.3
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20
before_install:
- chmod +x gradlew
- yes | sdkmanager "platforms;android-27"
script:
- "./gradlew clean build connectedCheck -PdisablePreDex --stacktrace"
# run tests against the emulator
- ./gradlew connectedAndroidTest
# run tests against the JVM
- ./gradlew test
Most of this is copy paste since this is the first project for us that are using Travis CI.
Our error:
This is how it works in my scripts:
before_script:
- cd ${TRAVIS_BUILD_DIR}/TreasurePleasure
- chmod +x ./gradlew
script: "./gradlew assemble"

Travis CI android emulator can't be created with avdmanager

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.

Trying to run a CI server with an emulator

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

Categories

Resources