From 77ac82a1109f5bfc885b9f6389ba509381234808 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 25 Jan 2024 09:55:53 -0600 Subject: [PATCH] [release/8.0.1xx] [Xamarin.Android.Build.Tasks] XA1039 warning for Android.Support (#8648) Context: 2f192386e8072f8e0ecaf0de2fe48654f3ade423 Commit 2f192386 introduces a new XA1039 error when the Android Support libraries are referenced by a .NET 9 project. For .NET 8, partially backport 2f192386 to emit an XA1039 *warning* when the Android Support libraries are referenced by a .NET 8 project. Also introduce a new `$(_AndroidIgnoreAndroidSupportWarning)` MSBuild property as an escape hatch if someone needs to completely disable the warning: <_AndroidIgnoreAndroidSupportWarning>true .NET 9 will not honor or support `$(_AndroidIgnoreAndroidSupportWarning)`. --- Documentation/guides/messages/xa1039.md | 47 +++++++++++++++++++ .../Properties/Resources.resx | 4 ++ .../Xamarin.Android.Build.Tests/BuildTest.cs | 13 +++++ .../Xamarin.Android.Common.targets | 17 +++++++ 4 files changed, 81 insertions(+) create mode 100644 Documentation/guides/messages/xa1039.md diff --git a/Documentation/guides/messages/xa1039.md b/Documentation/guides/messages/xa1039.md new file mode 100644 index 000000000..ec43ce672 --- /dev/null +++ b/Documentation/guides/messages/xa1039.md @@ -0,0 +1,47 @@ +--- +title: Xamarin.Android warning XA1039 +description: XA1039 warning code +ms.date: 1/10/2024 +--- +# Xamarin.Android warning XA1039 + +## Example messages + +``` +warning XA1039: The Android Support libraries are not supported in .NET 9 and later, please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details. +``` + +## Issue + +Outdated "Android Support Library" packages are no longer supported in .NET 9: + +* `Xamarin.Android.Arch.*` +* `Xamarin.Android.Support.*` + +The underlying Java libraries are no longer supported by Google since the final +28.0.0 release. See the [Android Support Library Documentation][support] for +details. + +Some example prefixes of the newer, supported AndroidX packages are: + +* `Xamarin.AndroidX.*` +* `Xamarin.AndroidX.Arch.*` + +For more information about the Android Support libraries or AndroidX, see: + +* [Android Support Library Documentation][support] +* [AndroidX Documentation](https://developer.android.com/jetpack/androidx) + +[support]: https://developer.android.com/topic/libraries/support-library/packages + +## Solution + +Remove all NuGet package references to `Xamarin.Android.Support` or +`Xamarin.Android.Arch` in favor of the new AndroidX equivalents. + +This also can occur if you are using a NuGet package with a transitive +dependency on the Android support packages. In this case, you will need to +remove the package or contact the package author. + +See the [AndroidX migration documentation](https://aka.ms/xamarin/androidx) for +details. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 5915871c6..09fb910bd 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -947,4 +947,8 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS {0} - An Android Resource Identifier. + + The Android Support libraries are not supported in .NET 9 and later, please migrate to AndroidX. See https://aka.ms/xamarin/androidx for more details. + The following are literal names and should not be translated: Android Support, AndroidX, .NET. + diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 9b6db6e36..e8dde8d8c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -1463,6 +1463,19 @@ namespace UnnamedProject } } + [Test] + public void XA1039 () + { + var proj = new XamarinAndroidApplicationProject { + PackageReferences = { + KnownPackages.SupportCompat_27_0_2_1 + } + }; + using var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj), "build should have succeeded"); + StringAssertEx.Contains ("warning XA1039", builder.LastBuildOutput, "Should get XA1039 warning"); + } + [Test] [NonParallelizable] public void CheckLintErrorsAndWarnings () diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 8c51829f9..ece4ee9b8 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -499,6 +499,23 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. /> + + + <_AndroidUnsupportedPackages + Include="%(ResolvedCompileFileDefinitions.NuGetPackageId)" + Condition=" '%(ResolvedCompileFileDefinitions.NuGetPackageId)' != '' and + ( $([System.String]::Copy(%(ResolvedCompileFileDefinitions.NuGetPackageId)).StartsWith ('Xamarin.Android.Arch.')) or + $([System.String]::Copy(%(ResolvedCompileFileDefinitions.NuGetPackageId)).StartsWith ('Xamarin.Android.Support.')) )" + /> + + + +