[Xamarin.Android.Build.Tasks] warn XA0149 on legacy __AndroidEnvironment__ resources#11700
Open
jonathanpeppers wants to merge 1 commit into
Open
[Xamarin.Android.Build.Tasks] warn XA0149 on legacy __AndroidEnvironment__ resources#11700jonathanpeppers wants to merge 1 commit into
__AndroidEnvironment__ resources#11700jonathanpeppers wants to merge 1 commit into
Conversation
…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>
Contributor
There was a problem hiding this comment.
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 duringResolveLibraryProjectImportsrefresh; 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.aarproduced by an Android class library under.net/env/.NuGet already warns NU1703 for packages that still target the
deprecated
MonoAndroidtarget framework (see also the breaking-changenotice 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:__AndroidEnvironment__*embeddedresources; emit
XA0149instead.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.
XA0149with two variants, modeled on theXA0141(16 KB shared-library) warning so the message always namesthe 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.mdentry.The new
.net/env/*.envAAR layout used by .NET for Android classlibraries is untouched and still flows through
@(LibraryEnvironments).