Add Android emulator lifecycle management with automatic start #1526
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds automatic Android emulator lifecycle management to XHarness, matching the behavior of iOS simulators. When no suitable device is found, XHarness can now automatically start an emulator with the exact API level and architecture requirements, eliminating manual emulator management.
Key improvements:
--api-version)--reset-emulatorflag for data wiping and cleanup (iOS parity with--reset-simulator)Note: API version and architecture validation already existed in XHarness. This PR adds automation of emulator lifecycle, not the validation logic itself.
Usage Examples
1. Automatic emulator start with specific API level
2. Clean slate testing with data wipe
3. Architecture-specific testing
4. Helix/CI integration
Before vs After Comparison
Manual workflow (before)
Automated workflow (after)
iOS Parity Achieved
--reset-*flag for data wipeProblems solved by this PR:
Technical Implementation
New Components
EmulatorManager (
src/Microsoft.DotNet.XHarness.Android/EmulatorManager.cs)EmulatorDiagnostics (
src/Microsoft.DotNet.XHarness.Android/EmulatorDiagnostics.cs)AdbRunner.GetDeviceOrStartEmulator (
src/Microsoft.DotNet.XHarness.Android/AdbRunner.cs#L936-L1011)Integration Points
Commands now call
GetDeviceOrStartEmulatorinstead ofGetSingleDevice:Design Decisions
Opt-in behavior: Emulator start only triggered when
--api-versionspecifiedStop other emulators first: Avoids resource contention
Diagnostic collection on failure: Helps troubleshoot boot issues
Device ID takes precedence: If
--device-idspecified, never start emulatorTesting
Microsoft.DotNet.XHarness.Android.Teststests/integration-tests/Android/Emulator.Lifecycle.Tests.projRelated Issues
Closes #1459 - Add support for running workitems on specified Android emulator API levels
References #393 - Automatically create and boot Android emulators
References #1488 - Timeout on android leaves test processes running