From ad08ac177e88bdea5775590ad0de9d703561dd64 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 19 Sep 2019 16:23:18 -0500 Subject: [PATCH] [Xamarin.Android.Build.Tasks] deprecate The `` MSBuild task is the precursor to Xamarin.Build.Download. It is only used by very old versions of the Xamarin support library components. We want to deprecate its behavior in an effort to remove complexity and improve build performance. We have to scan each assembly for these assembly-level attributes. I added a new `XA0121` warning if a library is encountered during a build that uses these attributes: * `IncludeAndroidResourcesFromAttribute` * `NativeLibraryReferenceAttribute` * `JavaLibraryReferenceAttribute` I added `[Obsolete]` on these as well. --- Documentation/guides/messages/xa0121.md | 34 +++++++++++++++++++ .../IncludeAndroidResourcesFromAttribute.cs | 1 + .../NativeLibraryReferenceAttribute.cs | 1 + .../Android/ReferenceFilesAttribute.cs | 2 +- .../JavaLibraryReferenceAttribute.cs | 1 + .../GetAdditionalResourcesFromAssemblies.cs | 3 ++ .../Xamarin.Android.Build.Tests/BuildTest.cs | 1 + 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Documentation/guides/messages/xa0121.md diff --git a/Documentation/guides/messages/xa0121.md b/Documentation/guides/messages/xa0121.md new file mode 100644 index 00000000000..c736263a2f1 --- /dev/null +++ b/Documentation/guides/messages/xa0121.md @@ -0,0 +1,34 @@ +--- +title: Xamarin.Android warning XA0121 +description: XA0121 warning code +ms.date: 09/19/2019 +--- +# Xamarin.Android warning XA0121 + +## Issue + +The behavior implemented in the +`` MSBuild task is now +deprecated. + +This MSBuild task is a precursor to [Xamarin.Build.Download][xbd] that +enables downloading of Android packages from the internet. + +Libraries using any of the following custom assembly-level attributes +will encounter this warning: + +* `IncludeAndroidResourcesFromAttribute` +* `NativeLibraryReferenceAttribute` +* `JavaLibraryReferenceAttribute` + +## Solution + +The [Xamarin Support Libraries][supportlibs], can be simply updated to +a newer version on NuGet. + +Library authors will need to remove usage of these deprecated +attributes. Their functionality will be removed in a future version of +Xamarin.Android. + +[xbd]: https://www.nuget.org/packages/Xamarin.Build.Download +[supportlibs]: https://github.com/xamarin/AndroidSupportComponents diff --git a/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs b/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs index e310b7a4123..e89125dfd86 100644 --- a/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs +++ b/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs @@ -3,6 +3,7 @@ namespace Android { [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] + [Obsolete ("This attribute is deprecated and will be removed in a future release.")] public class IncludeAndroidResourcesFromAttribute : ReferenceFilesAttribute { public IncludeAndroidResourcesFromAttribute (string path) diff --git a/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs b/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs index f45f95e76eb..88941e5e649 100644 --- a/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs +++ b/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs @@ -3,6 +3,7 @@ namespace Android { [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] + [Obsolete ("This attribute is deprecated and will be removed in a future release.")] sealed public class NativeLibraryReferenceAttribute : ReferenceFilesAttribute { public NativeLibraryReferenceAttribute (string filename) diff --git a/src/Mono.Android/Android/ReferenceFilesAttribute.cs b/src/Mono.Android/Android/ReferenceFilesAttribute.cs index 6d98891f5de..c73ebc394a2 100644 --- a/src/Mono.Android/Android/ReferenceFilesAttribute.cs +++ b/src/Mono.Android/Android/ReferenceFilesAttribute.cs @@ -1,7 +1,7 @@ using System; namespace Android { - + [Obsolete ("This attribute is deprecated and will be removed in a future release.")] public abstract class ReferenceFilesAttribute : Attribute { internal ReferenceFilesAttribute () {} diff --git a/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs b/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs index c0262389629..a859cc23135 100644 --- a/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs +++ b/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs @@ -3,6 +3,7 @@ namespace Java.Interop { [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] + [Obsolete ("This attribute is deprecated and will be removed in a future release.")] public class JavaLibraryReferenceAttribute : Android.ReferenceFilesAttribute { public JavaLibraryReferenceAttribute (string filename) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs index 62b677a30d1..fc8b6cb6916 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs @@ -113,6 +113,9 @@ internal static string ErrorMessage (CustomAttributeValue attributeValue void AddAttributeValue (ICollection items, CustomAttributeValue attributeValue, string errorCode, string errorFmt, bool isDirectory, string fullPath, string attributeFullName) { + LogCodedWarning ("XA0121", + $"Assembly '{Path.GetFileName (fullPath)}' is using a deprecated attribute '[assembly: {attributeFullName}]'. Use a newer version of this NuGet package or notify the library author."); + if (attributeValue.NamedArguments.Length == 0 || attributeValue.FixedArguments.Length != 1) { LogCodedWarning (errorCode, "Attribute {0} doesn't have expected one constructor agrument", attributeFullName); return; 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 2d71c2284c6..c63bad15f45 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 @@ -2296,6 +2296,7 @@ public void ResourceExtraction ([Values (true, false)] bool useAapt2) using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) { Assert.IsTrue (builder.DesignTimeBuild (proj), "design-time build should have succeeded"); Assert.IsTrue (builder.Build (proj), "build should have succeeded"); + Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, "XA0121"), "Output should contain XA0121 warnings"); var targetAar = Path.Combine (CachePath, "Xamarin.Android.Support.v7.AppCompat", "23.1.1.0", "content", "m2repository", "com", "android", "support", "appcompat-v7", "23.1.1", "appcompat-v7-23.1.1.aar"); if (File.Exists (targetAar)) {