-
Notifications
You must be signed in to change notification settings - Fork 578
[Xamarin.Android.Build.Tasks] Skip library proguard.txt with disallowed global options #11709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| title: .NET for Android warning XA4322 | ||
| description: XA4322 warning code | ||
| ms.date: 06/22/2026 | ||
| f1_keywords: | ||
| - "XA4322" | ||
| --- | ||
|
|
||
| # .NET for Android warning XA4322 | ||
|
|
||
| ## Example messages | ||
|
|
||
| ``` | ||
| warning XA4322: Skipping library ProGuard configuration file 'obj/Debug/net10.0-android/lp/0/jl/proguard.txt' (from NuGet package 'Acme.SomeLibrary' 1.2.3) because it contains the unsupported global option '-printmapping'. Global ProGuard options are only allowed in application projects. | ||
| ``` | ||
|
|
||
| ## Issue | ||
|
|
||
| An Android library (`.aar`) shipped a `proguard.txt` file (a "consumer ProGuard | ||
| configuration") that contains a global ProGuard option such as `-dontoptimize`, | ||
| `-dontobfuscate`, `-printmapping`, `-printconfiguration`, `-printusage`, | ||
| `-printseeds`, or `-dump`. | ||
|
|
||
| These options control the entire build (for example, where R8 writes the | ||
| mapping file) and must only be set by the application project that consumes the | ||
| library. They are not allowed inside an `.aar`'s `proguard.txt`. This matches | ||
| the behavior introduced in [Android Gradle Plugin 9.0](https://developer.android.com/build/releases/agp-9-0-0-release-notes#behavior-changes), | ||
| where R8 either fails library publishing or silently ignores such global | ||
| options when they appear in a pre-compiled dependency (JAR or AAR). To keep | ||
| your build working, .NET for Android skips the entire offending file before | ||
| invoking R8 and emits this warning. | ||
|
|
||
| ## Solution | ||
|
|
||
| If you own the library, remove the global options from its `proguard.txt` / | ||
| `ProguardConfiguration` items and instead set them in the application project's | ||
| own `ProguardConfiguration` (for example, by setting | ||
| `$(AndroidProguardMappingFile)` to control where the mapping file is written). | ||
| Once the global options are removed, the library's keep rules will once again | ||
| be passed to R8. | ||
|
|
||
| If you do not own the library, file an issue with its maintainers and ask them | ||
| to remove the disallowed options. Until then, R8 will not see any of the keep | ||
| rules from this library's `proguard.txt`, which may cause needed code to be | ||
| shrunk. Add equivalent `-keep` rules to your own application's | ||
| `ProguardConfiguration` as a workaround. |
9 changes: 9 additions & 0 deletions
9
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
35 changes: 35 additions & 0 deletions
35
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/R8Tests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using NUnit.Framework; | ||
| using Xamarin.Android.Tasks; | ||
|
|
||
| namespace Xamarin.Android.Build.Tests | ||
| { | ||
| [TestFixture] | ||
| public class R8Tests | ||
| { | ||
| [TestCase ("-keep class com.example.Foo { *; }", false, "")] | ||
| [TestCase ("-dontwarn com.example.**", false, "")] | ||
| [TestCase ("# -printmapping comment", false, "")] | ||
| [TestCase ("", false, "")] | ||
| [TestCase ("-printmappingFoo foo.txt", false, "")] // token-boundary: must not match -printmapping | ||
| [TestCase ("-dumpsterfire", false, "")] // token-boundary: must not match -dump | ||
| [TestCase ("-printmapping mapping.txt", true, "-printmapping")] | ||
| [TestCase ("-printmapping", true, "-printmapping")] // option with no argument | ||
| [TestCase (" -printmapping mapping.txt", true, "-printmapping")] | ||
| [TestCase ("\t-printseeds seeds.txt", true, "-printseeds")] | ||
| [TestCase ("-printusage usage.txt", true, "-printusage")] | ||
| [TestCase ("-printconfiguration config.txt", true, "-printconfiguration")] | ||
| [TestCase ("-dump dump.txt", true, "-dump")] | ||
| [TestCase ("-dontoptimize", true, "-dontoptimize")] | ||
| [TestCase ("-dontobfuscate", true, "-dontobfuscate")] | ||
| [TestCase ("-PrintMapping mapping.txt", true, "-printmapping")] // case-insensitive | ||
| [TestCase ("-DUMP dump.txt", true, "-dump")] | ||
| [TestCase ("-DontOptimize", true, "-dontoptimize")] | ||
| public void TryGetDisallowedOption (string line, bool expected, string expectedOption) | ||
| { | ||
| var actual = R8.TryGetDisallowedOption (line, out var option); | ||
| Assert.AreEqual (expected, actual); | ||
| Assert.AreEqual (expectedOption, option); | ||
| } | ||
| } | ||
| } | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.