Developing with Avalonia for Android
Setting up your developer environment
Follow these steps to install the tools you will need, using the CLI:
- Check that you have installed a compatible version of the .NET SDK. The lowest version that works with Avalonia is 6.0.2.00.
You can see the available .NET SDK versions.
- You may need to uninstall an old version of the Android Workload. To do this, type the following command:
dotnet workload uninstall android
- Install the Android Workload. To do this, type the following command:
dotnet workload install android
You may need to run the above commands with sudo.
The dotnet workload command requires the official Microsoft .NET SDK. .NET packages from Linux distribution repositories (such as Arch Linux AUR, Ubuntu dotnet-sdk apt packages, or Fedora dotnet dnf packages) may not include workload support. If dotnet workload install android fails with error NETSDK1139, install the SDK from Microsoft's .NET download page or use the install script:
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel 10.0
Install the Android SDK
There are several ways to install the Android SDK. Choose the one that matches your development environment.
If you have Visual Studio or Visual Studio for Mac then follow the Android SDK installation guide.
If you use JetBrains Rider then follow the Rider Xamarin setup guide.
Alternatively you can install the Android command line tools.
This toolset has a command line based SDK manager that can be used to install the SDK. On successfully installing the Android SDK, add the path to the sdk to your PATH environment variable, directly in bash or in your profile's .bashrc file on Linux.
export ANDROID_HOME=/path/to/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
You can also directly specify the Android SDK location in the dotnet commands when you build, run or deploy the dotnet Android project, by setting the AndroidSdkDirectory variable in the command:
dotnet build ... /p:AndroidSdkDirectory=/path/to/sdk
Ensure you've installed the JDK 11 or above using your platform's package manager. This is already done if set up using Visual Studio or JetBrains Rider as stated above.
There is also a tool in development called MAUI Check that can install all the required SDKs and tools for you automatically:
dotnet tool install -g Redth.Net.Maui.Check
maui-check
With the above Android development environment setup, you will be able to build Android applications, and run them in a simulator on your platform.
See also
- Deploying on Android (emulator, device, and publishing)
- Configure Android debugging in Visual Studio Code on Linux