Repository navigation
TargetFramework=net8.0-android33 gives poor error message #8331
Description
Activity
- addedArea: App+Library BuildIssues when building Library projects or Application projects.Issues when building Library projects or Application projects.
on Sep 13, 2023 - addedneeds-triageIssues that need to be assigned.Issues that need to be assigned.
on Sep 13, 2023 - removedneeds-triageIssues that need to be assigned.Issues that need to be assigned.
on Sep 13, 2023 I'm seeing this error even if I remove
33.0from the target framework of an Android Java Library Binding project<TargetFramework>net8.0-android</TargetFramework>Can you provide any more details on why this error occurs? This is with RC2
Can you share a
.binlogof the build? https://aka.ms/binlogThank you! Your suggestion lead to a solution :)
I ran
dotnet buildin the terminal so I could add the-blparameter, and the build succeeded. Apparently triggering a restore, or a build, from within VS for Mac isn't working and is "stuck" on version 33.0, but runningdotnet buildfrom terminal succeeds.Here's the error I was getting in VS in case it helps someone else:
/usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5) : error NETSDK1181: Error getting pack version: Pack 'Microsoft.Android.Ref.33' was not present in workload manifests. /usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5) : error NETSDK1181: Error getting pack version: Pack 'Microsoft.Android.Ref.33' was not present in workload manifests. /usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5) : error NETSDK1181: Error getting pack version: Pack 'Microsoft.Android.Ref.33' was not present in workload manifests.VS Mac has a checkbox that allows it to use the .NET 8 SDK. Maybe it is confused and mixing .NET 7 and 8?
Reacted by kpespisaGood 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.
Reacted by Paul AstroHello, I'm also getting this error. When upgrading maui from .net 7 to .net 8. I tried your solutions.. Anything I can try?
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.
Reacted by milanioReacted by Paul Astro and Echo Lumaque30 remaining items
Yes, that is not the final one. Are you wanting to the the value to something other than the default? Is something not working?
Ah ok. I thought this was the final one.
aapt2shows the the correcttargetSdkVersionE: uses-sdk (line=9) A: http://schemas.android.com/apk/res/android:minSdkVersion(0x0101020c)=24 A: http://schemas.android.com/apk/res/android:targetSdkVersion(0x01010270)=34Now i understand how this works.
One last question: Is it possible to view the finalAndroidManifest.xmlsomewhere in the obj or bin forders? Just to verify if all my settings correctly merged.Thank you
The
.apkis the source of truth. You might try theapkanalyzertool from the Android SDK's cmdline-tools. Checkout theView information in the manifestsection:I tested a bit more. The warning i mentioned earlier:
XA1006: The TargetFrameworkVersion (Android API level 34) is higher than the targetSdkVersion (28). Please increase the android:targetSdkVersion in the AndroidManifest.xml so that the API levels match.
happens when the targetSdkVersion is set to 28 from maui. Maui set 28 in the apk if in the platforms/android/AndroidManifest.xml file is an empty
<uses-sdk/>node. Like this:<?xml version="1.0" encoding="utf-8"?> <manifest android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="true" android:fullBackupContent="@xml/backup_rules" android:dataExtractionRules="@xml/backup_rules_api31" android:localeConfig="@xml/locales_config" android:supportsRtl="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round"> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/PushNotificationAndroid" /> </application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-sdk /> </manifest>
Completely remove the empty node generated value 34.
I am running into this issue. The error message (from the original post) is below, and is completely unhelpful because it does not tell me what to do, in order to fix the error. I don't know what a workload manifest is or how to add anything to it.
Error getting pack version: Pack 'Microsoft.Android.Ref.33' was not present in workload manifests
I am in the process of upgrading our widespread and popular app from Xamarin to net8.0-android. I understand that by default, .net 8 sets the target OS version to 34. However, since our app hasn't yet been proved compatible with the Android OS changes that take effect when apps say they target version 34, I wish to leave this as 33 for the time being. However, I cannot build with it set to 33, I receive the error above.
I can leave the property property set to 34 but include in the manifest file. It's not clear whether this works or not (from the perspective of Android then considering our app to be targetting OS 33) but that then generates its own compiler warning:
Warning XA4211 AndroidManifest.xml //uses-sdk/@android:targetSdkVersion '33' is less than $(TargetFrameworkVersion) ''. Using API-34 for ACW compilation.
In short, our project needs to be built using the latest tools, specify a minimum Android version of 21, and a target Android version of 33, and have no errors or warnings during a build.
@divil5000 as a workaround you can still target net7 and use this in your csproj :
<TargetFrameworks>net7.0-android33.0</TargetFrameworks>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.
Reacted by Jonathan ANTOINESo 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.xml<uses-sdk android:targetSdkVersion="33" />
In .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 element<NoWarn>XA1006;XA4211</NoWarn>
I'm pretty sure @jonathanpeppers or @jonpryor will correct me if I'm wrong on any of this.
Reacted by Jonathan ANTOINE and AXiXThanks 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 entry to explicitly target API 33 while building against API 34. I just object to the warning :)
Reacted by Dean Ellis and Jonathan ANTOINEThanks for the explanation as it was not this clear in the documentation @dellis1972
You can just remove the
<uses-sdk/>element completely in .NET 6+. It can get those values from your.csprojinstead.<uses-sdk/>keeps being added by Visual studio's (Version 17.9.0) new dedicated manifest editor (if you touch and save some other value).- added a commit that references this issue
on Feb 29, 2024 - added a commit that references this issue
on Mar 1, 2024 - locked and limited conversation to collaborators
on Apr 1, 2024 - added a commit that references this issue
on May 9, 2024
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:
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 androidTargetFrameworkDid you find any workaround?
Remove
33.0Relevant log output
No response