MauiAndroidExtensions Methods
AddAndroidDevice(IResourceBuilder<MauiProjectResource>) Section titled AddAndroidDevice(IResourceBuilder<MauiProjectResource>) extension IResourceBuilder<MauiAndroidDeviceResource> public static class MauiAndroidExtensions{ public static IResourceBuilder<MauiAndroidDeviceResource> AddAndroidDevice( this IResourceBuilder<MauiProjectResource> builder) { // ... }}Parameters
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder. Returns
IResourceBuilder<MauiAndroidDeviceResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
dotnet run. The resource does not auto-start and must be explicitly started from the dashboard by clicking the start button. The resource name will default to "{projectName}-android-device".
This will run the application on a physical Android device connected via USB/WiFi debugging. If only one device is attached, it will automatically use that device. If multiple devices are attached, use the overload with deviceId parameter to specify which device to use. Make sure an Android device is connected and visible via adb devices.
Examples
Add an Android device to a MAUI project:
var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");var androidDevice = maui.AddAndroidDevice();
builder.Build().Run();AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string) Section titled AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string) extension IResourceBuilder<MauiAndroidDeviceResource> public static class MauiAndroidExtensions{ public static IResourceBuilder<MauiAndroidDeviceResource> AddAndroidDevice( this IResourceBuilder<MauiProjectResource> builder, string name) { // ... }}Parameters
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder. name string The name of the Android device resource. Returns
IResourceBuilder<MauiAndroidDeviceResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
dotnet run. The resource does not auto-start and must be explicitly started from the dashboard by clicking the start button. Multiple Android device resources can be added to the same MAUI project if needed, each with a unique name.
This will run the application on a physical Android device connected via USB/WiFi debugging. If only one device is attached, it will automatically use that device. If multiple devices are attached, use the overload with deviceId parameter to specify which device to use. Make sure an Android device is connected and visible via adb devices.
Examples
Add multiple Android devices to a MAUI project:
var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");var device1 = maui.AddAndroidDevice("android-device-1");var device2 = maui.AddAndroidDevice("android-device-2");
builder.Build().Run();AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string, string?) Section titled AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string, string?) extension IResourceBuilder<MauiAndroidDeviceResource> public static class MauiAndroidExtensions{ public static IResourceBuilder<MauiAndroidDeviceResource> AddAndroidDevice( this IResourceBuilder<MauiProjectResource> builder, string name, string? deviceId = null) { // ... }}Parameters
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder. name string The name of the Android device resource. deviceId string? optional Optional device ID to target a specific Android device. If not specified, uses the only attached device (requires exactly one device to be connected). Returns
IResourceBuilder<MauiAndroidDeviceResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
dotnet run. The resource does not auto-start and must be explicitly started from the dashboard by clicking the start button. Multiple Android device resources can be added to the same MAUI project if needed, each with a unique name.
This will run the application on a physical Android device connected via USB/WiFi debugging. Make sure an Android device is connected and visible via adb devices.
To target a specific device when multiple are attached, provide the device ID (e.g., "abc12345" or "192.168.1.100:5555" for WiFi debugging). Use adb devices to list available device IDs.
Examples
Add multiple Android devices to a MAUI project:
var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");
// Default device (only one attached)var device1 = maui.AddAndroidDevice("android-device-default");
// Specific device by serial numbervar device2 = maui.AddAndroidDevice("android-device-pixel", "abc12345");
// WiFi debugging devicevar device3 = maui.AddAndroidDevice("android-device-wifi", "192.168.1.100:5555");
builder.Build().Run();AddAndroidEmulator(IResourceBuilder<MauiProjectResource>) Section titled AddAndroidEmulator(IResourceBuilder<MauiProjectResource>) extension IResourceBuilder<MauiAndroidEmulatorResource> public static class MauiAndroidExtensions{ public static IResourceBuilder<MauiAndroidEmulatorResource> AddAndroidEmulator( this IResourceBuilder<MauiProjectResource> builder) { // ... }}Parameters
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder. Returns
IResourceBuilder<MauiAndroidEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
dotnet run. The resource does not auto-start and must be explicitly started from the dashboard by clicking the start button. The resource name will default to "{projectName}-android-emulator".
This will run the application on an Android emulator. Make sure you have created an Android Virtual Device (AVD) using Android Studio or avdmanager. The emulator should be running and visible via adb devices.
To target a specific emulator, use the overload that accepts an emulatorId parameter.
Examples
Add an Android emulator to a MAUI project:
var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");
// Uses default/running emulatorvar defaultEmulator = maui.AddAndroidEmulator();
builder.Build().Run();AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string) Section titled AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string) extension IResourceBuilder<MauiAndroidEmulatorResource> public static class MauiAndroidExtensions{ public static IResourceBuilder<MauiAndroidEmulatorResource> AddAndroidEmulator( this IResourceBuilder<MauiProjectResource> builder, string name) { // ... }}Parameters
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder. name string The name of the Android emulator resource. Returns
IResourceBuilder<MauiAndroidEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
dotnet run. The resource does not auto-start and must be explicitly started from the dashboard by clicking the start button. Multiple Android emulator resources can be added to the same MAUI project if needed, each with a unique name.
This will run the application on an Android emulator. Make sure you have created an Android Virtual Device (AVD) using Android Studio or avdmanager. The emulator should be running and visible via adb devices.
To target a specific emulator, use the overload that accepts an emulatorId parameter.
Examples
Add multiple Android emulators to a MAUI project:
var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");var emulator1 = maui.AddAndroidEmulator("android-emulator-1");var emulator2 = maui.AddAndroidEmulator("android-emulator-2");
builder.Build().Run();AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string, string?) Section titled AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string, string?) extension IResourceBuilder<MauiAndroidEmulatorResource> public static class MauiAndroidExtensions{ public static IResourceBuilder<MauiAndroidEmulatorResource> AddAndroidEmulator( this IResourceBuilder<MauiProjectResource> builder, string name, string? emulatorId = null) { // ... }}Parameters
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder. name string The name of the Android emulator resource. emulatorId string? optional Optional emulator ID to target a specific Android emulator. If not specified, uses the currently running emulator or starts the default emulator. Returns
IResourceBuilder<MauiAndroidEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
dotnet run. The resource does not auto-start and must be explicitly started from the dashboard by clicking the start button. Multiple Android emulator resources can be added to the same MAUI project if needed, each with a unique name.
This will run the application on an Android emulator. Make sure you have created an Android Virtual Device (AVD) using Android Studio or avdmanager. The emulator should be running and visible via adb devices.
To target a specific emulator, provide the emulator ID (e.g., "Pixel_5_API_33" or "emulator-5554"). Use adb devices to list available emulator IDs.
Examples
Add multiple Android emulators to a MAUI project:
var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");
// Default emulatorvar emulator1 = maui.AddAndroidEmulator("android-emulator-default");
// Specific Pixel 5 emulatorvar emulator2 = maui.AddAndroidEmulator("android-emulator-pixel5", "Pixel_5_API_33");
// Specific emulator by serialvar emulator3 = maui.AddAndroidEmulator("android-emulator-5554", "emulator-5554");
builder.Build().Run();