Categories
.NET .NET 8 .NET 9 .NET MAUI Android Blazor C# Desktop Developer Hybrid iOS macOS Mobile Visual Studio VS Code Web Windows Windows 11 Xamarin Xamarin.Forms

Using WSA for .NET MAUI Android Development

Windows Subsystem for Android™️ (WSA) enables your Windows 11 device to run Android applications.

Even though optimization techniques such as Intel HAXM are available, there is a marginal performance tradeoff when using the Android Emulator.

The Subsystem has been designed to function as an integral OS component, providing superior performance compared to the Android Emulator.

From my perspective, the only drawback of using WSA is the lack of support for Google Play Services (as it works with Amazon Appstore). So any apps that rely on those services, WSA might not be the best fit. So continue to use the Android Emulator or the Physical device.

Installation:

Windows Subsystem for Android - Advanced Settings - Developer Mode
Windows Subsystem for Android – Advanced Settings – Developer Mode

For certain regions, the WSA is not available for direct installation from the Microsoft Store. However, there is a workaround for manual installation, to be undertaken AT YOUR OWN RISK.

Check the below links for the same:

While working with Android, it is highly recommended to install the ADB (Android Debug Bridge) executable to perform various tasks from CLI. It is available as part of the Android SDK Platform Tools and can be installed from within Visual Studio. Consult the documentation for more details.

  • Launch Visual Studio
  • From the Menu, Tools → Android → Android SDK Manager …
  • In the Tools tab, select Android SDK Platform Tools and click on Apply Changes
Android SDK Platform Tools - Android Debug Bridge (adb)
Android SDK Platform Tools – Android Debug Bridge (adb)

Once installation is complete, verify whether adb is recognized as an executable. The below command should display its details.

adb version

Connect to WSA:

Then Start the Amazon Appstore App from the Windows Start menu or with the below command.

The wsa:// scheme is a unique protocol, enabling the initiation of any installed app within WSA with its package ID.

start wsa://com.amazon.venezia

Now it is time to establish a connection to the WSA using the adb command. To operate alongside WSA on the local machine, a connection must be established using the localhost IP address 127.0.0.1 and port # 58526. The command is as follows:

adb connect 127.0.0.1:58526

Authorization is required for the connection to be successful. Please click on Allow. Optionally check the Always allow from this computer option to avoid frequent prompts.

Windows Subsystem for Android - Authorization
Windows Subsystem for Android – Authorization

Verify whether the device appears in the list of connected devices with the below command.

adb devices

Launch an App:

.NET MAUI App can be installed and launched from WSA using the below command.

dotnet build -f net8.0-android -t:Run

If multiple devices are connected to ADB, it is necessary to specify the AdbTarget property to launch on a specific device. Value for this property is of the format: -s device_id

Note: There should be a space between the key -s and the value device_id and it is to be URL encoded (%20).

dotnet build -f net8.0-android -t:Run -p:AdbTarget=-s%20127.0.0.1:58526
.NET MAUI Android App running on Windows Subsystem for Android
.NET MAUI Android App running on Windows Subsystem for Android

It’s to be noted that once connected to WSA, it appears as an Android device target in both Visual Studio and VS Code. Making it easy to work with it without ever having to leave the IDE.

To further simplify, install this Windows Subsystem for Android Barista VS Extension. This adds a command to the Tools menu to start and connect to WSA so you can develop and debug with it from within Visual Studio.

Visual Studio 2022 - Windows Subsystem for Android (WSA) as Android Device Target
Visual Studio 2022 – Windows Subsystem for Android (WSA) as Android Device Target
VS Code - Windows Subsystem for Android (WSA) as Android Device Target
VS Code – Windows Subsystem for Android (WSA) as Android Device Target

Refer to this Using VS Code for .NET MAUI Development article for initial setup and how to switch between device targets.

On macOS and Linux:

The Windows Subsystem for Android (WSA) offers the advantage of allowing devices on the same private network to access the Subsystem. This functionality is akin to Pair to Mac for iOS development.

Since the .NET MAUI Android Workload is installable on macOS and Linux, developers can create .NET MAUI Apps from those platforms using VS Code and WSA.

Developers on macOS can download the SDK Platform Tools from the official download page, extract the Zip contents to a folder, and launch the Terminal in that folder context to work with it. Add the extracted folder path to the Path environment variable to work with ADB from anywhere.

To install ADB on Linux, use the following command:

sudo apt install android-tools-adb

Verify the installation:

adb version

Since the WSA would be operating on a separate machine within the network, it is essential to specify its IP address while working with it.

To obtain the IP address, utilize the ipconfig command.

adb connect <ip_address>:58526

For example:

adb connect 192.168.1.100:58526

On the authorization prompt, please select Allow to establish a successful connection.

Then verify whether the device appears in the list of connected devices with the below command.

adb devices

Then continue to use the same set of dotnet commands to work with the App.

Once everything is done, the connection to the device can be terminated by utilizing the following command. To disconnect a particular device, the device_id should be provided as a parameter.

adb disconnect

If you would like to recognize the work, kindly consider sponsoring on the GitHub Sponsor page or Buy Me a Coffee page. Thanks in advance.

Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.

One reply on “Using WSA for .NET MAUI Android Development”

Comments are closed.

Discover more from Developer Thoughts

Subscribe now to keep reading and get access to the full archive.

Continue reading