Skip to content

[release/10.0.1xx] Backport selective R8 obfuscation and optimization - #12752

Merged
jonathanpeppers merged 1 commit into
release/10.0.1xxfrom
jonathanpeppers-backport-r8-obfuscation-net10
Sep 10, 2026
Merged

jonathanpeppers merged 1 commit into
release/10.0.1xxfrom
jonathanpeppers-backport-r8-obfuscation-net10

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

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.

  • keeps $(AndroidR8ObfuscationMode) defaulted to disabled on .NET 10, preserving existing behavior
  • makes private-members available as an explicit opt-in, enabling R8 optimization while preserving Java class/interface and public/protected member names
  • adds XA1050 validation, English resources, documentation, and message documentation for unsupported values
  • gates mode validation on $(AndroidLinkTool) == r8, so unrelated builds are unaffected
  • adds task, packaging, incremental-build, invalid-mode, R8-only validation, and device coverage
  • installs both Android default R8 configuration variants

Release-branch adaptations

The release branch predates main's NativeAOT R8Mapping and user-Java-source rooting infrastructure. Device coverage is therefore adapted to MonoVM and CoreCLR, reads mapping.txt directly, and supplies the explicit keep rule needed for the Java probe. The release task's existing string[] configuration-file shape is retained.

No .apkdesc baselines are changed: unlike main, the .NET 10 servicing default remains disabled, and measured targeted packaging/device coverage did not require release baseline updates. No unrelated Java.Interop version changes are included.

Validation

  • built Xamarin.Android.sln and configured the repository local Android workload
  • built Xamarin.Android.Build.Tests and MSBuildDeviceIntegration
  • R8 task and packaging matrix: 9/9 passed, covering default, explicit disabled, explicit private-members, incremental builds, metadata/optimization state, invalid-mode XA1050, and validation with R8 enabled/disabled
  • physical-device R8 coverage: 2/2 passed on MonoVM and CoreCLR
  • changed XML files parse successfully
  • git diff --check passes
  • final review reported no findings

Backport of #12668; includes #12753.

Copilot AI lite review requested due to automatic review settings September 10, 2026 15:27

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.

🟡 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) (default disabled) with opt-in private-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.txt and proguard-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.

Comment thread src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.

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
jonathanpeppers force-pushed the jonathanpeppers-backport-r8-obfuscation-net10 branch from 7441933 to b9bd72b Compare September 10, 2026 18:16
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 10, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

Test failures unrelated, merging.

@jonathanpeppers
jonathanpeppers merged commit 99d226b into release/10.0.1xx Sep 10, 2026
1 of 2 checks passed
@jonathanpeppers
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`
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants