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] remove the code that XA0121 deprecates #3857

Merged
merged 1 commit into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Documentation/guides/messages/xa0121.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
title: Xamarin.Android warning XA0121
description: XA0121 warning code
ms.date: 09/19/2019
title: Xamarin.Android error XA0121
description: XA0121 error code
ms.date: 10/30/2019
---
# Xamarin.Android warning XA0121
# Xamarin.Android error XA0121

## Issue

The behavior implemented in the
`<GetAdditionalResourcesFromAssemblies/>` MSBuild task is now
deprecated.
`<GetAdditionalResourcesFromAssemblies/>` MSBuild task is no longer
supported.

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:
will encounter this error:

* `IncludeAndroidResourcesFromAttribute`
* `NativeLibraryReferenceAttribute`
Expand All @@ -26,9 +26,8 @@ will encounter this warning:
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.
Library authors will need to remove usage of these attributes. Their
functionality was removed in Xamarin.Android 10.2.

[xbd]: https://www.nuget.org/packages/Xamarin.Build.Download
[supportlibs]: https://github.com/xamarin/AndroidSupportComponents
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Android {

[AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
[Obsolete ("This attribute is not longer supported.", error: true)]
public class IncludeAndroidResourcesFromAttribute : ReferenceFilesAttribute
{
public IncludeAndroidResourcesFromAttribute (string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Android {

[AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
[Obsolete ("This attribute is not longer supported.", error: true)]
sealed public class NativeLibraryReferenceAttribute : ReferenceFilesAttribute
{
public NativeLibraryReferenceAttribute (string filename)
Expand Down
2 changes: 1 addition & 1 deletion src/Mono.Android/Android/ReferenceFilesAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace Android {
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
[Obsolete ("This attribute is not longer supported.", error: true)]
public abstract class ReferenceFilesAttribute : Attribute
{
internal ReferenceFilesAttribute () {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Java.Interop {

[AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)]
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
[Obsolete ("This attribute is not longer supported.", error: true)]
public class JavaLibraryReferenceAttribute : Android.ReferenceFilesAttribute
{
public JavaLibraryReferenceAttribute (string filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved.
ExtraArgs="$(AndroidResgenExtraArgs)"
ToolPath="$(AaptToolPath)"
ToolExe="$(AaptToolExe)"
AdditionalAndroidResourcePaths="@(_AdditonalAndroidResourceCachePaths)"
ApiLevel="$(_AndroidTargetSdkVersion)"
AndroidUseLatestPlatformSdk="$(AndroidUseLatestPlatformSdk)"
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
Expand Down Expand Up @@ -81,7 +80,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved.
AssetDirectory="$(MonoAndroidAssetsDirIntermediate)"
ToolPath="$(AaptToolPath)"
ToolExe="$(AaptToolExe)"
AdditionalAndroidResourcePaths="@(_AdditonalAndroidResourceCachePaths)"
ApiLevel="$(_AndroidTargetSdkVersion)"
AndroidUseLatestPlatformSdk="$(AndroidUseLatestPlatformSdk)"
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
Condition=" '$(_AndroidUseAapt2)' == 'True' "
>
<CollectNonEmptyDirectories
Directories="@(LibraryResourceDirectories);@(_AdditonalAndroidResourceCachePaths->'%(Identity)\res')"
Directories="@(LibraryResourceDirectories)"
LibraryProjectIntermediatePath="$(_AndroidLibrayProjectIntermediatePath)"
StampDirectory="$(_AndroidStampDirectory)">
<Output TaskParameter="Output" ItemName="_LibraryResourceDirectories" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ Copyright (C) 2016 Xamarin. All rights reserved.
<Target Name="GetExtraLibraryLocationsForDesigner"
DependsOnTargets="_SetupDesignTimeBuildForCompile"
Returns="ExtraJarLocation;ExtraResourceLocation">
<ReadAdditionalResourcesFromAssemblyCache
Condition="Exists('$(_AndroidResourcePathsCache)')"
CacheFile="$(_AndroidResourcePathsCache)">
<Output TaskParameter="AdditionalAndroidResourcePaths" ItemName="_AdditionalAndroidResourcePaths" />
<Output TaskParameter="AdditionalJavaLibraryReferences" ItemName="_AdditionalJavaLibraryReferences" />
</ReadAdditionalResourcesFromAssemblyCache>
<ReadLibraryProjectImportsCache
Condition="Exists('$(_AndroidLibraryProjectImportsCache)')"
CacheFile="$(_AndroidLibraryProjectImportsCache)">
Expand All @@ -41,9 +35,6 @@ Copyright (C) 2016 Xamarin. All rights reserved.
<ExtraJarLocation Include="@(AndroidJavaLibrary->'%(FullPath)')">
<Source>AndroidJavaLibrary</Source>
</ExtraJarLocation>
<ExtraResourceLocation Include="@(_AdditionalAndroidResourcePaths->'%(Identity)\res')">
<Source>AssemblyCache</Source>
</ExtraResourceLocation>
<ExtraResourceLocation Include="@(_LibraryResourceDirectories)">
<Source>LibraryImport</Source>
</ExtraResourceLocation>
Expand Down
36 changes: 35 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override bool RunTask ()
using (var pe = new PEReader (File.OpenRead (assemblyItem.ItemSpec))) {
var reader = pe.GetMetadataReader ();
var assemblyDefinition = reader.GetAssemblyDefinition ();
var targetFrameworkIdentifier = assemblyDefinition.GetTargetFrameworkIdentifier (reader);
var targetFrameworkIdentifier = GetTargetFrameworkIdentifier (assemblyDefinition, reader);
if (string.Compare (targetFrameworkIdentifier, TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) == 0) {
output.Add (assemblyItem);
continue;
Expand Down Expand Up @@ -71,6 +71,40 @@ public override bool RunTask ()
return !Log.HasLoggedErrors;
}

string GetTargetFrameworkIdentifier (AssemblyDefinition assembly, MetadataReader reader)
{
string targetFrameworkIdentifier = null;
foreach (var handle in assembly.GetCustomAttributes ()) {
var attribute = reader.GetCustomAttribute (handle);
var name = reader.GetCustomAttributeFullName (attribute);
switch (name) {
case "System.Runtime.Versioning.TargetFrameworkAttribute":
var arguments = attribute.GetCustomAttributeArguments ();
foreach (var p in arguments.FixedArguments) {
// Of the form "MonoAndroid,Version=v8.1"
var value = p.Value?.ToString ();
if (!string.IsNullOrEmpty (value)) {
int commaIndex = value.IndexOf (",", StringComparison.Ordinal);
if (commaIndex != -1) {
targetFrameworkIdentifier = value.Substring (0, commaIndex);
break;
}
}
}
break;
case "Android.IncludeAndroidResourcesFromAttribute":
case "Android.NativeLibraryReferenceAttribute":
case "Java.Interop.JavaLibraryReferenceAttribute":
Log.LogCodedError ("XA0121",
$"Assembly '{reader.GetString (assembly.Name)}' is using '[assembly: {name}]', which is no longer supported. Use a newer version of this NuGet package or notify the library author.");
break;
default:
break;
}
}
return targetFrameworkIdentifier;
}

bool HasReference (MetadataReader reader)
{
foreach (var handle in reader.AssemblyReferences) {
Expand Down
Loading