Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jonathanpeppers opened this issue Sep 13, 2023 · 42 comments · Fixed by #8777
Closed

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

jonathanpeppers opened this issue Sep 13, 2023 · 42 comments · Fixed by #8777
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Milestone

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Sep 13, 2023

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

@jonathanpeppers jonathanpeppers added the Area: App+Library Build Issues when building Library projects or Application projects. label Sep 13, 2023
@jonathanpeppers jonathanpeppers added this to the .NET 8 milestone Sep 13, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issues that need to be assigned. label Sep 13, 2023
@jonathanpeppers jonathanpeppers removed the needs-triage Issues that need to be assigned. label Sep 13, 2023
@jonpryor jonpryor modified the milestones: .NET 8, .NET 9 Planning Oct 23, 2023
@kpespisa
Copy link

kpespisa commented Nov 8, 2023

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

@jonathanpeppers
Copy link
Member Author

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

@kpespisa
Copy link

kpespisa commented Nov 8, 2023

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.

@jonathanpeppers
Copy link
Member Author

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

@kpespisa
Copy link

kpespisa commented Nov 8, 2023

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.

@ziomek64
Copy link

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

@wallym
Copy link

wallym commented Nov 14, 2023

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.

@jpobst jpobst added the enhancement Proposed change to current functionality. label Nov 14, 2023
@plppp2001
Copy link

plppp2001 commented Nov 15, 2023

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.

I did that but now I'm getting this following error:

