Skip to content

Commit 1a61fa8

Browse files
jonathanpeppersdellis1972
authored andcommitted
[Xamarin.Android.Build.Tasks] remove the code that XA0121 deprecated (#3857)
Context: #3654 Context: https://docs.microsoft.com/en-us/xamarin/android/release-notes/10/10.1#xa0121-deprecation-warning-for-old-xamarinandroidsupport-library-versions In VS 16.4 / Xamarin.Android 10.1, we deprecated `<GetAdditionalResourcesFromAssemblies/>`. This PR removes the behavior completely for 16.5, since it uses SHA1. We aim to remove all SHA1 and MD5 usage for 16.5. NuGet packages I've seen that no longer work: * Android Support Libraries, 25.x and older * Google Play Services older than 44.x I have still been able to use an old Xamarin.Forms (2.3.4) in combination with newer support libraries. ~~ XA0121 is now an error ~~ We give a build error now in `<FilterAssemblies/>` if we encounter the unsupported attributes. This target runs very early in the build, so we have to do it at this point. ~~ JcwGen-Tests ~~ These tests were using these attributes such as: [assembly: Android.IncludeAndroidResourcesFromAttribute ("./", SourceUrl="file:///JavaLib.zip")] [assembly: Java.Interop.JavaLibraryReference ("classes.jar", SourceUrl="file:///JavaLib.zip")] [assembly: Android.NativeLibraryReference ("arm64-v8a/libsimple.so", SourceUrl="file:///NativeLib.zip", Version="native-lib-1")] Instead, I switched to use `@(LibraryProjectZip)` for the `.aar` file and `@(EmbeddedNativeLibrary)` for the `.so` files. ~~ Designer Tests ~~ The designer tests build the MyDriving app: https://github.com/Azure-Samples/MyDriving Which uses old NuGet packages that now fail, and is now in read-only mode on Github. I suspect we may just need to remove that test? error XA0121: Assembly 'Xamarin.Android.Support.CustomTabs' is using '[assembly: Java.Interop.JavaLibraryReferenceAttribute]', which is no longer supported. Use a newer version of this NuGet package or notify the library author.
1 parent c3555ad commit 1a61fa8

37 files changed

+229
-1433
lines changed
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
title: Xamarin.Android warning XA0121
3-
description: XA0121 warning code
4-
ms.date: 09/19/2019
2+
title: Xamarin.Android error XA0121
3+
description: XA0121 error code
4+
ms.date: 10/30/2019
55
---
6-
# Xamarin.Android warning XA0121
6+
# Xamarin.Android error XA0121
77

88
## Issue
99

1010
The behavior implemented in the
11-
`<GetAdditionalResourcesFromAssemblies/>` MSBuild task is now
12-
deprecated.
11+
`<GetAdditionalResourcesFromAssemblies/>` MSBuild task is no longer
12+
supported.
1313

1414
This MSBuild task is a precursor to [Xamarin.Build.Download][xbd] that
1515
enables downloading of Android packages from the internet.
1616

1717
Libraries using any of the following custom assembly-level attributes
18-
will encounter this warning:
18+
will encounter this error:
1919

2020
* `IncludeAndroidResourcesFromAttribute`
2121
* `NativeLibraryReferenceAttribute`
@@ -26,9 +26,8 @@ will encounter this warning:
2626
The [Xamarin Support Libraries][supportlibs], can be simply updated to
2727
a newer version on NuGet.
2828

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.
29+
Library authors will need to remove usage of these attributes. Their
30+
functionality was removed in Xamarin.Android 10.2.
3231

3332
[xbd]: https://www.nuget.org/packages/Xamarin.Build.Download
3433
[supportlibs]: https://github.com/xamarin/AndroidSupportComponents

src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +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.")]
6+
[Obsolete ("This attribute is not longer supported.", error: true)]
77
public class IncludeAndroidResourcesFromAttribute : ReferenceFilesAttribute
88
{
99
public IncludeAndroidResourcesFromAttribute (string path)

src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +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.")]
6+
[Obsolete ("This attribute is not longer supported.", error: true)]
77
sealed public class NativeLibraryReferenceAttribute : ReferenceFilesAttribute
88
{
99
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-
[Obsolete ("This attribute is deprecated and will be removed in a future release.")]
4+
[Obsolete ("This attribute is not longer supported.", error: true)]
55
public abstract class ReferenceFilesAttribute : Attribute
66
{
77
internal ReferenceFilesAttribute () {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +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.")]
6+
[Obsolete ("This attribute is not longer supported.", error: true)]
77
public class JavaLibraryReferenceAttribute : Android.ReferenceFilesAttribute
88
{
99
public JavaLibraryReferenceAttribute (string filename)

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved.
4848
ExtraArgs="$(AndroidResgenExtraArgs)"
4949
ToolPath="$(AaptToolPath)"
5050
ToolExe="$(AaptToolExe)"
51-
AdditionalAndroidResourcePaths="@(_AdditonalAndroidResourceCachePaths)"
5251
ApiLevel="$(_AndroidTargetSdkVersion)"
5352
AndroidUseLatestPlatformSdk="$(AndroidUseLatestPlatformSdk)"
5453
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
@@ -81,7 +80,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved.
8180
AssetDirectory="$(MonoAndroidAssetsDirIntermediate)"
8281
ToolPath="$(AaptToolPath)"
8382
ToolExe="$(AaptToolExe)"
84-
AdditionalAndroidResourcePaths="@(_AdditonalAndroidResourceCachePaths)"
8583
ApiLevel="$(_AndroidTargetSdkVersion)"
8684
AndroidUseLatestPlatformSdk="$(AndroidUseLatestPlatformSdk)"
8785
ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
5050
Condition=" '$(_AndroidUseAapt2)' == 'True' "
5151
>
5252
<CollectNonEmptyDirectories
53-
Directories="@(LibraryResourceDirectories);@(_AdditonalAndroidResourceCachePaths->'%(Identity)\res')"
53+
Directories="@(LibraryResourceDirectories)"
5454
LibraryProjectIntermediatePath="$(_AndroidLibrayProjectIntermediatePath)"
5555
StampDirectory="$(_AndroidStampDirectory)">
5656
<Output TaskParameter="Output" ItemName="_LibraryResourceDirectories" />

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Designer.targets

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ Copyright (C) 2016 Xamarin. All rights reserved.
1919
<Target Name="GetExtraLibraryLocationsForDesigner"
2020
DependsOnTargets="_SetupDesignTimeBuildForCompile"
2121
Returns="ExtraJarLocation;ExtraResourceLocation">
22-
<ReadAdditionalResourcesFromAssemblyCache
23-
Condition="Exists('$(_AndroidResourcePathsCache)')"
24-
CacheFile="$(_AndroidResourcePathsCache)">
25-
<Output TaskParameter="AdditionalAndroidResourcePaths" ItemName="_AdditionalAndroidResourcePaths" />
26-
<Output TaskParameter="AdditionalJavaLibraryReferences" ItemName="_AdditionalJavaLibraryReferences" />
27-
</ReadAdditionalResourcesFromAssemblyCache>
2822
<ReadLibraryProjectImportsCache
2923
Condition="Exists('$(_AndroidLibraryProjectImportsCache)')"
3024
CacheFile="$(_AndroidLibraryProjectImportsCache)">
@@ -41,9 +35,6 @@ Copyright (C) 2016 Xamarin. All rights reserved.
4135
<ExtraJarLocation Include="@(AndroidJavaLibrary->'%(FullPath)')">
4236
<Source>AndroidJavaLibrary</Source>
4337
</ExtraJarLocation>
44-
<ExtraResourceLocation Include="@(_AdditionalAndroidResourcePaths->'%(Identity)\res')">
45-
<Source>AssemblyCache</Source>
46-
</ExtraResourceLocation>
4738
<ExtraResourceLocation Include="@(_LibraryResourceDirectories)">
4839
<Source>LibraryImport</Source>
4940
</ExtraResourceLocation>

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override bool RunTask ()
4343
using (var pe = new PEReader (File.OpenRead (assemblyItem.ItemSpec))) {
4444
var reader = pe.GetMetadataReader ();
4545
var assemblyDefinition = reader.GetAssemblyDefinition ();
46-
var targetFrameworkIdentifier = assemblyDefinition.GetTargetFrameworkIdentifier (reader);
46+
var targetFrameworkIdentifier = GetTargetFrameworkIdentifier (assemblyDefinition, reader);
4747
if (string.Compare (targetFrameworkIdentifier, TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) == 0) {
4848
output.Add (assemblyItem);
4949
continue;
@@ -71,6 +71,40 @@ public override bool RunTask ()
7171
return !Log.HasLoggedErrors;
7272
}
7373

74+
string GetTargetFrameworkIdentifier (AssemblyDefinition assembly, MetadataReader reader)
75+
{
76+
string targetFrameworkIdentifier = null;
77+
foreach (var handle in assembly.GetCustomAttributes ()) {
78+
var attribute = reader.GetCustomAttribute (handle);
79+
var name = reader.GetCustomAttributeFullName (attribute);
80+
switch (name) {
81+
case "System.Runtime.Versioning.TargetFrameworkAttribute":
82+
var arguments = attribute.GetCustomAttributeArguments ();
83+
foreach (var p in arguments.FixedArguments) {
84+
// Of the form "MonoAndroid,Version=v8.1"
85+
var value = p.Value?.ToString ();
86+
if (!string.IsNullOrEmpty (value)) {
87+
int commaIndex = value.IndexOf (",", StringComparison.Ordinal);
88+
if (commaIndex != -1) {
89+
targetFrameworkIdentifier = value.Substring (0, commaIndex);
90+
break;
91+
}
92+
}
93+
}
94+
break;
95+
case "Android.IncludeAndroidResourcesFromAttribute":
96+
case "Android.NativeLibraryReferenceAttribute":
97+
case "Java.Interop.JavaLibraryReferenceAttribute":
98+
Log.LogCodedError ("XA0121",
99+
$"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.");
100+
break;
101+
default:
102+
break;
103+
}
104+
}
105+
return targetFrameworkIdentifier;
106+
}
107+
74108
bool HasReference (MetadataReader reader)
75109
{
76110
foreach (var handle in reader.AssemblyReferences) {

0 commit comments

Comments
 (0)