When attempting to deploy a MAUI app, the build process failed with the following error:
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/35.0.50/tools/Xamarin.Android.Tooling.targets(92,5): error XA5207:
Could not find android.jar for API level 35. This means the Android SDK platform for API level 35 is not installed; it was expected to be in `/Users/banditoth/Library/Android/sdk/platforms/android-35/android.jar`.
You can install the missing API level by running `dotnet build -t:InstallAndroidDependencies -f net9.0-android "-p:AndroidSdkDirectory=/Users/banditoth/Library/Android/sdk"`, or change the project to target an API version that is installed.
See https://aka.ms/xa5207 for more details.
This error indicates that the Android SDK platform for API level 35 is missing. The suggested solution is to install the missing API level by running the following command:
dotnet build -t:InstallAndroidDependencies -f net9.0-android "-p:AndroidSdkDirectory=/Users/banditoth/Library/Android/sdk"
However, running the above command led to another error:
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/35.0.50/tools/Xamarin.Installer.Common.targets(19,3): error : The Android SDK license agreements were not accepted, please set `$(AcceptAndroidSDKLicenses)` to accept.
This error occurs because the Android SDK license agreements have not been accepted.
The Solution
To resolve this issue, you need to accept the Android SDK license agreements. This can be done by modifying your project’s .csproj
file. Add the following line within a <PropertyGroup>
:
<AcceptAndroidSDKLicenses>true</AcceptAndroidSDKLicenses>
Here’s an example of how your .csproj
file might look after the modification:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
<RootNamespace>YourAppNamespace</RootNamespace>
<AcceptAndroidSDKLicenses>true</AcceptAndroidSDKLicenses>
</PropertyGroup>
</Project>