How to set API level for MAUI projects
Asked Answered
K

4

2

I am starting with dotnet maui and documentation is very poor at this point. I have existing project that targets older Android API level and have the Environment ready for this. When I try to build it, I get an error,

error XA5207: Could not find android.jar for API level 31. This means the Android SDK platform for API level 31 is not installed. Either install it in the Android SDK Manager (Tools > Open Android SDK Manager...), or change the Xamarin.Android project to target an API version that is installed

I couldn't find an option to change API level.

Edit: I could find a way to target newer versions and added that as an answer, but monikers older than 30 is still not being recognized and I am getting an error,

NETSDKZZZZ: Error getting pack version: Pack 'Microsoft.Android.Ref.30' was not present in workload manifests.
Kepi answered 19/7, 2022 at 7:18 Comment(0)
L
7

I think the easiest and best solution is to actually install the requested SDK. This speaks of the target API level. I think the default for .NET MAUI apps right now is 31.

The minimum required API level to submit apps to the Google Play Store at this point is API level 30.

If you still want to change it, include a node like this in your csproj file: <TargetPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">30</TargetPlatformVersion>

Logical answered 19/7, 2022 at 7:27 Comment(2)
I had figured out this part and posted same answer. Will delete mine as the one you posted is more detailed. Also it seems 31 is the minimum level now.Kepi
I can only select the newest Android Version(33). But i have installed 33, 32, 12, etc. #76299619Waylin
G
1

The advice above is to install the missing Android SDK. Rather than googling on how to do that, the best way to do it is to install the desired/missing Android SDK within the Visual Studio 2022 IDE. To do that, access the Tools | Android | Android SDK Manager menu item:

enter image description here

After that, you'll see a list of possibilities. Sometimes it will be necessary to uncheck/apply then check/apply to re-set your system, but in most cases, you'll just need to check the missing SDK in the list then click Apply Changes to download it.

enter image description here

Graces answered 25/9, 2022 at 0:23 Comment(1)
the sdk is installed, but in net7 it only shows 33 instead of 32 and 24 that I have installed (restarted the computer)Larcher
K
0

For anyone trying to target newer API level:

Setting TargetPlatformVersion version in csproj seems to work for newer version (>30).

<TargetPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">32</TargetPlatformVersion>
Kepi answered 19/7, 2022 at 7:26 Comment(0)
E
0

Found this today, currently (july 2024) the minimal api level is 34. Somehow my migrated Xamarin.Forms to MAUI project had lvl 21 in this property.

Equiponderate answered 8/7, 2024 at 11:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.