-
Notifications
You must be signed in to change notification settings - Fork 566
Description
Description
When running dotnet run --project <android-project>, the _EnsureDeviceBooted target never executes before _DeployApk, causing deployment to fail with adb: no devices/emulators found when the selected device is an unbooted AVD emulator.
Root Cause
_EnsureDeviceBooted is defined with BeforeTargets="_GetPrimaryCpuAbi;_DeployApk;_DeployAppBundle". However, the .NET SDK's dotnet run command invokes the DeployToDevice target via ProjectInstance.Build() in-process (in RunCommandSelector.TryDeployToDevice()), and the BeforeTargets hooks are not triggered in that code path.
When the same target is invoked via a separate MSBuild process (msbuild -t:DeployToDevice -p:Device=<avd>), _EnsureDeviceBooted fires correctly, boots the emulator, and deployment succeeds.
Steps to Reproduce
- Have a single AVD emulator available (not running):
emulator -list-avds→MAUI_Emulator_API_36 - Run:
dotnet run --project <android-app>.csproj - The SDK auto-selects the emulator and passes
Device=MAUI_Emulator_API_36 - Build succeeds, but
_DeployApkrunsadb installwithout-sflag → fails with "no devices/emulators found" _EnsureDeviceBootednever appears in diagnostic logs
Expected Behavior
_EnsureDeviceBooted should boot the emulator before _DeployApk runs, resolving AdbTarget to "-s emulator-5554".
Proposed Fix
Add _EnsureDeviceBooted to DeployToDeviceDependsOnTargets in Microsoft.Android.Sdk.BuildOrder.targets (before _DeployApk), so it runs via DependsOnTargets rather than relying solely on BeforeTargets. Keep the existing BeforeTargets for _GetPrimaryCpuAbi (commercial builds).