android: `TargetFramework=net8.0-android33` gives poor error message

Android application type

.NET Android (net8.0-android, etc.)

Affected platform version

.NET 8

Description

.NET 8 is API 34, so 33 is invalid, but you get a poor error message:

Error    NETSDK1181    Error getting pack version: Pack 'Microsoft.Android.Ref.33' was not present in workload manifests.
C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets

https://discord.com/channels/732297728826277939/732297916680765551/1151549736269119549

It would be nice if we could emit a better message here, so see what the .NET SDK expects us to do.

Steps to Reproduce

  1. dotnet new android
  2. Put 33.0 on the TargetFramework

Did you find any workaround?

Remove 33.0

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 42 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@plppp2001 I would change net8.0-android34.0 to just net8.0-android so you don’t have to fight this next year.

@AlexNik4 they’ve already fixed this in the next 17.9 Preview. Thanks, though!

Private repo, but the change is here: https://github.com/xamarin/XamarinVS/pull/14329

If .NET 8 is incompatible with older SDKs the UI should really prevent this scenario and not generate invalid csproj

image

I am getting the same error as @ziomek64. I have run the “dotnet build” and “dotnet build -bl” commands in a terminal session, however, that did not solve the problem. I am in windows11 and the release vs 2022 as of November 14 and the released .net 8.

I went into my project file, and I noticed that the one of the target platforms was net8.0-android33.0. I changed this to net8.0-android34.0, and the error in VS has gone away. Fingers crossed that this solves the problem.

Thanks Dean for that comprehensive explanation. I am glad my understanding was approaching what you said.

As regards your last paragraph, Google is clearly pretending it lives in an ideal world, whereas most of us do not. There shouldn’t be a warning for developers who haven’t managed to go through the whole develop/test process of targeting the next API version yet. Updating one’s build tools (as I am currently in the process of doing) is a different job to re-targeting one’s app to the next OS version.

It sounds like I’m ok at the moment with my <used-sdk> entry to explicitly target API 33 while building against API 34. I just object to the warning 😃

So for Android if you use the TargetFramework that is controlling what your app is Compiled against.

I think what you actually want is to add the following to your AndroidManifest.xml

<uses-sdk android:targetSdkVersion="33" />

In .net 6/7/8+ the MSBuild property SupportedOSPlatformVersion controls the android:minSdkVersion. TargetFramework(s) will control BOTH android:targetSdkVersion and android:compileSdkVersion unless android:targetSdkVersion is provided in the AndroidManifest.xml already.

adding the API level to the end of net8.0-android (e.g net8.0-android33.0) will mean you compile aginst that API level. I think the plan is as we move forward we will only support compiling against the latest API level as we do the .net SDK (@jonpryor correct me if I’m wrong here). So .net 8 will only allow compiling against API 34, .net 7 API 33, .net 9 API 34 or 35 depending on when the next stable API level is released by google.

So to sum up.

minSdkVersion is the minimum platform you support. compileSdkVersion is what your compiled agsinst. targetSdkVersion is what your API Level app Supports, this can be different from compileSdkVersion since you can use runtime checks to see which API level you are on.

If you want to compiled against API 34 but target API 33 you will get the following warning.

warning XA1006: The TargetFrameworkVersion (Android API level 34) is higher than the targetSdkVersion (33). Please increase the android:targetSdkVersionin theAndroidManifest.xml so that the API levels match.

in an ideal world these should match, this is something google recommends. This is why this warning exists. If you do not want to see this you might be able to disable the warning via the <NoWarn/> MSbuild element

<NoWarn>XA1006;XA4211</NoWarn>

I’m pretty sure @jonathanpeppers or @jonpryor will correct me if I’m wrong on any of this.

Same issue but I don’t want the app targeted at API 34 so I’m keeping the <used-sdk>.

Also I’m getting an other warning during the build: The TargetFrameworkVersion (Android API level 34) is higher than the targetSdkVersion (33). Please increase the `android:targetSdkVersion` in the `AndroidManifest.xml` so that the API levels match.

You can just remove the <uses-sdk/> element completely in .NET 6+. It can get those values from your .csproj instead. in the ANDROIDMANIFEST.XML FILE

I could, but then presumably miss out on all that .net 8 has to offer.

Is this actually an acknowledged bug then? Did Microsoft simply not realise that people would wish to compile using the latest SDKs but that OS targeting is different? I keep hoping that I’ve simply misunderstood something.

@aqua-ix I believe the answer is “yes” to all your questions.

However, I would usually completely omit <uses-sdk/> from projects and let the Android workload specify the values for you. If you set SupportedOSPlatformVersion=21 in your project, it enables Roslyn analyzers and sets minSdkVersion for you.

@jonathanpeppers On the latest main, we found that the issue https://github.com/xamarin/XamarinVS/pull/14329 has been fixed in net8.0 maui (only Android14 API34 is supported), but there are still options below 34 in net8.0 Android application. .NET 8.0 MAUI: image .NET 8.0 Android application: image

@plppp2001 I would change net8.0-android34.0 to just net8.0-android so you don’t have to fight this next year.

Worked for me too, thanks!

Error XA1036 AndroidManifest.xml //uses-sdk/https://github.com/android:minSdkVersion ‘24’ does not match the (SupportedOSPlatformVersion) value in the project file, then a default value has been assumed).

You can just remove the <uses-sdk/> element completely in .NET 6+. It can get those values from your .csproj instead.

If you want to set the minimum SDK version, you can do:

 <SupportedOSPlatformVersion>24</SupportedOSPlatformVersion>

This way you’ll get the Roslyn analyzers that warn about Android APIs.

Good thought! Under Preferences > Preview Features, it was showing as selected. I unchecked the option, restarted, then selected the option, and restarted. The restore and build succeeds now.

VS Mac has a checkbox that allows it to use the .NET 8 SDK. Maybe it is confused and mixing .NET 7 and 8?