I'm trying to build & test my project on Travis CI. It keeps showing me same repetitive output every time on all my repositories.
Here is my travis.yml https://github.com/carts-uiet/cartsbusboarding/blob/master/.travis.yml
language: android
android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
# - platform-tools
# - tools
# The BuildTools version used by your project
- build-tools-21.0.0
# The SDK version used to compile your project
- android-21
# Additional components
- add-on
- extra
# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-armeabi-v7a-android-21
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
Here is one such build https://travis-ci.org/carts-uiet/cartsbusboarding/builds/39447907
$ javac -version
javac 1.7.0_60
before_script.1
3.53s$ echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
Android 5.0 is a basic Android platform.
Do you wish to create a custom hardware profile [no]Created AVD 'test' based on Android 5.0, ARM (armeabi-v7a) processor,
with the following hardware config:
hw.cpu.model=cortex-a8
hw.lcd.density=240
hw.ramSize=512
vm.heapSize=48
before_script.2
0.01s
$ emulator -avd test -no-skin -no-audio -no-window &
$ android-wait-for-emulator
Failed to Initialize backend EGL display
emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
error: device offline
error: device offline
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
error: device offline
error: device offline
running
running
running
running
running
running
All these builds time-out.
What am I doing wrong here?
Updated response: VM images already include fixed android-wait-for-emulator script and android SDK tools version 24.0.0 by default solving this issue. I deleted my outdated response and workaround.
Build Environment Updates - 2014-12-09
This sounds like the best alternative to get the latest version of the script:
I added this to my before script:
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- curl http://is.gd/android_wait_for_emulator > android-wait-for-emulator
- chmod u+x android-wait-for-emulator
- ./android-wait-for-emulator
- adb shell input keyevent 82 &
The url points to the latest script available on github.
Hope that helps . . .
You need to instruct your travis build to actually run unit tests:
# run tests against the emulator
- ./gradlew connectedAndroidTest
# run tests against the JVM
- ./gradlew test
Related
I'd like to run an Android test on Travis CI but seems like the emulator does not connect to the network. Does Travis CI's Android Emulator support using the network? If so, how to configure .travis.yml to enable this feature?
My app uses Firebase Cloud Messaging, which will retrieve a token when the app is opened. My Android test is to see if my app successfully get the token 10 seconds after the app is opened. I can pass the test locally but fails when it's on Travis CI's emulator. That's why I suspect that the emulator cannot connect to the network.
My .travis.yml is:
language: android
jdk: oraclejdk8
sudo: required # For faster internet speeds and more memory
android:
components:
- tools
- tools
# The BuildTools version used by your project
- build-tools-26.0.2
# The SDK version used to compile your project
#- Android-24
- android-22
# Specify at least one system image,
# if you need to run the emulator(s) during your tests
- sys-img-armeabi-v7a-android-22
#https://docs.travis-ci.com/user/languages/android/#Caching
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:
- echo y | ${ANDROID_HOME}/tools/bin/sdkmanager --channel=3 "tools" "platform-tools" "build-tools;26.0.1" "platforms;android-26" "extras;google;m2repository"
# Emulator Management: Create, Start and Wait
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script: ./build.sh
I'm currently trying to get a travis.yml that works for Android 24 / build tools 24.0.3 and having some trouble.
I have the following for my travis.yml:
language: android
sudo: required
jdk: oraclejdk8
cache:
directories:
- ${TRAVIS_BUILD_DIR}/gradle/caches/
- ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/
env:
global:
- ANDROID_API_LEVEL=24
- ANDROID_BUILD_TOOLS_VERSION=24.0.3
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)
android:
components:
- tools # to get the new `repository-11.xml`
- platform-tools
- tools # to install Android SDK tools 25.1.x
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_API_LEVEL
# For Google APIs
- addon-google_apis-google-$ANDROID_API_LEVEL
# Support library
- extra-android-support
# Latest artifacts in local repository
- extra-google-m2repository
- extra-android-m2repository
# Specify at least one system image
- sys-img-armeabi-v7a-google_apis-$ANDROID_API_LEVEL
before_script:
- echo no | android create avd --force -n test -t "android-"$ANDROID_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-skin -no-window &
- android-wait-for-emulator
script:
- ./gradlew clean jacocoDebugTestReport
My current issue is that I keep getting:
: No compatible devices connected.[TestRunner] FAILED Found 1 connected device(s), 0 of which were compatible. :app:connectedDebugAndroidTest FAILED
or:
No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
which are two completely separate error states.
Does anyone see anything glaringly wrong or incorrect about my travis.yml that could help explain why it's not working.
Add travis_wait followed by the desired minutes to wait to fix the second issue.
before_script:
- echo no | android create avd --force -n test -t "android-"$ANDROID_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-skin -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- travis_wait 20 ./gradlew clean jacocoDebugTestReport
If you fix the first issue, probably you wont need the previous solution.
The line below is normally necessary, I didn't test it on android-24 and I would need to see a full log
- adb shell input keyevent 82 &
As a workaround, I would use a lower API level as suggested here until you find a better solution.
I have spent a lot of free time the last two years trying to find solutions to this type of issues and the best you can do is to use ci builds for lower APIs and devices or local tests for recent APIs.
The benefits of using latest APIs are not enough if you consider the time required to solve issues.
Elaborating on what Ardock posted, I was able to get around my issue by lowering the emulators SDK level. My working travis.yml is:
language: android
jdk: oraclejdk8
sudo: false
android:
components:
- platform-tools
- tools
- build-tools-24.0.3
- android-22
- android-24
- sys-img-armeabi-v7a-android-22
- extra-android-m2repository
- extra-android-support
- extra-google-m2repository
before_script:
# Create and start emulator
- 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 &
script: ./gradlew clean connectedAndroidTest -PdisablePreDex --stacktrace
It's not super elegant having to download and install multiple SDKs, but https://github.com/isuPatches/WiseFy/commits/master
and https://travis-ci.org/isuPatches/WiseFy/builds show that it's working.
I am trying to set up Travis for Android. Running the build seems to work so far, but when it comes to the tests, it complains about "No connected devices!"
:app:connectedAndroidTestDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:connectedAndroidTestDebug'.
> com.android.builder.testing.api.DeviceException: java.lang.RuntimeException:
No connected devices!
Here is my .travis.yml, and from what I understand, I am creating and starting an emulator for the tests, just the way as the documentation says.
language: android
android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
# - platform-tools
# - tools
# The BuildTools version used by your project
- build-tools-22.0.1
# The SDK version used to compile your project
- android-22
# Additional components
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
# - addon-google_apis-google-19
# - add-on
# - extra
# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-armeabi-v7a-android-22
# - sys-img-x86-android-17
licenses:
- 'android-sdk-license-.+'
# Emulator Management: Create, Start and Wait
before_script:
- 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 &
Can you tell me what I'm doing wrong and how to fix it?
Unfortunately i am not allowed to comment, as i just want to complete DominicJodoin's answer. Correct indentation and a longer ADB_INSTALL_TIMEOUT is necessary as DominicJodoin already stated.
In my opinion your Emulator is running but not ready to install an apk. With - adb wait-for-device you wait until the device connected. According to the Documentation this means:
Note that this command does not cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system.
Try replacing this line with - android-wait-for-emulator in your travis.yml instead.
Travis.yml
language: android
jdk: oraclejdk7
cache:
directories:
- node_modules
sudo: false
android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
# - platform-tools
# - tools
# The BuildTools version used by your project
- build-tools-22.0.1
# The SDK version used to compile your project
- android-22
# Additional components
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
# - addon-google_apis-google-19
# - add-on
# - extra
# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-armeabi-v7a-android-21
# - sys-img-x86-android-17
licenses:
- 'android-sdk-license-.+'
env:
global:
# install timeout in minutes (2 minutes by default)
- ADB_INSTALL_TIMEOUT=8
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- android list target
- ./gradlew connectedAndroidTest
I think your problem is the sys-img-armeabi-v7a-android-22 image is not available yet on Travis CI.
Indeed if you run the following command on Travis CI: android list target, the output for android-22 shows no Tag/ABIs : no ABIs.
I would suggest you try running your tests on the sys-img-armeabi-v7a-android-21 in the meantime.
You can have a look at a sample Android project with unit tests I forked and ran successfully with your components but with sys-img-armeabi-v7a-android-21 image on Travis CI:
Sample project
Travis CI build log
Hope this helps!
Edit: android-22 image should be available shortly on Travis CI. See the following pull request.
I wanted to use a more recent emulator. Unfortunately I wasn't able to make it work on android-26 or 27, but I was able to make it work on android-25. The ABI names were changed. Here's what works for me:
language: android
jdk:
- oraclejdk8
env:
global:
- ANDROID_BUILD_TOOLS_VERSION=26.0.2
- ANDROID_ABI=arm64-v8a
- ANDROID_TAG=google_apis
- ANDROID_API_LEVEL=26
- EMULATOR_API_LEVEL=25
- ADB_INSTALL_TIMEOUT=8 # minutes (2 minutes by default)
android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
- tools
- platform-tools
- tools
# The BuildTools version used by your project
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
# The SDK version used to compile your project
- android-$ANDROID_API_LEVEL
- android-$EMULATOR_API_LEVEL
# Support library
# Latest artifacts in local repository
- extra-android-m2repository
# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-$ANDROID_ABI-$ANDROID_TAG-$EMULATOR_API_LEVEL
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/
# Emulator Management: Create, Start and Wait
before_script:
- android list targets
- echo no | android create avd --force -n test -t "android-"$EMULATOR_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -list-avds
- emulator -avd test -no-window &
- android-wait-for-emulator
- adb devices
- adb shell input keyevent 82 &
I found the key ADB_TIMEOUT_INSTALL bit in J-Bossi answer, and it starts the emulator in before_script like 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
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
I've read through com.android.builder.testing.ConnectedDevice > hasTests[test(AVD) - 5.0] FAILED and I am having a very similar problem. Unfortunately, it's very difficult to discern what the actual solution to that problem was, given all of the discussion the solution author gave.
Essentially, I have the following .travis.yml file:
language: android
android:
components:
- build-tools-21.1.0
- android-19
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- addon-google_apis-google-19
- addon-google_apis-google-21
- sys-img-armeabi-v7a-android-19
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 &
- cat `which android-wait-for-emulator`
- android-wait-for-emulator
- adb shell input keyevent 82 &
script: ./gradlew clean build connectedCheck
When I push, and travis builds the appropriate .apk, I end up with the following log: http://pastebin.com/LVw5rG58
If I run ./gradlew clean build installDebug, the build turns out fine, so it doesn't appear to be an issue with the timeout being too short in the android-wait-for-emulator script (also, it's using the newer version, I've checked - see the cat which android-wait-for-emulator command in the .travis.yml.
Additionally, I do have a single test in my source repository, and running ./gradlew clean build connectedCheck on my local development machine (with a phone attached) works fine.
This just started happening since I updated gradle to 2.2.1 and updated the build tools to 21.1.0. However, I have another project using the exact same .travis.yml that isn't failing for some reason.
Edit:
My application has the following directory structure:
wagebase-android/
- WageBase/
- src/
- androidTest/
- java/
- com.thisclicks.wagebase/ <- Test Sources
- main/
- java/
- com.thisclicks.wagebase/ <- App sources
Edit:
It appears that if I run this on a local emulator, it also fails with the same error. I used the same configuration as in Travis, i.e.:
$ echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
$ emulator -avd test -no-skin -no-audio -no-window &
$ adb wait-for-device
$ ./gradlew connectedCheck
About Unable to find instrumentation target package: com.thisclicks.wagebase:
If wagebase is a Project Library, check the first response, otherwise the second response here:
unable-to-find-instrumentation-target-package-com-xyz.
You have to create and setup an Application Project that depends on
the Library Project, in order to test the Library Project.
When you create android test project remember to set good target
package
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test" <-------------------
If you run gradle installDebug --debug you'll know more about the error (share the log here), perhaps an installation issue. And you can show androidTest logs as I do here, line 3848
cat ${TRAVIS_BUILD_DIR}/*/build/outputs/androidTest-results/connected/*
About dependencies, I think that you don't need extra-google-google_play_services included in extra-google-m2repository. You can check a working travis.yml file for google apis here.
android:
components:
- build-tools-21.1.2
- android-21
- addon-google_apis-google-21
- extra-google-m2repository
- extra-android-m2repository
- sys-img-armeabi-v7a-addon-google_apis-google-21
before_install:
- echo no | android create avd --force -n test -t "Google Inc.:Google APIs:21" --abi google_apis/armeabi-v7a