Skip to content

[Xamarin.Android.Build.Tasks] warn XA0149 on legacy __AndroidEnvironment__ resources#11700

Open
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers/legendary-goggles
Open

[Xamarin.Android.Build.Tasks] warn XA0149 on legacy __AndroidEnvironment__ resources#11700
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers/legendary-goggles

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

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 that still target the
deprecated MonoAndroid target framework (see also the breaking-change
notice in dotnet/docs#53550), but it does not call out that any
embedded environment files would be silently extracted and merged into
the application by ResolveLibraryProjectImports.

Changes

  • Tasks/ResolveLibraryProjectImports.cs:
    • Refresh path: stop extracting __AndroidEnvironment__* embedded
      resources; emit XA0149 instead.
    • Cached path: drop the enumeration that re-surfaced previously
      extracted env files. We don't warn again on incremental builds —
      the warning is intended to be loud on the build that actually
      refreshes the assembly.
  • New warning code XA0149 with two variants, modeled on the
    XA0141 (16 KB shared-library) warning so the message always names
    the assembly and, when available, the NuGet package id and version:
    • XA0149: Ignoring legacy Xamarin.Android environment file '{0}' from NuGet package '{1}' version '{2}' in assembly '{3}'. …
    • XA0149_Assembly: Ignoring legacy Xamarin.Android environment file '{0}' in assembly '{1}'. …
  • Documentation/docs-mobile/messages/xa0149.md + index.md entry.

The new .net/env/*.env AAR layout used by .NET for Android class
libraries is untouched and still flows through @(LibraryEnvironments).

…ent__ 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>
Copilot AI review requested due to automatic review settings June 18, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new build warning (XA0149) to surface and ignore legacy __AndroidEnvironment__* embedded resources from Xamarin.Android-era class libraries/NuGet packages, instead of silently extracting and merging them into the app via ResolveLibraryProjectImports.

Changes:

  • Stop extracting __AndroidEnvironment__* embedded resources during ResolveLibraryProjectImports refresh; emit XA0149 (with package-aware and assembly-only variants).
  • Add XA0149/XA0149_Assembly strings to Resources.resx (and generated designer).
  • Add documentation page for XA0149 and link it from the message index.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs Emit XA0149 warnings for legacy embedded env resources instead of extracting them; remove cached-path env enumeration.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Add localized strings for XA0149 and XA0149_Assembly.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Generated accessors for the new XA0149 resource strings.
Documentation/docs-mobile/messages/xa0149.md New documentation page describing XA0149, causes, and remediation.
Documentation/docs-mobile/messages/index.md Add XA0149 entry to the message index.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file

Comment on lines 262 to +266
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);
+ [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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants