.NET MAUI Tutorial - Build your first multi-platform app in C#

Run on mobile device

You can decide to deploy to one or more of the platforms based on your development environment. You just ran and deployed your app to Windows. Now, let's set up an Android device or emulator.

Activate Hyper-V

In your Windows Search Bar, type Windows features and select Turn Windows features on or off.

Turn windows features on or off

Make sure the Hyper-V box is checked and select Ok.

Windows Features with Hyper-v box checked

You'll need to reboot your machine at this time for the change to take effect.

Android SDK Install

Open Visual Studio and your MyFirstMauiApp solution. From the debug target drop-down menu, select net8.0-android under Framework.

Select Android as target deployment

Specific versions of the Android SDK are required to build projects. If you haven't accepted the Android SDK license, you'll see the following error message on the Error List window.

Error message on the Error List window showing that the Android SDK license hasn't been accepted.

Double click the message to start the license acceptance process. Click Accept for each of the licenses present and the automatic installation will begin.

Android SDK Prompt asking user to install specific Android SDK version to build project.

Set up Android emulator

If you don't have an Android device to deploy to, you can follow these steps to set up an Android emulator. If you've already done this or want to use your own Android device, you can skip this step.

If this is your first time building a .NET MAUI application, you'll see Android Emulator selected in the debug target drop-down menu. Click it to start the creation process. If a license acceptence dialog shows up, select Accept.

Visual Studio 2022 toolbar menu showing 'Android Emulator' as the debug target.

This brings up the New Device window. Select the Create button to create an emulator with default settings. This will download the emulator images and finalize the creation of the emulator for use in Visual Studio. This step might take a while.

Don't worry if the API Level you see is different from the images. It may be 33 or higher.

Dialog to create a new Android emulator with default settings populated.

Once the emulator has been created, you'll see a button that says Start. Click it.

Android emulator manager showing that the emulator has been created and ready to run.

You may receive prompt to enable Windows Hypervisor Platform. Follow the documentation to enable acceleration to improve performance (required to get the emulator up and running). Select Run Anyway.

Prompt to enable Windows Hypervisor Platform

The Android emulator will launch and will be fully finished when you see the ability to Stop in the Android Device Manager. This may take some time.

Visual Studio 2022 toolbar menu showing the newly created Android emulator as a debug target.

Once it's fully finished, you'll see it displayed in the Visual Studio debug menu.

Visual Studio 2022 toolbar menu showing the newly created Android emulator as a debug target.

Your Android emulator has now been created and is ready to use. Next time you run Visual Studio, the emulator will appear directly in the debug target window and will start when you select it. If you ran into any issues or have performance issues with the emulator, read through the full setup documentation.

Set up Android device

To develop with your Android device, USB debugging needs to be enabled. Follow these steps on the device to connect it to Visual Studio. If you don't have an Android device, you can skip this section.

Enable developer mode

  1. Go to the Settings screen.
  2. Find Build number by using search at the top of the settings screen, or locate it in About phone.
  3. Tap Build number 7-10 times until "You are now a developer!" pops up.

Android device's settings screen on the about phone screen displaying build number.

Check USB debugging status

  1. Go to the Settings screen.
  2. Find USB debugging by using search at the top of the settings screen, or locate it in Developer options.
  3. Enable USB debugging if it isn't enabled already.

Android device's settings screen on the about developer settings screen displaying USB debugging option that is turned on.

Trust device

  1. Plug your device into your computer.
  2. You'll be prompted to Allow USB debugging.
  3. Check Always allow from this computer.
  4. Click Allow.

Android device prompt to allow USB debugging on the device from the computer.

Your device is now configured and will show up in Visual Studio as a deployment target.

Having issues? Check the documentation.

Your emulator or device should now be configured for deployment!

Run on Android

Make sure your device or emulator is selected as a debug target.

Android emulator Pixel 5 set as debug target.

From the menu, select Debug > Start Debugging (or press F5). If this option is disabled, ensure an emulator or device is selected.

Your application will build, deploy to the Android device/emulator selected, and run.

Android emulator running the .NET MAUI app. A 'Hello, .NET MAUI!' message is displayed.

You can deploy to one or more of the platforms based on your development environment. You just ran and deployed your app to macOS. Now, let's deploy to iOS.

Close the .NET MAUI application you had running and return to VS Code.

Click on the curly braces in the bottom right of the VS Code window in the Status Bar and select Debug Target.

My Mac selected as target deployment by default

Scroll down and select iPhone 15.

Debug target list with iPhone 15 highlighted

You should now see iOS: iPhone 15 as the new debug target.

Debug target updated to show iPhone 15

To run the app, click the Run and Debug icon in the VS Code Activity Bar. Then click Run and Debug.

VS Code run and debug pane

Your application will build and deploy to the iPhone simulator. Please note this may take a minute, it is virtually turning on an iPhone!

.NET MAUI app running in iOS simulator

Continue