I have found several problems with Travis CI and I have been solving them but the last one I can't.
I'm getting the common error
com.android.ddmlib.InstallException: Failed to establish session
This is my travis file:
language: android
before_install:
- chmod +x gradlew
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
- tools
- build-tools-23.0.3
# Additional components
- extra-google-m2repository
- extra-android-m2repository
# The SDK version used to compile your project
- android-23
# Specify at least one system image,
# if you need to run emulator(s) during your tests
- sys-img-armeabi-v7a-android-23
#- sys-img-x86-android-17
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 --name test --target android-23 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window -gpu off -no-boot-anim &
- android-wait-for-emulator
- adb devices
- adb shell input keyevent 82 &
script:
- echo $ADB_INSTALL_TIMEOUT
- android list target
- ./gradlew connectedAndroidTest
after_failure:
# Customize this line, 'android' is the specific app module name of this project. Shows log.
- export MY_MOD="SimpleLock"
- export MY_LOG_DIR="$(pwd)/app/build/reports/androidTests/connected/"
- pwd && cd "${MY_LOG_DIR:-.}" && pwd && ls -al
- sudo apt-get install -qq lynx && lynx --dump index.html > myIndex.log
- lynx --dump com.android.builder.testing.ConnectedDevice.html > myConnectedDevice.log
- lynx --dump com.android.builder.testing.html > myTesting.log
- for file in *.log; do echo "$file"; echo "====================="; cat "$file"; done || true
And this is my travis output: https://travis-ci.org/GarceGon/SimpleLock/builds/139367600
:app:connectedDebugAndroidTestUnable to install /home/travis/build/GarceGon/SimpleLock/app/build/outputs/apk/app-debug.apk
com.android.ddmlib.InstallException: Failed to establish session
at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:66)
at com.android.ddmlib.Device.installPackages(Device.java:901)
at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:119)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:121)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:48)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
com.android.builder.testing.ConnectedDevice > runTests[test(AVD) - 6.0] FAILED
com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to establish session
at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:129)
null
com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to establish session
at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:129)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:121)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:48)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.ddmlib.InstallException: Failed to establish session
at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:66)
at com.android.ddmlib.Device.installPackages(Device.java:901)
at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:119)
... 8 more
:app:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///home/travis/build/GarceGon/SimpleLock/app/build/reports/androidTests/connected/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2 mins 20.531 secs
The command "./gradlew connectedAndroidTest" exited with 1.
Thanks!
Solution:
Delete -no-boot-anim
option to wait for emulator ready and increase timeout to 10 minutes.
First issue:
Replace
- emulator -avd test -no-skin -no-audio -no-window -gpu off -no-boot-anim &
By
- emulator -avd test -no-skin -no-audio -no-window -gpu off &
Deleting -no-boot-anim
option, android-wait-for-emulator
script depends on boot animation to detect when the emulator is ready as I explain here.
I forked your project to confirm this on a develop branch and the Travis-CI build passed but...
Second issue:
Later I recreated the change using the master branch and the build failed...
Caused by: com.android.ddmlib.ShellCommandUnresponsiveException
You already fixed this version of the issue very well explained by Sean Barbeau:
# install timeout in minutes (2 minutes by default)
- ADB_INSTALL_TIMEOUT=8
and you also fixed another timeout issue explained here and here that needs more time, see:
Android Gradle Plugin had a hard coded timeout value that was too low.
Google fixed it (version 2.0.0-beta3):
https://code.google.com/p/android/issues/detail?id=189764
So what do we put in build.gradle to set this timeout value?
Currently it's all attached to android.adbOptions.timeOutInMs.
Sample: Google project Increasing ADB timeout and adding Travis-ci support. It works!
// This enables long timeouts required on slow environments, e.g. Travis
adbOptions {
timeOutInMs 10 * 60 * 1000 // Set the timeout to 10 minutes
installOptions "-d","-t"
}
I increased the timeout from 1 to 10 minutes like Mark McDonald did, and the build passed:
Try few things
$ adb kill-server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With