# MauiAndroidExtensions Methods

- Package: [Aspire.Hosting.Maui](/reference/api/csharp/aspire.hosting.maui.md)
- Type: [MauiAndroidExtensions](/reference/api/csharp/aspire.hosting.maui/mauiandroidextensions.md)
- Kind: `Methods`
- Members: `6`

Provides extension methods for adding Android platform resources to MAUI projects.

## AddAndroidDevice(IResourceBuilder<MauiProjectResource>)

- Name: `AddAndroidDevice(IResourceBuilder<MauiProjectResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<MauiAndroidDeviceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Maui/MauiAndroidExtensions.cs#L52-L55)

Adds an Android physical device resource to run the MAUI application on an Android device.

```csharp
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

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`.

This overload is not available in polyglot app hosts. Use [MauiAndroidExtensions.AddAndroidDevice(IResourceBuilder<MauiProjectResource>)](/reference/api/csharp/aspire.hosting.maui/mauiandroidextensions/methods.md#addandroiddevice-iresourcebuilder-mauiprojectresource) instead.

## Examples

Add an Android device to a MAUI project:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");
var androidDevice = maui.AddAndroidDevice();

builder.Build().Run();
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string)

- Name: `AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<MauiAndroidDeviceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Maui/MauiAndroidExtensions.cs#L99)

Adds an Android physical device resource to run the MAUI application on an Android device with a specific name.

```csharp
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

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`.

This overload is not available in polyglot app hosts. Use [MauiAndroidExtensions.AddAndroidDevice(IResourceBuilder<MauiProjectResource>)](/reference/api/csharp/aspire.hosting.maui/mauiandroidextensions/methods.md#addandroiddevice-iresourcebuilder-mauiprojectresource) instead.

## Examples

Add multiple Android devices to a MAUI project:

```csharp
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();
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string, string?)

- Name: `AddAndroidDevice(IResourceBuilder<MauiProjectResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<MauiAndroidDeviceResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Maui/MauiAndroidExtensions.cs#L152-L200)

Adds an Android physical device resource to run the MAUI application on an Android device with a specific name and device ID.

```csharp
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

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.

## Examples

Add multiple Android devices to a MAUI project:

```csharp
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();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddAndroidEmulator(IResourceBuilder<MauiProjectResource>)

- Name: `AddAndroidEmulator(IResourceBuilder<MauiProjectResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<MauiAndroidEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Maui/MauiAndroidExtensions.cs#L244-L247)

Adds an Android emulator resource to run the MAUI application on an Android emulator.

```csharp
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

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.

This overload is not available in polyglot app hosts. Use [MauiAndroidExtensions.AddAndroidEmulator(IResourceBuilder<MauiProjectResource>)](/reference/api/csharp/aspire.hosting.maui/mauiandroidextensions/methods.md#addandroidemulator-iresourcebuilder-mauiprojectresource) instead.

## Examples

Add an Android emulator to a MAUI project:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var maui = builder.AddMauiProject("mauiapp", "../MyMauiApp/MyMauiApp.csproj");

// Uses default/running emulator
var defaultEmulator = maui.AddAndroidEmulator();

builder.Build().Run();
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string)

- Name: `AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<MauiAndroidEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Maui/MauiAndroidExtensions.cs#L293)

Adds an Android emulator resource to run the MAUI application on an Android emulator with a specific name.

```csharp
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

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.

This overload is not available in polyglot app hosts. Use [MauiAndroidExtensions.AddAndroidEmulator(IResourceBuilder<MauiProjectResource>)](/reference/api/csharp/aspire.hosting.maui/mauiandroidextensions/methods.md#addandroidemulator-iresourcebuilder-mauiprojectresource) instead.

## Examples

Add multiple Android emulators to a MAUI project:

```csharp
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();
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string, string?)

- Name: `AddAndroidEmulator(IResourceBuilder<MauiProjectResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<MauiAndroidEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Maui/MauiAndroidExtensions.cs#L347-L395)

Adds an Android emulator resource to run the MAUI application on an Android emulator with a specific name.

```csharp
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

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.

## Examples

Add multiple Android emulators to a MAUI project:

```csharp
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();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
