dotnet / dotnet/android

GetEmulatorAvdNameAsync should fallback to getprop when adb emu avd name returns empty

Open
#12,078 1 comment 0 reactions 0 assignees View on GitHub
android-tools bug needs-triage
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 21h
Merged PRs (30d)
257

Description

## Problem

`AdbRunner.GetEmulatorAvdNameAsync()` uses `adb -s emu avd name` to resolve the AVD name of a running emulator. On ADB v36.0.0, this command returns empty output (exit code 0) — causing `MergeDevicesAndEmulators()` to fail deduplication, resulting in duplicate device entries (one running without AVD name + one "Not Running" from `emulator -list-avds`).

## Root Cause

`adb emu avd name` returns empty on adb v36.0.0:
```
$ adb -s emulator-5554 emu avd name
(empty output, exit code 0)
```

But the correct name is available via shell property:
```
$ adb -s emulator-5554 shell getprop ro.boot.qemu.avd_name
MAUI_Emulator_API_36
```

## Proposed Fix

In `GetEmulatorAvdNameAsync()`, add a fallback:
1. Try `adb emu avd name` (existing behavior)
2. If result is null/empty, try `adb shell getprop ro.boot.qemu.avd_name`
3. Return the first non-empty result

## Impact

This is a **pre-existing bug on main** — confirmed by testing `dotnet run` on dotnet/android main branch with an emulator running: same duplicate listing occurs. Not caused by the EmulatorRunner feature branch.

The same fix is also needed in `dotnet/android`'s `GetAvailableAndroidDevices.GetEmulatorAvdName()` which has identical logic.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.