Severity Code Description Project File Line Suppression State
Error XA1036 AndroidManifest.xml //uses-sdk/@android:minSdkVersion '24' does not match the $(SupportedOSPlatformVersion) value '21.0' in the project file (if there is no $(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed).
Either change the value in the AndroidManifest.xml to match the $(SupportedOSPlatformVersion) value, or remove the value in the AndroidManifest.xml (and add a $(SupportedOSPlatformVersion) value to the project file if it doesn't already exist). CheapEaseMauiTaskApp C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.43\tools\Xamarin.Android.Tooling.targets 100

Screenshot 2023-11-15 165029

@jonathanpeppers
Copy link
Member Author

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.

@plppp2001
Copy link

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.

I did that but now I'm getting this following error:

Severity Code Description Project File Line Suppression State Error XA1036 AndroidManifest.xml //uses-sdk/@android:minSdkVersion '24' does not match the (SupportedOSPlatformVersion)value′21.0′intheprojectfile(ifthereisno(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed). Either change the value in the AndroidManifest.xml to match the (SupportedOSPlatformVersion)value,orremovethevalueintheAndroidManifest.xml(andadda(SupportedOSPlatformVersion) value to the project file if it doesn't already exist). CheapEaseMauiTaskApp C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.43\tools\Xamarin.Android.Tooling.targets 100
Screenshot 2023-11-15 165029

UPDATE I got net 8 maui update to compile, I have the following settings and it compiled ( not sure if it will work or if this is correct for MAUI 8):

Screenshot 2023-11-15 165606 Screenshot 2023-11-15 165550 Screenshot 2023-11-15 165536

@jonathanpeppers
Copy link
Member Author

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

@plppp2001
Copy link

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

This worked, thank you. Net 8 is going...

@echolumaque
Copy link

@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!

@rgroenewoudt
Copy link

rgroenewoudt commented Nov 24, 2023

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.

@ziomek64
Copy link

Same issue but I don't want the app targeted at API 34 so I'm keeping the .

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.

Check manifest

@plppp2001
Copy link

Same issue but I don't want the app targeted at API 34 so I'm keeping the .

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  element completely in .NET 6+. It can get those values from your .csproj instead. in the ANDROIDMANIFEST.XML FILE

1 similar comment
@plppp2001

This comment was marked as duplicate.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Dec 6, 2023
Fixes: dotnet#8331

Building a `net8.0-android33` project, currently fails with:

    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

To solve this, you would either change 33 to 34, or just remove the
number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Emit the new `XA1038` warning message.

This allows these projects to build with a reasonable warning message.

The only concern down the road: if we ever support `net8.0-android35`
alongside `net8.0-android34`, then we'd need to slightly adjust the
logic here.
@AlexNik4
Copy link

AlexNik4 commented Dec 7, 2023

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

image

@jonathanpeppers
Copy link
Member Author

@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

@aqua-ix
Copy link

aqua-ix commented Dec 22, 2023

Does <uses-sdk android:targetSdkVersion="33" /> in AndroidManifest.xml override the default target 34 of net8.0-android in .csproj?

Also, compileSdk and targetSdk can be set in the build.gradle of an Android native app, but is it correct to assume that the following will work in a .NET Android app?

  • compileSdk: Value specified in <TargetFramework> of .csproj
  • targetSdk: Value specified in <uses-sdk/> of AndroidManifest.xml

@jonathanpeppers
Copy link
Member Author

@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 added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 3, 2024
Fixes: dotnet#8331

Building a `net8.0-android33` project, currently fails with:

    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

To solve this, you would either change 33 to 34, or just remove the
number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Emit the new `XA1038` error message.

This allows these projects to build with a reasonable error message.

The only concern down the road: if we ever support `net8.0-android35`
alongside `net8.0-android34`, then we'd need to slightly adjust the
logic here.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 4, 2024
Fixes: dotnet#8331

Building a `net8.0-android33` project, currently fails with:

    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

To solve this, you would either change 33 to 34, or just remove the
number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Emit the new `XA1038` error message.

This allows these projects to build with a reasonable error message.

The only concern down the road: if we ever support `net8.0-android35`
alongside `net8.0-android34`, then we'd need to slightly adjust the
logic here.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 8, 2024
Fixes: dotnet#8331

Building a `net8.0-android33` project, currently fails with:

    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

To solve this, you would either change 33 to 34, or just remove the
number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Emit the new `XA1038` error message.

This allows these projects to build with a reasonable error message.

The only concern down the road: if we ever support `net8.0-android35`
alongside `net8.0-android34`, then we'd need to slightly adjust the
logic here.
@AlleSchonWeg
Copy link

Hi @jonathanpeppers
I'm a bit confused with these settings. In XF i set android:minSdkVersion and android:targetSdkVersion in the manifest file (AndroidManifest.xml). It can be changed via the android manifest tab in the android project. I can also change the "Compile using android framework" in the Application tab.
In MAUI the <uses-sdk/> is created from he csproj file.
Now i have this warning:

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.

Is the TargetFrameworkVersion API 34 in .Net 8? Is this the same as "Compile using android framework" in XF?
And where comes the targetSdkVersion (28) from? Is this also a default MAUI value?

In MAUI i can set "Target Android Framework" under the Application / Android targets tab. Is this the targetSdkVersion value for the manifest file?

Thank you

@jonathanpeppers
Copy link
Member Author

Can you share an example of what your <uses-sdk/> looks like? What do you have set for TargetFramework(s) and SupportedOSPlatformVersion?

I would recommend what the project templates do:

  • Delete the <uses-sdk/> element
  • TargetFramework=net8.0-android
  • SupportedOSPlatformVersion=21

The various project options pages & manifest editor might simply be outdated. We can file something with IDE teams to look into this.

And if you want to do something else, maybe what are you trying to do?

@AlleSchonWeg
Copy link

Can you share an example of what your <uses-sdk/> looks like? What do you have set for TargetFramework(s) and SupportedOSPlatformVersion?

I would recommend what the project templates do:

  • Delete the <uses-sdk/> element
  • TargetFramework=net8.0-android
  • SupportedOSPlatformVersion=21

The various project options pages & manifest editor might simply be outdated. We can file something with IDE teams to look into this.

And if you want to do something else, maybe what are you trying to do?

My XF <uses-sdk/>has this values:
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="32" />
And MAUI (generated manifest from ..\obj\Debug\net8.0-android\AndroidManifest.xml) this value:
<uses-sdk android:minSdkVersion="24" />

In the csproj file:

<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>

And the settings from the project properties:
image

I'm trying to add the android:targetSdkVersion="32" attribute to the generated manifest.

Thanks again

@jonathanpeppers
Copy link
Member Author

Why can't you just remove <uses-sdk/> everywhere?

We have this documented here: https://learn.microsoft.com/en-us/dotnet/maui/migration/android-projects?view=net-maui-8.0#changes-to-androidmanifestxml

@AlleSchonWeg
Copy link

I have removed <uses-sdk/> everywhere. Here is my AndroidManifest.xml in the Platforms/Android folder:

<?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" />
</manifest>

At compile time Maui generates this <uses-sdk/> node:

 <uses-sdk android:minSdkVersion="24" />

The android:minSdkVersion is ok. But no android:targetSdkVersion. If i read the docs correctly than TargetFramework net8.0-android should generate android:targetSdkVersion. Or i misunderstood something?

@plppp2001
Copy link

plppp2001 commented Jan 10, 2024 via email

@jonathanpeppers
Copy link
Member Author

@AlleSchonWeg how are you looking at the AndroidManifest.xml file? Are you opening the .apk file in Android Studio? AS can "decompile" an .apk and show you the final AndroidManifest.xml contents from the binary format.

aapt2 should emit targetSdkVersion no matter what, Android requires it for the final app.

@AlleSchonWeg
Copy link

@AlleSchonWeg how are you looking at the AndroidManifest.xml file? Are you opening the .apk file in Android Studio?

No. I just open it with notepad++. The one located in the .\obj\Debug\net8.0-android\ folder.

@jonathanpeppers
Copy link
Member Author

Yes, that is not the final one. Are you wanting to the the value to something other than the default? Is something not working?

@AlleSchonWeg
Copy link

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

@jonathanpeppers
Copy link
Member Author

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:

@AlleSchonWeg
Copy link

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.

@divil5000
Copy link

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.

@jonathanantoine
Copy link

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

@divil5000
Copy link

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.

@dellis1972
Copy link
Contributor

dellis1972 commented Jan 31, 2024

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.

@divil5000
Copy link

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

@jonathanantoine
Copy link

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

@crwsolutions
Copy link

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

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Feb 29, 2024
…API levels

Fixes: dotnet#8331
Context: dotnet#8569
Context: dotnet/sdk@25b360d

Building for `net9.0-android33` would give 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

To solve this, you would either change 33 to 34, or just remove the number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Opt into `%(DefineConstantsOnly)=true` for API levels 21-33 (and not
  the latest), which allows the .NET SDK to emit the *better* .NET SDK
  error message instead.

So now users will get:

    (_CheckForInvalidTargetPlatformVersion target) ->
    dotnet/sdk/9.0.100-alpha.1.23628.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(243,5):
    error NETSDK1140: 33.0 is not a valid TargetPlatformVersion for Android.
    Valid versions include: 34.0

I added a test for this scenario.
jonathanpeppers added a commit that referenced this issue Mar 1, 2024
…API levels (#8777)

Fixes: #8331
Context: #8569
Context: dotnet/sdk@25b360d

Building for `net9.0-android33` would give 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

To solve this, you would either change 33 to 34, or just remove the number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Opt into `%(DefineConstantsOnly)=true` for API levels 21-33 (and not
  the latest), which allows the .NET SDK to emit the *better* .NET SDK
  error message instead.

So now users will get:

    (_CheckForInvalidTargetPlatformVersion target) ->
    dotnet/sdk/9.0.100-alpha.1.23628.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(243,5):
    error NETSDK1140: 33.0 is not a valid TargetPlatformVersion for Android.
    Valid versions include: 34.0

I added a test for this scenario.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2024
jonathanpeppers added a commit that referenced this issue May 9, 2024
…API levels (#8777)

Fixes: #8331
Context: #8569
Context: dotnet/sdk@25b360d

Building for `net9.0-android33` would give 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

To solve this, you would either change 33 to 34, or just remove the number to rely on the default value.

To make this easier:

* Automatically switch to 34 if the user specifies 33 or less.

* Opt into `%(DefineConstantsOnly)=true` for API levels 21-33 (and not
  the latest), which allows the .NET SDK to emit the *better* .NET SDK
  error message instead.

So now users will get:

    (_CheckForInvalidTargetPlatformVersion target) ->
    dotnet/sdk/9.0.100-alpha.1.23628.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(243,5):
    error NETSDK1140: 33.0 is not a valid TargetPlatformVersion for Android.
    Valid versions include: 34.0

I added a test for this scenario.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Projects
None yet