Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] remove the code that XA0121 deprecated (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jonathanpeppers authored and jonpryor committed Nov 20, 2019
1 parent 46f2a6a commit 63a6987
Show file tree
Hide file tree
Showing 37 changed files with 229 additions and 1,433 deletions.
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

0 comments on commit 63a6987

Please sign in to comment.