Fix dotnet run failing with multiple AVDs present - #11001
Merged
jonathanpeppers merged 3 commits intoMar 23, 2026
Conversation
When multiple AVD emulator images are defined but only one device is running, 'dotnet run' incorrectly considers all AVDs (including non-running ones) as available targets, causing a device selection prompt or error in non-interactive mode. Add FilterDevicesForSelection() to GetAvailableAndroidDevices that filters the merged device list: when any online devices exist, only online devices are returned (enabling auto-selection when a single device is running). When no online devices exist, all devices are returned including non-running emulators so the user can pick one to boot. Fixes #10998 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two-pass approach in FilterDevicesForSelection: first determine if filtering is needed, then allocate only when mixed online/offline states exist. Returns the original list when all devices share the same status. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes dotnet run device auto-selection when multiple AVDs exist by prioritizing currently online devices over non-running emulator definitions, avoiding erroneous “multiple devices available” outcomes in non-interactive runs.
Changes:
- Filter merged device/emulator list so that when any
Onlinedevices exist, only those are returned for selection. - Keep existing behavior (return all devices, including non-running emulators) when no online devices exist, so users can choose an emulator to boot.
- Add unit tests covering the filtering behavior across online/offline/unauthorized/non-running scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs | Adds FilterDevicesForSelection() and applies it after merge so online devices take priority in dotnet run selection. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAvailableAndroidDevicesTests.cs | Adds unit tests validating filtering behavior across common device state combinations. |
jonathanpeppers
approved these changes
Mar 23, 2026
jonathanpeppers
left a comment
Member
There was a problem hiding this comment.
After thinking about this, I think it is simpler to fix here than dotnet/sdk.
dotnet/sdk we'd have to introduce a new "public API" to find "online devices", which is a concern that only the Android workload really knows about.
Some workloads might not want the behavior we're adding here.
I think we should just merge this and try it. 👍
jonathanpeppers
pushed a commit
that referenced
this pull request
Mar 23, 2026
Fixes: #10998 When multiple AVD emulator images are defined but only one device is running, 'dotnet run' incorrectly considers all AVDs (including non-running ones) as available targets, causing a device selection prompt or error in non-interactive mode. Add FilterDevicesForSelection() to GetAvailableAndroidDevices that filters the merged device list: when any online devices exist, only online devices are returned (enabling auto-selection when a single device is running). When no online devices exist, all devices are returned including non-running emulators so the user can pick one to boot. ## Address review: avoid allocation when no filtering needed Two-pass approach in FilterDevicesForSelection: first determine if filtering is needed, then allocate only when mixed online/offline states exist. Returns the original list when all devices share the same status. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
When multiple AVD emulator images are defined but only one device is running,
dotnet runincorrectly considers all AVDs (including non-running ones) as available targets, causing a device selection prompt or error in non-interactive mode.Changes
Added
FilterDevicesForSelection()toGetAvailableAndroidDevicesthat filters the merged device list after the merge step:This means:
Tests
Added 8 unit tests covering:
Fixes #10998