Skip to content
Docs Try Aspire

MauiAndroidExtensions Methods

Class Methods 6 members
Provides extension methods for adding Android platform resources to MAUI projects.
AddAndroidDevice(IResourceBuilder<MauiProjectResource>) Section titled AddAndroidDevice(IResourceBuilder<MauiProjectResource>) extension IResourceBuilder<MauiAndroidDeviceResource>
Adds an Android physical device resource to run the MAUI application on an Android device.
public static class MauiAndroidExtensions
{
public static IResourceBuilder<MauiAndroidDeviceResource> AddAndroidDevice(
this IResourceBuilder<MauiProjectResource> builder)
{
// ...
}
}
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder.
IResourceBuilder<MauiAndroidDeviceResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method creates a new Android device platform resource that will run the MAUI application targeting the Android platform using 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.

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>
Adds an Android physical device resource to run the MAUI application on an Android device with a specific name.
public static class MauiAndroidExtensions
{
public static IResourceBuilder<MauiAndroidDeviceResource> AddAndroidDevice(
this IResourceBuilder<MauiProjectResource> builder,
string name)
{
// ...
}
}
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder.
name string The name of the Android device resource.
IResourceBuilder<MauiAndroidDeviceResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method creates a new Android device platform resource that will run the MAUI application targeting the Android platform using 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.

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>
Adds an Android physical device resource to run the MAUI application on an Android device with a specific name and device ID.
public static class MauiAndroidExtensions
{
public static IResourceBuilder<MauiAndroidDeviceResource> AddAndroidDevice(
this IResourceBuilder<MauiProjectResource> builder,
string name,
string? deviceId = null)
{
// ...
}
}
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).
IResourceBuilder<MauiAndroidDeviceResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method creates a new Android device platform resource that will run the MAUI application targeting the Android platform using 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.

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 number
var device2 = maui.AddAndroidDevice("android-device-pixel", "abc12345");
// WiFi debugging device
var 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>
Adds an Android emulator resource to run the MAUI application on an Android emulator.
public static class MauiAndroidExtensions
{
public static IResourceBuilder<MauiAndroidEmulatorResource> AddAndroidEmulator(
this IResourceBuilder<MauiProjectResource> builder)
{
// ...
}
}
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder.
IResourceBuilder<MauiAndroidEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method creates a new Android emulator platform resource that will run the MAUI application targeting the Android platform using 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.

Add an Android emulator to a MAUI project:

var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");
// Uses default/running emulator
var defaultEmulator = maui.AddAndroidEmulator();
builder.Build().Run();
AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string) Section titled AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string) extension IResourceBuilder<MauiAndroidEmulatorResource>
Adds an Android emulator resource to run the MAUI application on an Android emulator with a specific name.
public static class MauiAndroidExtensions
{
public static IResourceBuilder<MauiAndroidEmulatorResource> AddAndroidEmulator(
this IResourceBuilder<MauiProjectResource> builder,
string name)
{
// ...
}
}
builder IResourceBuilder<MauiProjectResource> The MAUI project resource builder.
name string The name of the Android emulator resource.
IResourceBuilder<MauiAndroidEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method creates a new Android emulator platform resource that will run the MAUI application targeting the Android platform using 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.

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>
Adds an Android emulator resource to run the MAUI application on an Android emulator with a specific name.
public static class MauiAndroidExtensions
{
public static IResourceBuilder<MauiAndroidEmulatorResource> AddAndroidEmulator(
this IResourceBuilder<MauiProjectResource> builder,
string name,
string? emulatorId = null)
{
// ...
}
}
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.
IResourceBuilder<MauiAndroidEmulatorResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method creates a new Android emulator platform resource that will run the MAUI application targeting the Android platform using 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.

Add multiple Android emulators to a MAUI project:

var builder = DistributedApplication.CreateBuilder(args);
var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");
// Default emulator
var emulator1 = maui.AddAndroidEmulator("android-emulator-default");
// Specific Pixel 5 emulator
var emulator2 = maui.AddAndroidEmulator("android-emulator-pixel5", "Pixel_5_API_33");
// Specific emulator by serial
var emulator3 = maui.AddAndroidEmulator("android-emulator-5554", "emulator-5554");
builder.Build().Run();