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

[Xamarin.Android.Build.Tasks] set %(DefineConstantsOnly) for older API levels #8777

Merged

Conversation

jonathanpeppers
Copy link
Member

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.

…API levels

Fixes: xamarin#8331
Context: xamarin#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
Copy link
Member Author

/cc @rolfbjarne just to check if xamarin-macios did anything different here.

Copy link
Member

@rolfbjarne rolfbjarne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty much like what I did.

@jonathanpeppers jonathanpeppers merged commit 60dbcc9 into xamarin:main Mar 1, 2024
47 checks passed
@jonathanpeppers jonathanpeppers deleted the InvalidTargetPlatformVersions branch March 1, 2024 14:49
grendello added a commit that referenced this pull request Mar 1, 2024
* main:
  [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (#8777)
grendello added a commit that referenced this pull request Mar 1, 2024
* main:
  [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (#8777)
grendello added a commit that referenced this pull request Mar 6, 2024
* main:
  [Mono.Android] Fix race condition in AndroidMessageHandler (#8753)
  [ci] Fix SDL Sources Analysis for PRs from forks (#8785)
  [ci] Add 1ESPT override to MSBuild test stages (#8784)
  [ci] Do not use @self annotation for templates (#8783)
  [ci] Migrate to the 1ES template (#8747)
  [Mono.Android] fix trimming warnings, part 2 (#8758)
  [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (#8777)
  [tests] fix duplicate sources in `NuGet.config` (#8772)
  Bump to xamarin/monodroid@e13723e701 (#8771)
grendello added a commit to grendello/xamarin-android that referenced this pull request Mar 8, 2024
* main: (306 commits)
  [templates] Remove redundant "template" from display name. (xamarin#8773)
  Bump to xamarin/java.interop@a7e09b7 (xamarin#8793)
  [build] Include MIT license in most NuGet packages (xamarin#8787)
  Bump to dotnet/installer@893b762b6e 9.0.100-preview.3.24153.2 (xamarin#8782)
  [docs] update notes about `dotnet-trace` and `dotnet-gcdump` (xamarin#8713)
  [Mono.Android] Fix race condition in AndroidMessageHandler (xamarin#8753)
  [ci] Fix SDL Sources Analysis for PRs from forks (xamarin#8785)
  [ci] Add 1ESPT override to MSBuild test stages (xamarin#8784)
  [ci] Do not use @self annotation for templates (xamarin#8783)
  [ci] Migrate to the 1ES template (xamarin#8747)
  [Mono.Android] fix trimming warnings, part 2 (xamarin#8758)
  [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (xamarin#8777)
  [tests] fix duplicate sources in `NuGet.config` (xamarin#8772)
  Bump to xamarin/monodroid@e13723e701 (xamarin#8771)
  Bump to xamarin/xamarin-android-tools@37d79c9 (xamarin#8752)
  Bump to dotnet/installer@d070660282 9.0.100-preview.3.24126.2 (xamarin#8763)
  Bump to xamarin/java.interop@14a9470 (xamarin#8766)
  $(AndroidPackVersionSuffix)=preview.3; net9 is 34.99.0.preview.3 (xamarin#8765)
  [Mono.Android] Do not dispose request content stream in AndroidMessageHandler (xamarin#8764)
  Bump com.android.tools:r8 from 8.2.42 to 8.2.47 (xamarin#8761)
  ...
@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TargetFramework=net8.0-android33 gives poor error message
3 participants