7

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.

ris8_allo_zen0
  • 1,537
  • 1
  • 15
  • 35

2 Answers2

0

firstly clean your project,and than recreate an Android emulator,execute a cmd commond adb start-service .if fail again you should to use other's emulator in markets.

0

I'm facing the exact same problem. Any hint so far? In my former ant script, to ensure adb was connected to the device, we used to to do:

%ANDROID_SDK%-current\platform-tools\adb.exe devices
%ANDROID_SDK%-current\platform-tools\adb.exe root
%ANDROID_SDK%-current\platform-tools\adb.exe devices
%ANDROID_SDK%-current\platform-tools\adb.exe wait-for-device

This way we ensured the device would be available while testing.

Jaime
  • 83
  • 1
  • 6
  • I've finished the Bash script that emulates `cAT` also with JUnit reports, but we get no reports if the app crashes. I guess your commands have to be run after the emulator is started and before `cAT` is run? – ris8_allo_zen0 Aug 17 '17 at 10:15
  • Well, I actually use it with a real device. I think the emulator should be running before executing these commands, yes. And it should also run before cAT runs. What you can do is make cAT dinamically depend on a task that executes the commands above. – Jaime Aug 17 '17 at 11:59