Travis-CI implementation of Android SDK 25 with Emulator - android

I need help with implementing Travis-CI in my android repository.
My Project is compiled with SDK 25 but is downwards compatible to Version 21.
How do I have to change my .travis.yml to run an android emulator thats compatible with that SDK Version?
.travis.yml:
language: android
jdk: oraclejdk8
android:
components:
- tools # to get the new `repository-11.xml`
- tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943)
- platform-tools
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- addon-google_apis-google-19
- build-tools-25.0.0
- android-25
# - sys-img-armeabi-v7a-android-22
before_script:
#- android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-25,sys-img-x86_64-android-25
# - 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 build connectedCheck
Right now it exits with the "no connected devices"-Error, which makes sense, because there is no emulator running. But when I tried it using the android-22 emulator it also crashed with an error like "Android SDK 22 not installed"
EDIT:
The commented lines in the travis.yml didn't work, that's why they are commented out.

For such properties that we have in our project:
compileSdkVersion 25
minSdkVersion 21
targetSdkVersion 25
We use such emulator:
echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a --skin 480x800
No special deps are required in travis.yml besides:
- tools
- platform-tools
- build-tools-25.0.1
- android-25
- extra-android-m2repository
Here is out repository with min SDK 19:
https://github.com/elpassion/el-peon-android

I only answer the android-22 part because I'm not using Travis-ci with recent versions of Android:
language: android
jdk: oraclejdk8
android:
components:
- tools # to get the new `repository-11.xml`
- tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943)
- platform-tools
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- build-tools-25.0.0
- android-25
- android-22 # Android platform used by your alternative emulator
- sys-img-armeabi-v7a-android-22
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 &
script:
- ./gradlew build connectedCheck

Related

Travis Android build fails due to "Target id is not valid."

