Use shared AdbRunner from android-tools for device listing#10880
Use shared AdbRunner from android-tools for device listing#10880
Conversation
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)); |
There was a problem hiding this comment.
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.
jonathanpeppers
left a comment
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this comment.
You might check, maybe this doesn't need to extend AndroidAdb anymore, and can just extend AndroidTask.
Summary
Delegates the
adb devices -lparsing, description building, and device/emulator merging logic from theGetAvailableAndroidDevicesMSBuild task to the sharedAdbRunnerinXamarin.Android.Tools.AndroidSdk(via theexternal/xamarin-android-toolssubmodule).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
external/xamarin-android-tools→feature/adb-runnerbranch (b70d9d9)AdbRunner.ParseAdbDevicesOutput,AdbRunner.BuildDeviceDescription, andAdbRunner.MergeDevicesAndEmulatorsinstead of having its own parsing logic. AddedConvertToTaskItemsto bridgeAdbDeviceInfo→ITaskItem.AdbRunner/AdbDeviceInfodirectly instead of reflection. All 33 tests preserved with equivalent coverage.Dependencies
feature/adb-runnertomainWorkflow
feature/adb-runner)main/cc @jonathanpeppers