Skip to content

TargetFramework=net8.0-android33 gives poor error message #8331

Description

@jonathanpeppers

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

Activity

  1. added this to the .NET 8 milestone on Sep 13, 2023
  2. kpespisa commented on Nov 8, 2023

    @kpespisa

    I'm seeing this error even if I remove 33.0 from 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

  3. jonathanpeppers commented on Nov 8, 2023

    @jonathanpeppers
    MemberAuthor

    Can you share a .binlog of the build? https://aka.ms/binlog

  4. kpespisa commented on Nov 8, 2023

    @kpespisa

    Thank you! Your suggestion lead to a solution :)

    I ran dotnet build in the terminal so I could add the -bl parameter, 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 running dotnet build from 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.

  5. jonathanpeppers commented on Nov 8, 2023

    @jonathanpeppers
    MemberAuthor

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

  6. kpespisa commented on Nov 8, 2023

    @kpespisa

    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.

  7. ziomek64 commented on Nov 14, 2023

    @ziomek64

    Hello, I'm also getting this error. When upgrading maui from .net 7 to .net 8. I tried your solutions.. Anything I can try?

  8. wallym commented on Nov 14, 2023

    @wallym

    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.

  9. 30 remaining items

  10. AlleSchonWeg commented on Jan 10, 2024

    @AlleSchonWeg

    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. aapt2 shows the the correct targetSdkVersion

    E: 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)=34
    

    Now i understand how this works.
    One last question: Is it possible to view the final AndroidManifest.xml somewhere in the obj or bin forders? Just to verify if all my settings correctly merged.

    Thank you

  11. jonathanpeppers commented on Jan 10, 2024

    @jonathanpeppers
    MemberAuthor

    The .apk is the source of truth. You might try the apkanalyzer tool from the Android SDK's cmdline-tools. Checkout the View information in the manifest section:

  12. AlleSchonWeg commented on Jan 11, 2024

    @AlleSchonWeg

    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.

  13. divil5000 commented on Jan 30, 2024

    @divil5000

    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.

  14. jonathanantoine commented on Jan 30, 2024

    @jonathanantoine

    @divil5000 as a workaround you can still target net7 and use this in your csproj :
    <TargetFrameworks>net7.0-android33.0</TargetFrameworks>

  15. divil5000 commented on Jan 31, 2024

    @divil5000

    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.

  16. dellis1972 commented on Jan 31, 2024

    @dellis1972
    Contributor

    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.

  17. divil5000 commented on Jan 31, 2024

    @divil5000

    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 entry to explicitly target API 33 while building against API 34. I just object to the warning :)

  18. jonathanantoine commented on Jan 31, 2024

    @jonathanantoine

    Thanks for the explanation as it was not this clear in the documentation @dellis1972

  19. crwsolutions commented on Feb 28, 2024

    @crwsolutions

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

    <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).

  20. locked and limited conversation to collaborators on Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.enhancementProposed change to current functionality.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions