com.android.builder.testing.api.DeviceException: N

2019-06-26 03:04发布

问题:

I have Jenkins 2.73.1 installed on my Windows 7 machine, with no slaves. There is a single job to build an android application setup. I have the connectedCheck gradle task exected as part of the job's build process.

When I restart my computer and run my Jenkins job I see this output:

23:15:46 :app:connectedDebugAndroidTest
23:15:46 Starting 166 tests on Nexus_5X_API_26(AVD) - 8.0.0
23:15:48 
23:15:48 (packages).(testclass) > testMethod[Nexus_5X_API_26(AVD) - 8.0.0] [31mFAILED [0m
23:15:48    java.lang.AssertionError
23:15:48    at org.junit.Assert.fail(Assert.java:86)

23:15:49 There were failing tests. See the report at: file:(path to app) /app/build/reports/androidTests/connected/index.html

This is totally expected - I have a failing test in place to 'test' Jenkins out!

However I often run into the following issue after 'using' the same machine to do development work (it's shared with Jenkins - I know, 100% wrong to have development and Jenkins side by side, but this is for me to learn about Jenkins really, not to have it 100% safe if at all possible, I fully understand the answer may be to isolate dev/jenkins, but maybe there are other solutions for now?). I run the simulator, unit tests, etc. and eventually Jenkins complains:

00:27:19 :app:connectedDebugAndroidTest FAILED
00:27:19 
00:27:19 FAILURE: Build failed with an exception.
00:27:19 
00:27:19 * What went wrong:
00:27:19 Execution failed for task ':app:connectedDebugAndroidTest'.
00:27:19 > com.android.builder.testing.api.DeviceException: No connected devices!
00:27:19 
00:27:19 * Try:
00:27:19 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
00:27:19 
00:27:19 BUILD FAILED
00:27:19 
00:27:19 Total time: 1 mins 1.687 secs
00:27:20 Build step 'Invoke Gradle script' changed build result to FAILURE
00:27:20 Build step 'Invoke Gradle script' marked build as failure
00:27:20 [android] Stopping Android emulator
00:27:23 [android] Archiving emulator log
00:27:23 $ D:\Android\sdk/platform-tools/adb.exe kill-server

I absolutely have the simulator running as part of the job - I'm not sure what's going on. Any thoughts?

EDIT: I am using the Android Emulator plugin 2.15 to setup my emulator during the job. It is setup using an existing emulator name. In the logs I do see it start successfully each time, and also logs stating that it is stopping the simulator/etc after the job is finished (see the logs above i.e. "[android] Stopping Android emulator" etc.)