[dotnet run] ComputeAvailableDevices lists available emulators and auto-boot on deploy#10826
Draft
jonathanpeppers wants to merge 7 commits intomainfrom
Draft
[dotnet run] ComputeAvailableDevices lists available emulators and auto-boot on deploy#10826jonathanpeppers wants to merge 7 commits intomainfrom
ComputeAvailableDevices lists available emulators and auto-boot on deploy#10826jonathanpeppers wants to merge 7 commits intomainfrom
Conversation
…auto-boot on deploy Fixes: #10702 Context: IDEs (Visual Studio) handle emulator discovery and boot through the commercial `android-platform-support` repo. The key files are: - `src/Mono.AndroidTools/Internal/AvdWatcher.cs`: https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/Internal/AvdWatcher.cs Uses `FileSystemWatcher` on `~/.android/avd/*.ini` to discover AVDs (no `emulator -list-avds` call). Parses `.ini` files to load AVD metadata. - `src/Mono.AndroidTools/AndroidVirtualDeviceManager.cs`: https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/AndroidVirtualDeviceManager.cs Manages the full AVD lifecycle. `GetRunArguments()` constructs emulator launch arguments (`-avd`, `-netfast`, `-no-snapshot-load`, etc.). - `src/Mono.AndroidTools/AndroidVirtualDevice.cs`: https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/AndroidVirtualDevice.cs Loads AVD config from `.ini` files, reads `avd.ini.displayname` for friendly names, parses API level from target strings. - `src/Mono.AndroidTools/AndroidDeviceManager.cs`: https://devdiv.visualstudio.com/DevDiv/_git/android-platform-support?path=/src/Mono.AndroidTools/AndroidDeviceManager.cs Tracks connected devices via `adb track-devices` (persistent connection). This PR provides a simpler MSBuild-only equivalent for `dotnet run`: - `emulator -list-avds` instead of filesystem watchers for AVD discovery - `BootAndroidEmulator` task instead of IDE-level process management - Display names derived from AVD folder names (underscores to spaces, title case) instead of parsing `config.ini`/`avd.ini.displayname` Changes: - Extended `GetAvailableAndroidDevices` task to query `emulator -list-avds` and merge not-running emulators with `adb devices` output, sorted with online devices first, then offline emulators alphabetically. - Added `EmulatorToolPath`/`EmulatorToolExe`/`AdbToolExe` properties to `_ResolveMonoAndroidSdks` (ported `AdbToolPath` from `CreateProperty`). - Added `BootAndroidEmulator` task to boot a not-running AVD and wait for it to come online, resolving the ADB serial (e.g. `emulator-5554`). - Added `_EnsureDeviceBooted` target (`BeforeTargets=_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle`) so selecting a not-running emulator auto-boots it before deploy. - Updated `Resources.Designer.cs` by opening the resx in Visual Studio to regenerate it (the designer file was stale) and discarding whitespace changes.
There was a problem hiding this comment.
Pull request overview
This PR enables dotnet run to discover and auto-boot Android emulators, addressing issue #10702. The implementation adds emulator discovery via emulator -list-avds and automatic emulator booting when deploying to a not-running emulator.
Changes:
- Extended
GetAvailableAndroidDevicesto query available emulators and merge them with running devices - Added
BootAndroidEmulatortask to boot emulators and wait for them to come online - Updated MSBuild properties and targets to support emulator tool paths and auto-boot integration
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/Xamarin.Android.Build.Tasks/Tasks/GetAvailableAndroidDevices.cs |
Added emulator listing via emulator -list-avds, AVD name retrieval, and device/emulator merging logic with sorting |
src/Xamarin.Android.Build.Tasks/Tasks/BootAndroidEmulator.cs |
New task to boot emulators, detect running status, wait for full boot completion, and resolve ADB serials |
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAvailableAndroidDevicesTests.cs |
Added comprehensive tests for emulator merging, duplicate detection, sorting, and case-insensitive matching |
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets |
Added BootAndroidEmulator task declaration, _EnsureDeviceBooted target to auto-boot emulators before deployment, and emulator tool properties to ComputeAvailableDevices |
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets |
Defined AdbToolPath, AdbToolExe, EmulatorToolPath, and EmulatorToolExe properties with OS-specific defaults |
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx |
Added error messages XA0143-XA0145 for emulator boot failures and timeouts |
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs |
Regenerated designer file to add new error code properties and update tool version to 18.0.0.0 |
.github/copilot-instructions.md |
Added guideline to avoid #region/#endregion in C# code |
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported
....Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… to fix circular dependency
…ndroidSdkDirectory _EnsureDeviceBooted cannot use DependsOnTargets='_ResolveMonoAndroidSdks' because in commercial builds _GetPrimaryCpuAbi is in _ResolveMonoAndroidSdksDependsOn, creating a cycle. Instead, restore BeforeTargets='_GetPrimaryCpuAbi' so AdbTarget is correct, and let BootAndroidEmulator compute tool paths from AndroidSdkDirectory (which is available because _ResolveSdks runs earlier in the dependency chain).
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #10702
Context: IDEs (Visual Studio) handle emulator discovery and boot through the commercial
android-platform-supportrepo. The key files are:src/Mono.AndroidTools/Internal/AvdWatcher.cs: UsesFileSystemWatcheron~/.android/avd/*.inito discover AVDs (noemulator -list-avdscall). Parses.inifiles to load AVD metadata.src/Mono.AndroidTools/AndroidVirtualDeviceManager.cs: Manages the full AVD lifecycle.GetRunArguments()constructs emulator launch arguments (-avd,-netfast,-no-snapshot-load, etc.).src/Mono.AndroidTools/AndroidVirtualDevice.cs: Loads AVD config from.inifiles, readsavd.ini.displaynamefor friendly names, parses API level from target strings.src/Mono.AndroidTools/AndroidDeviceManager.cs: Tracks connected devices viaadb track-devices(persistent connection).This PR provides a simpler MSBuild-only equivalent for
dotnet run:emulator -list-avdsinstead of filesystem watchers for AVD discoveryBootAndroidEmulatortask instead of IDE-level process managementconfig.ini/avd.ini.displaynameChanges:
Extended
GetAvailableAndroidDevicestask to queryemulator -list-avdsand merge not-running emulators withadb devicesoutput, sorted with online devices first, then offline emulators alphabetically.Added
EmulatorToolPath/EmulatorToolExe/AdbToolExeproperties to_ResolveMonoAndroidSdks(portedAdbToolPathfromCreateProperty).Added
BootAndroidEmulatortask to boot a not-running AVD and wait for it to come online, resolving the ADB serial (e.g.emulator-5554).Added
_EnsureDeviceBootedtarget (BeforeTargets=_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle) so selecting a not-running emulator auto-boots it before deploy.Updated
Resources.Designer.csby opening the resx in Visual Studio to regenerate it (the designer file was stale) and discarding whitespace changes.