Skip to content

Use shared AdbRunner from android-tools for device listing#10880

Draft
rmarinho wants to merge 2 commits intomainfrom
feature/use-shared-adb-runner
Draft

Use shared AdbRunner from android-tools for device listing#10880
rmarinho wants to merge 2 commits intomainfrom
feature/use-shared-adb-runner

Conversation

@rmarinho
Copy link
Member

@rmarinho rmarinho commented Mar 3, 2026

Summary

Delegates the adb devices -l parsing, description building, and device/emulator merging logic from the GetAvailableAndroidDevices MSBuild task to the shared AdbRunner in Xamarin.Android.Tools.AndroidSdk (via the external/xamarin-android-tools submodule).

This removes ~200 lines of duplicated parsing/formatting/merging code from dotnet/android and consolidates it in the shared android-tools library where it can be reused by other consumers (e.g., the MAUI DevTools CLI).

Changes

  • Submodule update: external/xamarin-android-toolsfeature/adb-runner branch (b70d9d9)
  • GetAvailableAndroidDevices.cs: Rewritten to delegate to AdbRunner.ParseAdbDevicesOutput, AdbRunner.BuildDeviceDescription, and AdbRunner.MergeDevicesAndEmulators instead of having its own parsing logic. Added ConvertToTaskItems to bridge AdbDeviceInfoITaskItem.
  • GetAvailableAndroidDevicesTests.cs: Updated to use AdbRunner/AdbDeviceInfo directly instead of reflection. All 33 tests preserved with equivalent coverage.

Dependencies

Workflow

  1. Review & merge android-tools PR Bump mono to mono-4.8.0-branch commit 8864f4c and install Mono.Btls.Interface #283 (feature/adb-runner)
  2. Update this PR's submodule to android-tools main
  3. Take this PR out of draft and merge

/cc @jonathanpeppers

Delegate parsing, description building, and device/emulator merging
to AdbRunner in Xamarin.Android.Tools.AndroidSdk instead of duplicating
the logic in the MSBuild task.

- Update submodule to feature/adb-runner (b70d9d9)
- Rewrite GetAvailableAndroidDevices to use AdbRunner static methods
- Update tests to use AdbRunner/AdbDeviceInfo directly (remove reflection)
- Remove ~200 lines of duplicated parsing/formatting/merging code

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
// Parse devices from adb
var adbDevices = ParseAdbDevicesOutput (output);
// Parse devices from adb using shared AdbRunner logic
var adbDevices = AdbRunner.ParseAdbDevicesOutput (string.Join ("\n", output));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this accept an IEnumerable<string>? This will avoid created a large string object of all the lines joined with \n.

You might fix the dotnet/android-tools side to do this as well; it can create a List<string> as output comes in from stdout/stdin.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the calls here need to make it to the MSBuild logger, we lost some log messages with this change.

MSBuild tasks have a TaskLoggingHelper Log property, we need to pass this in to android-tools to use it for logging.

We could setup something like this:

https://github.com/dotnet/android-tools/blob/6a6de1f24572d93048f3bbaa997bcfcf43a472dd/src/Microsoft.Android.Build.BaseTasks/MSBuildExtensions.cs#L191-L207

So, from the MSBuild task, it passes in a Action<TraceLevel, string> for dotnet/android-tools to log with.

///
/// Parsing and merging logic is delegated to <see cref="AdbRunner"/> in Xamarin.Android.Tools.AndroidSdk.
/// </summary>
public class GetAvailableAndroidDevices : AndroidAdb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might check, maybe this doesn't need to extend AndroidAdb anymore, and can just extend AndroidTask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants