DEV Community

Cover image for Getting Started with .NET Multi-platform App UI (MAUI) for Android
Karthik Krishna Baiju🔥🚀
Karthik Krishna Baiju🔥🚀

Posted on

Getting Started with .NET Multi-platform App UI (MAUI) for Android

1. What is .NET MAUI

.NET MAUI is the next generation of Xamarin.Forms, Microsoft's latest cross platform offering. .NET MAUI is the evolution of Xamain.Forms toolkit.

Highlights of .NET MAUI

  • Cross Platform, Native UI
  • Single Project, Single Codebase
  • Deploy to multiple devices, mobile & desktop

2. Evolution of .NET MAUI

.NET MAUI is the successor of Xamarin.Forms . Xamarin is a software company founded in 2011 by the engineers behind Mono, Xamarin.Android and Xamarin.IOS . In 2016 Xamarin has been acquired by Microsoft.

Latest version of Xamarin.Forms, which is 5.0 released in 2021.
The next version of Xamarin.Forms is based on .NET 6. Its been announced that the next version of Xamarin.Forms is going to be .NET MAUI

Evolution of .NET MAUI from Xamarin.Forms

3. Current state

Currently .NET MAUI is in Preview 4. Check out the official release announcement.

4. Installation of .NET MAUI Check Tool

Run the following terminal command to install .NET MAUI Check Tool

dotnet tool install -g redth.net.maui.check

On successful installation of tool you can see the message following message on your terminal.

You can invoke the tool using the following command: maui-check
Tool 'redth.net.maui.check' (version '0.5.0') was successfully installed.
Enter fullscreen mode Exit fullscreen mode

Once installation is done, run the following terminal command to install all pre-requisites required for .NET MAUI development

maui-check

Tool will check for

  • OpenJdk / AndroidSDK
  • .NET 6 Preview SDK
  • .NET MAUI Templates

Whenever tool prompt to "Attempt to fix?", type 'y' to continue. Screen shots show various stages of tool checking pre-requisites

Alt Text

Alt Text

After successful installation, tool shows following message. Press enter to exit.

Alt Text

5. Get started with official samples

Connect your Android device in your PC or Launch Android Emulator before start.

Clone official .net maui samples repository

https://github.com/dotnet/maui-samples.git

Navigate to cloned path in your pc using command prompt

cd \maui-samples

To build Android project:

dotnet build HelloAndroid

To run Android project:

dotnet build HelloAndroid -t:Run

To launch .NET MAUI Project

dotnet build HelloMaui -t:Run -f net6.0-android

6. Get started with Visual Studio 2019 Preview

Make sure you have latest preview installed on your PC.

Visual studio version used for .NET MAUI Preview 4

Alt Text

Alt Text

Before running the code, do nuget package addition in visual studio. Create a nuget.config file to the root of your project and add the following feed(s) with these commands:

dotnet new nugetconfig
dotnet nuget add source -n maui-preview https://aka.ms/maui-preview/index.json

In visual studio change target to android, hit F5 run in local device or Emulator

Visual studio emulator selection for .NET MAUI

✌️ Your first MAUI App is up and running.

Running .NET MAUI Android Application

7. Battery Charge Indicator Sample Application for Android

I have created a MAUI application which shows the current battery charge percentage and source of power in an android device.

Alt Text

Check sample application created in Github.

https://github.com/karthikeyen/maui-explorer

8. 🚀 What Is Next?

Please check out the official roadmap

Top comments (2)

Collapse
 
zeus2nawaz profile image
Md Nawaz

Hi
I have created a MAUI project in VS 2022 preview, which is working fine initially with emulator, but now Emulator is not showing. When I create Xamarin project Emulator is showing and application is running on that Emulator.

Please help me to resolve this issue as it occurs developing application

What I have tried:

  1. I had delete/renamed
    Copy Code
    C:\Users\username\AppData\Local\Xamarin
    C:\Users\username\AppData\Local\Microsoft\VisualStudio\17.0_e17a11fb\ComponentModelCache

  2. I had repair VS 2022 preview

  3. I had reinstall MAUI

Collapse
 
kkb_ktm profile image
Karthik Krishna Baiju🔥🚀

Sorry for the late replay.

I have created the above using VS 2019 Preview. I'm not sure whether VS 2022 Preview is stable for xamarin devs. I need to check on this and will revert u.