Windows Subsystem for Android and .NET MAUI

Did you know you can deploy and debug your Android projects from Visual Studio 2022 (17.3+) to WSA (Windows Subsystem for Android)? This is a quick post to show you how to have your WSA appear in the list of target Android devices in Visual Studio.

WSA as the target device

First, make sure you have WSA installed and enabled, find the instructions here Windows Subsystem for Android™️ | Microsoft Docs. Once it is installed, start the Amazon App Store app to ensure WSA has been started.

Starting up WSA

Open the Windows Subsystem for Android™ Settings app (this gets installed with WSA) and make sure the Developer > Developer Mode setting is enabled. After it is enabled, you should now see an loopback IP address (127.0.0.1) and a port number (58526).

WSA IP address and port number for ADB

With WSA setup and running you can now deploy from Visual Studio 2022. The first step is in Visual Studio, expand the Tools > Android menu and select Android Adb Command Prompt menu item.

ADB Command Prompt

When the ADB command prompt window is opened, you can connect ADB to WSA using the ‘connect’ command and IP:port number for WSA. Here is the full command: adb connect 127.0.0.1:58526and here’s a screenshot of a successful connection:

Successful ADB connection

Finally, in your MAUI project; make sure the target framework is set to net6.0-android and you should find WSA listed under the Android Local Devices menu.

WSA listed as a local Android device in Visual Studio 2022 Preview

Here’s what it looks like after I deployed an early prototype of my current Microsoft Store app Hacked? as a .NET MAUI Android app!

.NET MAUI app running in WSA

Troubleshooting

Troubleshooting Tip 1 – Missing ‘Android Local Devices’

Problem: If you do not see Android Local Devices in the menu, then it means your WSA is probably put back to sleep by Windows because it wasn’t being used.

Solution 1: Just open any Android app, like the Amazon App Store, to start WSA again (you can keep that app open to prevent WSA from going back to sleep). Note: After it has been stopped and started, you’ll need to reconnect ADB again.

Solution 2: Another option is to tell Windows 11 to never put WSA to sleep. It will start up with Windows and always use system resources. Open the Windows Subsystem for Android Settings app and change the System > Subsystem Resources setting to Continuous (see screenshot)

Troubleshooting Tip 2 – No Internet in WSA

Problem: If you do not have any internet in your WSA apps, check to see if you have a VPN active. It is known that Cisco AnyConnnect’s network adapter can interfere if the split tunnel routes traffic with the same IP as the WSA vm.

  • Solution 1: If you disconnect the VPN, the internet will work in WSA again.
Disconnect option in the AnyConnect tray icon’s context menu
  • Solution 2: There is a semi-permanent solution for this by changing the AnyConnect network adapter to have a higher InterfaceMetric value than the WSA Hyper-V adapter one has. Here’s a screenshot of the two PowerShell commands I used to do that:
Increasing AnyConnect’s InterfaceMetric value
Please follow and like us:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.