Skip to content

[r8] Validate obfuscation mode only when R8 is enabled - #12753

Merged
simonrozsival merged 2 commits into
mainfrom
jonathanpeppers-fix-r8-private-obfuscation
Sep 11, 2026
Merged

simonrozsival merged 2 commits into
mainfrom
jonathanpeppers-fix-r8-private-obfuscation

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

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

Validate AndroidR8ObfuscationMode only when R8 actually executes, avoiding fragile application-property target conditions while reporting XA1050 for unsupported values.

Co-authored-by: Copilot App <[email protected]>
Copilot AI lite review requested due to automatic review settings September 10, 2026 16:49

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.

🟢 Approval recommended

The change is scoped, test-covered, and the only noted feedback is a non-blocking test robustness suggestion.

Pull request overview

This PR moves validation of $(AndroidR8ObfuscationMode) into the R8 MSBuild task so unsupported values surface as XA1050 only when R8 actually runs, avoiding earlier MSBuild-time validation pitfalls.

Changes:

  • Add XA1050 validation inside R8.RunTask() to reject unsupported obfuscation modes at execution time.
  • Add a unit test asserting an invalid mode fails execution and reports XA1050.
  • Add localized resources + message documentation and wire it into the docs index/TOC.
File summaries
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/R8Tests.cs Adds a regression test for invalid obfuscation-mode validation (XA1050).
src/Xamarin.Android.Build.Tasks/Tasks/R8.cs Validates ObfuscationMode at task execution and logs XA1050 on invalid values.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds the localized XA1050 message text.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Adds the generated accessor for XA1050.
Documentation/docs-mobile/TOC.yml Adds XA1050 to the docs TOC.
Documentation/docs-mobile/messages/xa1050.md Introduces the XA1050 error documentation page.
Documentation/docs-mobile/messages/index.md Adds XA1050 to the message index.
Review details

Files not reviewed (1)

  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
  • Files reviewed: 6/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

Move XA1050 validation to the MSBuild target introduced by the release-branch fix and gate it on AndroidLinkTool=r8, so unrelated builds are unaffected.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers jonathanpeppers changed the title [r8] Validate obfuscation mode when R8 runs [r8] Validate obfuscation mode only when R8 is enabled Sep 10, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #12753

@github-actions github-actions Bot 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.

⚠️ Needs Changes — 0 errors, 1 warning, 0 suggestions.

The XA1050 resource, documentation, and R8-only target condition are consistent with the supported AndroidR8ObfuscationMode values. The remaining issue is regression coverage: the test bypasses the normal build graph, so it does not prove that ordinary R8 builds invoke the new validation target.

CI is not green yet: one macOS emulator check is failing and numerous checks remain in progress. The Azure DevOps failure details were unavailable from this environment, so I could not determine whether that failure is related to this change.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • azcliprod.blob.core.windows.net

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "azcliprod.blob.core.windows.net"

See Network Configuration for more information.

Generated by Android PR Reviewer for #12753 · copilot · gpt56 · 66.2 AIC · ⌖ 11.3 AIC · ⊞ 21K
Comment /review to run again

jonathanpeppers added a commit that referenced this pull request Sep 10, 2026
## 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.

Co-authored-by: Copilot App <[email protected]>
@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
@simonrozsival
simonrozsival merged commit a8a2a8d into main Sep 11, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the jonathanpeppers-fix-r8-private-obfuscation branch September 11, 2026 06:49
@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