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
dotnet new android- 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
- [Xamarin.Android.Build.Tasks] introduce `XA1038` Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Building a `net8.0-android33` project, currently fails with: error NETSDK1181: Err... — committed to jonathanpeppers/xamarin-android by jonathanpeppers 3 years ago
- [Xamarin.Android.Build.Tasks] introduce `XA1038` Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Building a `net8.0-android33` project, currently fails with: error NETSDK1181: Err... — committed to jonathanpeppers/xamarin-android by jonathanpeppers 3 years ago
- [Xamarin.Android.Build.Tasks] introduce `XA1038` Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Building a `net8.0-android33` project, currently fails with: error NETSDK1181: Err... — committed to jonathanpeppers/xamarin-android by jonathanpeppers 3 years ago
- [Xamarin.Android.Build.Tasks] introduce `XA1038` Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Building a `net8.0-android33` project, currently fails with: error NETSDK1181: Err... — committed to jonathanpeppers/xamarin-android by jonathanpeppers 3 years ago
- [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Context: https://github.com/xamarin/xamarin-android/pull/... — committed to jonathanpeppers/xamarin-android by jonathanpeppers 3 years ago
- [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (#8777) Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Context: https://github.com/xamarin/xamarin-andr... — committed to dotnet/android by jonathanpeppers 3 years ago
- [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (#8777) Fixes: https://github.com/xamarin/xamarin-android/issues/8331 Context: https://github.com/xamarin/xamarin-andr... — committed to dotnet/android by jonathanpeppers 3 years ago
@plppp2001 I would change
net8.0-android34.0to justnet8.0-androidso 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
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
TargetFrameworkthat is controlling what your app is Compiled against.I think what you actually want is to add the following to your
AndroidManifest.xmlIn .net 6/7/8+ the MSBuild property
SupportedOSPlatformVersioncontrols theandroid:minSdkVersion.TargetFramework(s)will control BOTHandroid:targetSdkVersionandandroid:compileSdkVersionunlessandroid:targetSdkVersionis provided in the AndroidManifest.xml already.adding the API level to the end of
net8.0-android(e.gnet8.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.
minSdkVersionis the minimum platform you support.compileSdkVersionis what your compiled agsinst.targetSdkVersionis what your API Level app Supports, this can be different fromcompileSdkVersionsince 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 theandroid:targetSdkVersionin theAndroidManifest.xmlso 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 elementI’m pretty sure @jonathanpeppers or @jonpryor will correct me if I’m wrong on any of this.
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 setSupportedOSPlatformVersion=21in your project, it enables Roslyn analyzers and setsminSdkVersionfor 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:
.NET 8.0 Android application:

Worked for me too, thanks!
You can just remove the
<uses-sdk/>element completely in .NET 6+. It can get those values from your.csprojinstead.If you want to set the minimum SDK version, you can do:
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?