I'm setting up a Jenkins node (on Mac OS X) running instrumentation tests for my Android app.
My Jenkins project starts an Android emulator and runs the Gradle task :app:connectedAndroidTest
. But the task has always been unstable, sometimes being able to run the tests just fine, but most of the times failing with the following error:
:app:connectedAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:connectedAndroidTest'.
> com.android.builder.testing.api.DeviceException: No connected devices!
After some investigation, I found that:
- The issue only occurs on that machine; on my machine (another Mac OS X), the task has always worked as expected, inside and outside Android Studio;
- The issue occurs outside Jenkins, i.e. by manually starting the emulator and running the Gradle task from the command line;
- Even though the Jenkins output warned about using nonstandard ports, the issue occurs even when using the more usual 5554-5555;
adb devices
shows the emulator in online state;adb shell am instrument
works fine too;
Therefore I can say that the problem is that :app:connectedAndroidTest
doesn't detect the running emulator.
I already half-made a shell script that installs the APKs and runs am instrument
, but the latter doesn't produce a JUnit-compatible output.
So before doing additional work, I wonder how can I "repair" that Gradle task so that it detects the emulator. I'm also happy to get advice to further pinpoint the problem, e.g. to find out why the Gradle task works on my machine.