maui

Targeting Android API 34 in .NET MAUI app


I have a .NET MAUI app built on .NET 8, using the latest updates, etc.

I received an email from Google Play stating that my app needs to target Android API 34 due to their current support policies.

I right clicked my project and selected Properties and set the targets under Application > Android Targets -- see image below.

enter image description here

I then got an error stating that the targets in AndroidManifest.xml did not match the project file. So I updated it to the following:

<uses-sdk android:minSdkVersion="32" android:targetSdkVersion="34" />

Now, when I try to build my project, I get the following error but I had already deleted both bin and obj folders so they don't even exist right now. Here's the error:

Assets file 'my-project-folder\my-project\obj\project.assets.json' doesn't have a target for 'net8.0-android34.0' Ensure that restore has run and that you have included 'net8.0-android34.0' in the TargetFrameworks for your project.

I have run dotnet restore several times. The first time I did, it updated the workload to 8.0.7. I had updated Visual Studio to the latest version earlier today so I assume the workload was not updated properly.

And this is what I'm seeing in the project file:

<TargetFrameworks>net8.0-ios;net8.0-android34.0</TargetFrameworks>

Any suggestions about how to fix this issue? Currently, I can't compile my project.

Update:

Here's what I got when I ran dotnet workload list: enter image description here

I then ran dotnet workload update but still getting the same error when I try to build my project.


Solution

  • Note that if you're using net8.0, the default Target Android Framework as you set under Application > Android Targets is Android 14.0(API Level 34) (see here). So you don't need to set it. This setting is used to set the compiling API for the project.

    To fix your issue, you can use the <uses-sdk android:minSdkVersion="32" android:targetSdkVersion="34" in AndroidManifest.xml to meet the Google Play requirement. See Why target newer SDKs?.