[Xamarin.Android.Build.Tasks] Skip library proguard.txt with disallowed global options#11709
Open
jonathanpeppers wants to merge 2 commits into
Open
[Xamarin.Android.Build.Tasks] Skip library proguard.txt with disallowed global options#11709jonathanpeppers wants to merge 2 commits into
jonathanpeppers wants to merge 2 commits into
Conversation
…ed global options Android Gradle Plugin 9.0 disallows `global'' ProGuard options such as -printmapping, -printconfiguration, -printusage, -printseeds, and -dump in consumer keep files shipped inside an .aar. AGP either fails library publishing or silently strips the options when consuming a pre-built dependency: https://developer.android.com/build/releases/agp-9-0-0-release-notes#behavior-changes Bring the same protection to .NET for Android: when an .aar's proguard.txt (extracted by ResolveLibraryProjectImports) contains one of these options, skip the whole file when invoking R8 and emit a new XA4322 warning naming the NuGet package (or .aar path) the configuration came from. Files generated by us or added directly by the user are untouched. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the R8 MSBuild task to align with AGP 9.0 behavior by detecting and skipping library-provided proguard.txt files that contain disallowed global ProGuard options, emitting a new XA4322 warning to keep builds reliable and avoid unintended output redirection.
Changes:
- Change
R8.ProguardConfigurationFilesfromstring[]toITaskItem[]so metadata (OriginalFile,NuGetPackageId,NuGetPackageVersion) can be used to identify library-provided configs. - Add scanning logic in
R8.csto skip offending libraryproguard.txtfiles and logXA4322. - Add
XA4322resources + documentation, and a unit test for option detection.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/R8Tests.cs | Adds unit tests for TryGetDisallowedOption parsing. |
| src/Xamarin.Android.Build.Tasks/Tasks/R8.cs | Implements library proguard option detection + warning emission; switches config input to ITaskItem[]. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | Adds localized message text for XA4322. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs | Adds generated accessor for XA4322. |
| Documentation/docs-mobile/messages/xa4322.md | Adds a new warning documentation page for XA4322. |
| Documentation/docs-mobile/messages/index.md | Adds XA4322 to the messages index. |
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
…heck Per the AGP 9.0 release notes, the primary global options called out are -dontoptimize and -dontobfuscate. Add them to DisallowedLibraryProguardOptions so libraries cannot silently disable optimization/obfuscation for consuming apps. Also tighten TryGetDisallowedOption to require an end-of-token boundary (end-of-line or whitespace) after the matched option, so e.g. '-printmappingFoo' is no longer wrongly treated as '-printmapping'. Tests cover both new options and the boundary case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fixes/aligns with the behavior introduced in Android Gradle Plugin 9.0:
The same restriction applies to R8 for options that control where build outputs go —
-printmapping,-printconfiguration,-printusage,-printseeds,-dump. When a third-party.aar(or NuGet package wrapping one) ships aproguard.txtwith one of those directives, currentdotnet buildeither:Change
In
R8.cs, afterResolveLibraryProjectImportshas extracted each.aar'sproguard.txt, scan the file (only for items that carry theOriginalFilemetadata — i.e. library-provided files, not ones we generate or the user added). If any disallowed global option is present:--pg-conf, andXA4322warning is emitted naming the source: NuGet package id + version when available, otherwise the.aarpath.Example warning:
User-authored
<ProguardConfiguration Include="..." />items in the app project, and the SDK-generated configs (proguard_xamarin.cfg,proguard_project_primary.cfg, etc.) are left untouched.Notes
ProguardConfigurationFilesparameter on theR8task changed fromstring[]toITaskItem[]so we can read theOriginalFile/NuGetPackageId/NuGetPackageVersionmetadata thatResolveLibraryProjectImportsalready attaches. No targets needed updating —@(_ProguardConfiguration)/@(ProguardConfiguration)already flow through as items.-keeprules to the app's ownProguardConfiguration) for users blocked on a 3rd-party library fix.Tests
R8Tests.TryGetDisallowedOptionparametric unit test covers each option, leading whitespace (spaces and tabs), comments, empty lines, and case-insensitive matching.-printmapping out.txtto any AAR'sproguard.txtand observing theXA4322warning instead of the build failure / silent mapping override.