Skip to content

Commit e3cecfa

Browse files
jonathanpeppersjonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] deprecate <GetAdditionalResourcesFromAssemblies/> (#3654)
The `<GetAdditionalResourcesFromAssemblies/>` MSBuild task is the precursor to the [Xamarin.Build.Download NuGet package][0]. 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 attributes as well. [0]: https://www.nuget.org/packages/Xamarin.Build.Download/
1 parent 3adbab5 commit e3cecfa

File tree

7 files changed

+42
-1
lines changed

7 files changed

+42
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Xamarin.Android warning XA0121
3+
description: XA0121 warning code
4+
ms.date: 09/19/2019
5+
---
6+
# Xamarin.Android warning XA0121
7+
8+
## Issue
9+
10+
The behavior implemented in the
11+
`<GetAdditionalResourcesFromAssemblies/>` MSBuild task is now
12+
deprecated.
13+
14+
This MSBuild task is a precursor to [Xamarin.Build.Download][xbd] that
15+
enables downloading of Android packages from the internet.
16+
17+
Libraries using any of the following custom assembly-level attributes
18+
will encounter this warning:
19+
20+
* `IncludeAndroidResourcesFromAttribute`
21+
* `NativeLibraryReferenceAttribute`
22+
* `JavaLibraryReferenceAttribute`
23+
24+
## Solution
25+
26+
The [Xamarin Support Libraries][supportlibs], can be simply updated to
27+
a newer version on NuGet.
28+
29+
Library authors will need to remove usage of these deprecated
30+
attributes. Their functionality will be removed in a future version of
31+
Xamarin.Android.
32+
33+
[xbd]: https://www.nuget.org/packages/Xamarin.Build.Download
34+
[supportlibs]: https://github.com/xamarin/AndroidSupportComponents

src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Android {
44

55
[AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
6+
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
67
public class IncludeAndroidResourcesFromAttribute : ReferenceFilesAttribute
78
{
89
public IncludeAndroidResourcesFromAttribute (string path)

src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Android {
44

55
[AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
6+
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
67
sealed public class NativeLibraryReferenceAttribute : ReferenceFilesAttribute
78
{
89
public NativeLibraryReferenceAttribute (string filename)

src/Mono.Android/Android/ReferenceFilesAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22

33
namespace Android {
4-
4+
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
55
public abstract class ReferenceFilesAttribute : Attribute
66
{
77
internal ReferenceFilesAttribute () {}

src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Java.Interop {
44

55
[AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
6+
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
67
public class JavaLibraryReferenceAttribute : Android.ReferenceFilesAttribute
78
{
89
public JavaLibraryReferenceAttribute (string filename)

src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ internal static string ErrorMessage (CustomAttributeValue<object> attributeValue
113113
void AddAttributeValue (ICollection<string> items, CustomAttributeValue<object> attributeValue, string errorCode, string errorFmt,
114114
bool isDirectory, string fullPath, string attributeFullName)
115115
{
116+
LogCodedWarning ("XA0121",
117+
$"Assembly '{Path.GetFileName (fullPath)}' is using a deprecated attribute '[assembly: {attributeFullName}]'. Use a newer version of this NuGet package or notify the library author.");
118+
116119
if (attributeValue.NamedArguments.Length == 0 || attributeValue.FixedArguments.Length != 1) {
117120
LogCodedWarning (errorCode, "Attribute {0} doesn't have expected one constructor agrument", attributeFullName);
118121
return;

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,7 @@ public void ResourceExtraction ([Values (true, false)] bool useAapt2)
22962296
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
22972297
Assert.IsTrue (builder.DesignTimeBuild (proj), "design-time build should have succeeded");
22982298
Assert.IsTrue (builder.Build (proj), "build should have succeeded");
2299+
Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, "XA0121"), "Output should contain XA0121 warnings");
22992300
var targetAar = Path.Combine (CachePath, "Xamarin.Android.Support.v7.AppCompat", "23.1.1.0",
23002301
"content", "m2repository", "com", "android", "support", "appcompat-v7", "23.1.1", "appcompat-v7-23.1.1.aar");
23012302
if (File.Exists (targetAar)) {

0 commit comments

Comments
 (0)