I want to run android tests on a connected device. This is my .travis.yml file:
language: android
jdk: oraclejdk8
env:
global:
- ADB_INSTALL_TIMEOUT=10
before_cache:
- cd ${TRAVIS_BUILD_DIR}/gradle/caches/
- find . -name "*.lock" -exec rm -rfv {} \;
- cd ${TRAVIS_BUILD_DIR}
cache:
directories:
- ${TRAVIS_BUILD_DIR}/gradle/caches/
- ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/
notifications:
email: false
android:
components:
- tools
- build-tools-25.0.2
- platform-tools
- tools
- sys-img-armeabi-v7a-android-22
install:
- echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
- echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"
# Show version and download Gradle Wrapper if it's not already cached
- ./gradlew --version
# Check components status
- sdkmanager --list || true
# 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-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- android list target
- ./gradlew build connectedCheck test jacocoTestReport
after_script:
# Show lint results
- cat ${TRAVIS_BUILD_DIR}/*/build/reports/lint-results.xml
after_success:
- bash <(curl -s https://codecov.io/bash)
Here is the build log https://travis-ci.org/mueller-ma-bot/openhab.android/builds/311512604?utm_source=github_status&utm_medium=notification
Check this line in the build log:
Skipping 'ARM EABI v7a System Image, Android API 22, revision 2'; it
depends on 'SDK Platform Android 5.1.1, API 22, revision 2' which was
not installed.
Install missing platform:
android:
components:
- tools
- build-tools-25.0.2
- platform-tools
- tools
- android-22
- sys-img-armeabi-v7a-android-22

Test espresso with Travis

I am trying to test integration tests with Travis-CI. I have the yml:
language: android
jdk: oraclejdk8
sudo: false
android:
components:
- platform-tools
- tools
- build-tools-25.0.2
- android-25
- sys-img-armeabi-v7a-android-22
#Extras
- extra-android-m2repository
- extra-google-m2repository
- extra-android-m2repository
before_script:
- android list targets
- 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 test
- ./gradlew connectedAndroidTest
script: "./travis-build.sh"
This should work, but I am always getting:
Error: Target id is not valid. Use 'android list targets' to get the target ids.
I have no idea how to fix this problem...
Any help is appreciated
Old VM (used with sudo: false) only include platforms up to android-21, please try this
language: android
jdk: oraclejdk8
sudo: false
android:
components:
- platform-tools
- tools
- build-tools-25.0.2
- android-22 # Android platform used by your alternative emulator
- android-25
- sys-img-armeabi-v7a-android-22
#Extras
- extra-android-m2repository
- extra-google-m2repository # Removed duplicated component
before_script:
- android list targets
- 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 test
- ./gradlew connectedAndroidTest
script: "./travis-build.sh"

Travis CI Build Fails for android-20 and android-22

I want to test my code from android-15 to android-23, but unfortunately build fails for android-20 and android-22.
Error: Invalid --tag default for the selected target.
The command "echo no | android create avd --force -n test -t
$ANDROID_TARGET --abi $ANDROID_ABI" failed and exited with 1 during .
travis file :
language: android
sudo: false
jdk: oraclejdk7
os:
- linux
android:
components:
- platform-tools
- tools
- build-tools-23.0.3
- android-23
# Additional components
- extra
- extra-google-m2repository
- extra-android-m2repository
- extra-android-support
# Images
- sys-img-${ANDROID_ABI}-${ANDROID_TARGET}
env:
matrix:
- ANDROID_SDKS=android-15 ANDROID_TARGET=android-15 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-16 ANDROID_TARGET=android-16 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-17 ANDROID_TARGET=android-17 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-18 ANDROID_TARGET=android-18 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-20 ANDROID_TARGET=android-20 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-21 ANDROID_TARGET=android-21 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-22 ANDROID_TARGET=android-22 ANDROID_ABI=armeabi-v7a
- ANDROID_SDKS=android-23 ANDROID_TARGET=android-23 ANDROID_ABI=armeabi-v7a
global:
# wait up to 10 minutes for adb to connect to emulator
- ADB_INSTALL_TIMEOUT=10
cache:
directories:
- $HOME/.gradle/caches/2.10
- $HOME/.gradle/caches/jars-1
- $HOME/.gradle/daemon
- $HOME/.gradle/native
- $HOME/.gradle/wrapper
before_install:
- chmod +x gradlew
before_script:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
script:
- android-wait-for-emulator
- adb devices
- adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
- adb shell input keyevent 82 &
- ./gradlew connectedCheck
travis result
How fix it?
The Android 20 SDK target is for KitKat4.4 wearables and has a slightly different system image with abi prefix that is causing the error.
Under the #images you can add the image provided by Travis-CI
- sys-img-armeabi-v7a-android-wear-20
In the android 20 matrix script you will have to add android-wear/armeabi-v7
- ANDROID_SDKS=android-20 ANDROID_TARGET=android-20 ANDROID_ABI=android-wear/armeabi-v7a

Travis CI Android Tests: no connected devices

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

"Invalid --abi armeabi-v7a for the selected target" with Google APIs

I'm trying to update an Android project from using the API Level 19 SDK and build tools to the newest API Level 21, including the Google APIs. Everything was running fine on Travis prior to this update (for example, see this build).
When I run with the new API level I see the following error:
0.42s$ echo no | android create avd --force -n test -t "Google Inc.:Google APIs:"$ANDROID_API_LEVEL --abi $ANDROID_ABI
Valid ABIs: no ABIs.
Error: Invalid --abi armeabi-v7a for the selected target.
The command "echo no | android create avd --force -n test -t "Google Inc.:Google APIs:"$ANDROID_API_LEVEL --abi $ANDROID_ABI" failed and exited with 1
See this build for the full Travis output.
Here's my .travis.yml:
language: android
jdk: oraclejdk7
# Turn off caching to avoid any caching problems
cache: false
# Use the Travis Container-Based Infrastructure (see #203)
sudo: false
env:
global:
- ANDROID_API_LEVEL=21
- ANDROID_BUILD_TOOLS_VERSION=21.1.2
- ANDROID_ABI=armeabi-v7a
android:
components:
- platform-tools
- tools
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_BUILD_TOOLS_VERSION
# For Google Maps API v1
- addon-google_apis-google-$ANDROID_API_LEVEL
# Google Play Services
- extra-google-google_play_services
# 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-android-$ANDROID_BUILD_TOOLS_VERSION
before_script:
# Create and start emulator
- echo no | android create avd --force -n test -t "Google Inc.:Google APIs:"$ANDROID_API_LEVEL --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
script:
- ./wait_for_emulator
- ./gradlew connectedCheck -PdisablePreDex
My build.gradle is here.
Again, the only thing I changed in the new Travis build is the API level and build tools level.
Apparently the names of the Google APIs system images and ABI parameters changed:
ABI = armeabi-v7a to google_apis/armeabi-v7a
System image = sys-img-armeabi-v7a-android-21 to sys-img-armeabi-v7a-addon-google_apis-google-21
I fixed this by updating both my ANDROID_ABI variable and component name for the system image - new values are:
- ANDROID_ABI=google_apis/armeabi-v7a
...
# Specify at least one system image,
- sys-img-armeabi-v7a-addon-google_apis-google-$ANDROID_API_LEVEL
Here's the whole section in context:
env:
global:
- ANDROID_API_LEVEL=21
- ANDROID_BUILD_TOOLS_VERSION=21.1.2
- ANDROID_ABI=google_apis/armeabi-v7a
android:
components:
- platform-tools
- tools
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_API_LEVEL
# For Google Maps API v1
- addon-google_apis-google-$ANDROID_API_LEVEL
# Google Play Services
- extra-google-google_play_services
# 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-addon-google_apis-google-$ANDROID_API_LEVEL
After these changes, it builds successfully.
EDIT Sept 12th, 2016
Apparently there was another change in mid-2016 that causes this same problem. For example, here's a failed build with the same error message.
The following changes were needed to fix Travis builds:
Add separate ANDOID_TAG ABI tag variable
Duplicate tools to get the new repository-11.xml and to install Android SDK tools 25.1.x
Change system image names to match new Android SDK
Change emulator start command to use new ABI tag variable to specify Google APIs
For example:
- ANDROID_ABI=google_apis/armeabi-v7a
...changed to:
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- tools needs to be listed twice.
The system images:
- sys-img-armeabi-v7a-addon-google_apis-google-23
- sys-img-armeabi-v7a-addon-google_apis-google-23
...needed to be changed to:
- sys-img-armeabi-v7a-google_apis-23
- sys-img-armeabi-v7a-google_apis-23
The line to start the emulator changed from:
- echo no | android create avd --force -n test -t "Google Inc.:Google APIs:23" --abi $ANDROID_ABI
...to:
- echo no | android create avd --force -n test -t "android-23" --abi $ANDROID_ABI --tag $ANDROID_TAG
See this commit for a changeset of what needs to be changed, this file for a fully working script, and see https://github.com/travis-ci/travis-ci/issues/6122#issuecomment-239073557 for details.
Thanks to #Ardock for the fixes!
EDIT Nov 28th, 2016
I seems that API Level 23 emulator is currently not working on Travis with the above - android create avd --force -n test -t "android-23" --abi "armeabi-v7a" --tag "google_apis" yields the error Error: Invalid --tag google_apis for the selected target. For more details see https://github.com/OneBusAway/onebusaway-android/issues/720.
Also, apparently ARM ABIs aren't currently available for API Level 24 or 25 (Android 7.1.1) - see this issue for a screenshot of SDK Manager.
Posted issue to Android Studio Google+ Community here:
https://plus.google.com/+SeanBarbeau/posts/adNGGtJFhvi?sfc=true
A little late to the party but this still remains an issue and the only way I have found around it is by using android-22 on the emulator.
This is my .travis.yml for reference.
language: android
notifications:
email: false
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y pax
env:
global:
- ANDROID_API_LEVEL=26
- ANDROID_BUILD_TOOLS_VERSION=26.0.1
- ANDROID_EMU_API_LEVEL=22
- ANDROID_ABI=armeabi-v7a
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)
- QEMU_AUDIO_DRV=none # Remove audio
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
android:
components:
- tools
- platform-tools
- tools
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_API_LEVEL
- android-$ANDROID_EMU_API_LEVEL
- extra-android-support
- sys-img-$ANDROID_ABI-google_apis-$ANDROID_EMU_API_LEVEL
before_script:
- echo -e "Host github.com\n\tHostName github.com\n\tUser git\n\tIdentityFile ~/.ssh/id_travisci\n" >> ~/.ssh/config
- echo no | android create avd --force -n test -t android-$ANDROID_EMU_API_LEVEL --abi google_apis/$ANDROID_ABI
- emulator -avd test -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew clean installDebug
- ./gradlew check
- ./gradlew testDebugUnitTest
- ./gradlew connectedDebugAndroidTest

Categories

Resources