From 64fce5a4fa8b472775882731f9729d1b670dae55 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 18 Jun 2026 10:25:23 -0500 Subject: [PATCH 1/2] [Xamarin.Android.Build.Tasks] warn XA0149 on legacy __AndroidEnvironment__ resources Class libraries built with the legacy Xamarin.Android tooling embed `__AndroidEnvironment__*` resources inside the managed assembly. The .NET for Android replacement format places these files inside the `.aar` produced by an Android class library under `.net/env/`. NuGet already warns (NU1703) for packages targeting the deprecated `MonoAndroid` framework, but did not call out that any embedded environment files would be silently extracted and merged into the application by `ResolveLibraryProjectImports`. Skip extraction of these embedded resources, and instead emit a new warning `XA0149` so that users (and library authors) know that the file is being ignored. Two message variants are provided so the warning text always names the assembly and, when known, the NuGet package and version supplying it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Documentation/docs-mobile/messages/index.md | 1 + Documentation/docs-mobile/messages/xa0149.md | 45 +++++++++++++++++++ .../Properties/Resources.Designer.cs | 18 ++++++++ .../Properties/Resources.resx | 14 ++++++ .../Tasks/ResolveLibraryProjectImports.cs | 19 ++------ 5 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 Documentation/docs-mobile/messages/xa0149.md diff --git a/Documentation/docs-mobile/messages/index.md b/Documentation/docs-mobile/messages/index.md index 6ccfa15d29f..c3906f90414 100644 --- a/Documentation/docs-mobile/messages/index.md +++ b/Documentation/docs-mobile/messages/index.md @@ -111,6 +111,7 @@ or 'Help->Report a Problem' in Visual Studio for Mac. + [XA0146](xa0146.md): Attempt to check whether '{0}' is a correctly aligned ELF file failed with exception, ignoring alignment check for the file. + [XA0147](xa0147.md): Attempt to check whether '{0}' is a valid ELF file failed with exception, ignoring AOT check for the file. + [XA0148](xa0148.md): Attempt to check whether '{0}' is a valid ELF file failed with exception, ignoring symbol '{1}@{2}' check for the file. ++ [XA0149](xa0149.md): Ignoring legacy Xamarin.Android environment file '{0}' embedded in assembly '{1}' (from NuGet package '{2}' version '{3}'). Environment files from Xamarin.Android class libraries are not supported in .NET for Android. ## XA1xxx: Project related diff --git a/Documentation/docs-mobile/messages/xa0149.md b/Documentation/docs-mobile/messages/xa0149.md new file mode 100644 index 00000000000..db767d7efe3 --- /dev/null +++ b/Documentation/docs-mobile/messages/xa0149.md @@ -0,0 +1,45 @@ +--- +title: .NET for Android warning XA0149 +description: XA0149 warning code +ms.date: 06/18/2026 +f1_keywords: + - "XA0149" +--- + +# .NET for Android warning XA0149 + +## Example messages + +> warning XA0149: Ignoring legacy Xamarin.Android environment file '__AndroidEnvironment__abc123' from NuGet package 'Some.Old.Package' version '1.2.3' in assembly '/path/to/Some.Old.Package.dll'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. Use a newer version of this NuGet package or notify the library author. + +> warning XA0149: Ignoring legacy Xamarin.Android environment file '__AndroidEnvironment__abc123' in assembly '/path/to/SomeLibrary.dll'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. Use a newer version of this assembly or notify the library author. + +## Issue + +A referenced assembly (typically from an older Xamarin.Android class +library or a NuGet package targeting `MonoAndroid`) contains an embedded +`__AndroidEnvironment__*` resource. .NET for Android does not consume +environment files contributed by class libraries via this legacy +mechanism, so the file is being ignored. + +This is closely related to the +[NU1703](https://learn.microsoft.com/nuget/reference/errors-and-warnings/nu1703) +warning that NuGet emits for packages still targeting the deprecated +`MonoAndroid` framework. + +## Solution + +Update to a version of the NuGet package or library that targets +`net-android` (.NET for Android). If you maintain the library, rebuild +it as a .NET for Android class library so that any environment variables +are produced in the supported `.net/env/` AAR layout. + +If the environment variables are required by your application, declare +them directly in your app project using an `@(AndroidEnvironment)` +item: + +```xml + + + +``` diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index 601b39347c6..6d9b7e9df46 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -629,6 +629,24 @@ public static string XA0148 { } } + /// + /// Looks up a localized string similar to Ignoring legacy Xamarin.Android environment file '{0}' from NuGet package '{1}' version '{2}' in assembly '{3}'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. Use a newer version of this NuGet package or notify the library author.. + /// + public static string XA0149 { + get { + return ResourceManager.GetString("XA0149", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ignoring legacy Xamarin.Android environment file '{0}' in assembly '{1}'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. Use a newer version of this assembly or notify the library author.. + /// + public static string XA0149_Assembly { + get { + return ResourceManager.GetString("XA0149_Assembly", resourceCulture); + } + } + /// /// Looks up a localized string similar to There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}. /// diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index e7b8c06d6a8..620b9f7bbaf 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -1193,6 +1193,20 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS {0} - The file path. {1} - The symbol name. {2} - The section name. + + + Ignoring legacy Xamarin.Android environment file '{0}' from NuGet package '{1}' version '{2}' in assembly '{3}'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. Use a newer version of this NuGet package or notify the library author. + The following are literal names and should not be translated: Xamarin.Android, .NET for Android, NuGet. +{0} - The name of the embedded environment resource (such as __AndroidEnvironment__abc123). +{1} - The NuGet package id. +{2} - The NuGet package version. +{3} - The full path to the assembly that contains the environment resource. + + + Ignoring legacy Xamarin.Android environment file '{0}' in assembly '{1}'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. Use a newer version of this assembly or notify the library author. + The following are literal names and should not be translated: Xamarin.Android, .NET for Android. +{0} - The name of the embedded environment resource (such as __AndroidEnvironment__abc123). +{1} - The full path to the assembly that contains the environment resource. Executable 'gradlew' not found in project directory '{0}'. Please ensure the path to your Gradle project folder is correct, and that it contains Gradle Wrapper scripts. diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 845003bd3e5..bb6ceac5dd8 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -243,13 +243,6 @@ void Extract ( [NuGetPackageId] = nuGetPackageId, [NuGetPackageVersion] = nuGetPackageVersion, })); - foreach (var env in Directory.EnumerateFiles (outDirForDll, "__AndroidEnvironment__*", SearchOption.TopDirectoryOnly)) { - resolvedEnvironments.Add (new TaskItem (env, new Dictionary { - [OriginalFile] = assemblyPath, - [NuGetPackageId] = nuGetPackageId, - [NuGetPackageVersion] = nuGetPackageVersion, - })); - } continue; } @@ -267,15 +260,11 @@ void Extract ( // android environment files if (name.StartsWith ("__AndroidEnvironment__", StringComparison.OrdinalIgnoreCase)) { - var outFile = Path.Combine (outDirForDll, name); - using (var stream = pe.GetEmbeddedResourceStream (resource)) { - updated |= Files.CopyIfStreamChanged (stream, outFile); + if (nuGetPackageId.IsNullOrEmpty ()) { + Log.LogCodedWarning ("XA0149", Properties.Resources.XA0149_Assembly, name, assemblyPath); + } else { + Log.LogCodedWarning ("XA0149", Properties.Resources.XA0149, name, nuGetPackageId, nuGetPackageVersion, assemblyPath); } - resolvedEnvironments.Add (new TaskItem (Path.GetFullPath (outFile), new Dictionary { - [OriginalFile] = assemblyPath, - [NuGetPackageId] = nuGetPackageId, - [NuGetPackageVersion] = nuGetPackageVersion, - })); } // embedded jars (EmbeddedJar, EmbeddedReferenceJar) else if (name.EndsWith (".jar", StringComparison.InvariantCultureIgnoreCase)) { From 475514e7aa688b9bdfdb69963b28a510c2a1fffc Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 18 Jun 2026 15:16:13 -0500 Subject: [PATCH 2/2] Fix XA0149 placeholder ordering in messages index Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Documentation/docs-mobile/messages/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/docs-mobile/messages/index.md b/Documentation/docs-mobile/messages/index.md index c3906f90414..4dfe2ffdf55 100644 --- a/Documentation/docs-mobile/messages/index.md +++ b/Documentation/docs-mobile/messages/index.md @@ -111,7 +111,7 @@ or 'Help->Report a Problem' in Visual Studio for Mac. + [XA0146](xa0146.md): Attempt to check whether '{0}' is a correctly aligned ELF file failed with exception, ignoring alignment check for the file. + [XA0147](xa0147.md): Attempt to check whether '{0}' is a valid ELF file failed with exception, ignoring AOT check for the file. + [XA0148](xa0148.md): Attempt to check whether '{0}' is a valid ELF file failed with exception, ignoring symbol '{1}@{2}' check for the file. -+ [XA0149](xa0149.md): Ignoring legacy Xamarin.Android environment file '{0}' embedded in assembly '{1}' (from NuGet package '{2}' version '{3}'). Environment files from Xamarin.Android class libraries are not supported in .NET for Android. ++ [XA0149](xa0149.md): Ignoring legacy Xamarin.Android environment file '{0}' from NuGet package '{1}' version '{2}' in assembly '{3}'. Environment files from Xamarin.Android class libraries are not supported in .NET for Android. ## XA1xxx: Project related