Repository navigation
[release/10.0.1xx] Backport selective R8 obfuscation and optimization - #12752
Merged
jonathanpeppers merged 1 commit intoSep 10, 2026
Merged
jonathanpeppers merged 1 commit into
jonathanpeppers merged 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A new unit test expectation is inconsistent with the implementation output, and the XA1050 validation target’s conditions can allow invalid values to reach the task and fail with a non-XA1050 exception.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Backports the selective R8 obfuscation/optimization feature to the .NET 10 servicing branch by introducing the public $(AndroidR8ObfuscationMode) property (defaulting to disabled) and wiring it through MSBuild, the R8 task, packaging, tests, and documentation.
Changes:
- Add
$(AndroidR8ObfuscationMode)(defaultdisabled) with opt-inprivate-members, including build-time validation (XA1050) and rule generation. - Update R8/proguard configuration selection to install and use both Android default config variants (
proguard-android.txtandproguard-android-optimize.txt) based on the mode. - Add/extend unit, packaging, and device integration coverage plus documentation and message docs for XA1050.
File summaries
| File | Description |
|---|---|
| tests/MSBuildDeviceIntegration/Tests/R8ObfuscationTests.cs | Adds device-level verification that private/package-private Java members are renamed in private-members mode while public/protected names remain stable. |
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.D8.targets | Passes $(AndroidR8ObfuscationMode) through to the R8 task. |
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets | Defines default for AndroidR8ObfuscationMode, caches it for incremental builds, selects default proguard config based on mode, and adds XA1050 validation target. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs | Adds a KnownProperties constant for AndroidR8ObfuscationMode to use in tests. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/R8Tests.cs | Adds unit tests for the obfuscation rule writer, including invalid-mode coverage. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs | Extends packaging tests to validate r8.json optimization-state and ensure invalid modes fail with XA1050. |
| src/Xamarin.Android.Build.Tasks/Tasks/R8.cs | Implements ObfuscationMode parameter and emits mode-specific obfuscation rules into the generated proguard config. |
| src/Xamarin.Android.Build.Tasks/Resources/proguard_xamarin.cfg | Removes hardcoded -dontobfuscate and adds keep rule for net.dot.android.ApplicationRegistration. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | Adds localized XA1050 error message string. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs | Adds generated accessor for XA1050 resource. |
| src/proguard-android/proguard-android.targets | Produces and installs both default proguard rule files, including the optimize variant. |
| Documentation/docs-mobile/TOC.yml | Adds XA1050 to documentation TOC. |
| Documentation/docs-mobile/messages/xa1050.md | Adds XA1050 error documentation page. |
| Documentation/docs-mobile/messages/index.md | Adds XA1050 to the messages index. |
| Documentation/docs-mobile/building-apps/build-properties.md | Documents AndroidR8ObfuscationMode behavior and supported values. |
| build-tools/installers/create-installers.targets | Ensures proguard-android-optimize.txt is included in installers. |
Review details
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
- Files reviewed: 15/16 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
jonathanpeppers
force-pushed
the
jonathanpeppers-backport-r8-obfuscation-net10
branch
from
September 10, 2026 18:15
4be2640 to
7441933
Compare
Keep R8 obfuscation disabled by default on .NET 10 while allowing private Java members to be obfuscated and optimized when explicitly requested. Validate mode values only when R8 is enabled. Co-authored-by: Copilot App <[email protected]>
jonathanpeppers
force-pushed
the
jonathanpeppers-backport-r8-obfuscation-net10
branch
from
September 10, 2026 18:16
7441933 to
b9bd72b
Compare
Member
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
simonrozsival
approved these changes
Sep 10, 2026
Member
Author
|
Test failures unrelated, merging. |
jonathanpeppers
deleted the
jonathanpeppers-backport-r8-obfuscation-net10
branch
September 10, 2026 20:53
simonrozsival
pushed a commit
that referenced
this pull request
Sep 11, 2026
## Description Follow-up to #12668 and review feedback on #12752. Ports `_ValidateAndroidR8ObfuscationMode` to `main` and gates it on `$(AndroidLinkTool) == 'r8'`. Invalid `AndroidR8ObfuscationMode` values report XA1050 only when R8 is selected, while non-R8 builds remain unaffected. This preserves the behavior and `private-members` default introduced by #12668. ## Tests - `dotnet-local.cmd build src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj -v:minimal --no-restore` - `dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "Name~InvalidR8ObfuscationModeIsValidatedOnlyForR8" -v:minimal` - invalid mode without R8 succeeds - invalid mode with R8 fails with XA1050 - XML parsing for `Xamarin.Android.Common.targets` and `Resources.resx` - `git diff --check`
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Backports the complete relevant selective R8 obfuscation/optimization work from #12668 to .NET 10 servicing and incorporates the follow-up validation changes from #12753.
$(AndroidR8ObfuscationMode)defaulted todisabledon .NET 10, preserving existing behaviorprivate-membersavailable as an explicit opt-in, enabling R8 optimization while preserving Java class/interface and public/protected member namesXA1050validation, English resources, documentation, and message documentation for unsupported values$(AndroidLinkTool) == r8, so unrelated builds are unaffectedRelease-branch adaptations
The release branch predates main's NativeAOT
R8Mappingand user-Java-source rooting infrastructure. Device coverage is therefore adapted to MonoVM and CoreCLR, readsmapping.txtdirectly, and supplies the explicit keep rule needed for the Java probe. The release task's existingstring[]configuration-file shape is retained.No
.apkdescbaselines are changed: unlike main, the .NET 10 servicing default remainsdisabled, and measured targeted packaging/device coverage did not require release baseline updates. No unrelated Java.Interop version changes are included.Validation
Xamarin.Android.slnand configured the repository local Android workloadXamarin.Android.Build.TestsandMSBuildDeviceIntegrationdisabled, explicitprivate-members, incremental builds, metadata/optimization state, invalid-modeXA1050, and validation with R8 enabled/disabledgit diff --checkpassesBackport of #12668; includes #12753.