Skip to content

[release/10.0.1xx] [R8] Preserve bound Java fields - #13740

Merged
jonathanpeppers merged 1 commit into
release/10.0.1xxfrom
jonathanpeppers-backport-r8-field-rules-to-net-10
Nov 24, 2026
Merged

jonathanpeppers merged 1 commit into
release/10.0.1xxfrom
jonathanpeppers-backport-r8-field-rules-to-net-10

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Backports #13239 to release/10.0.1xx.

Generate R8 keep rules for registered properties and fields in the .NET 10 linker step. Add AndroidX and bound-field coverage for Mono and CoreCLR.

Relates to #13159.

Validation

  • Built the local SDK.
  • Seven targeted NUnit cases passed.

Backport the generated keep rules from #13239 to the .NET 10 linker step.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:06

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

No active review issues remain for the bound Java field preservation backport.

No open issues 🎉

What changed in this PR

Backports bound Java field preservation to .NET 10, addressing #13159 by preventing R8 from removing or changing fields accessed through managed bindings.

Changes:

  • Generate keep rules for registered managed properties and fields.
  • Add Mono and CoreCLR regression tests, with DEX checks for field names and types.
  • Document bound-field preservation alongside the R8 obfuscation settings.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.ProjectTools/​Utilities/​DexUtils.cs Adds DEX output collection and field lookup by declaring class, name, and type.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​PackagingTest.cs Tests AndroidX and custom bound-field preservation on Mono and CoreCLR.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​DexUtilsTests.cs Adds positive and negative field-lookup assertions.
src/​Microsoft.Android.Sdk.ILLink/​GenerateProguardConfiguration.cs Emits field keep rules from registered properties and fields.
Documentation/​docs-mobile/​building-apps/​build-properties.md Explains field-name and type preservation for JNI access.

Review effort: Balanced

@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 Nov 23, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 80c3ca2 statically against release/10.0.1xx (merge-base ad1dc6c); I didn't build or run anything.

  • Upstream #13239 changed the GenerateProguardConfiguration MSBuild task, which doesn't exist on this branch. On .NET 10 the trimmer step in Microsoft.Android.Sdk.ILLink is the only generator of these rules, so this is the right place for the change.
  • The logic matches upstream. For properties, then fields, it takes the first [Register] with a string argument and emits *** name;. That rule matches the field of any type, static or instance, and doesn't need a JNI signature. Nested classes keep their $ names, and a missing or non-string argument is skipped.
  • Bound Java fields are surfaced as properties carrying [Register("NAME")], and constants as [Register] const fields, so both are handled. The rules have no allow* modifiers, so they fix the name over the looser private-members rules. The output (proguard_project_references.cfg) reaches R8 through --pg-conf for both Mono and CoreCLR.
  • The tests only use helpers that exist at this head. Their paths match the targets, and setting minSdk 23 fits this branch's default of 21.

One thing to check before merging: Xamarin.Android-PR (build 16118131) failed, and I couldn't read its logs. The base commit and recent release/10.0.1xx backports show the same check failing, but please confirm the new PackagingTest cases passed.

@jonathanpeppers

Copy link
Copy Markdown
Member Author

The CI rerun still has two failures that do not appear related to this backport:

  • Windows AndroidGradleProjectTests.BuildApp failed during Gradle configuration, before R8 ran. Gradle reported zip END header not found and a compileSdk error.
  • macOS Mono.Android.NET_Tests-NoAot did not return results after the emulator restarted. The reason for the restart is unknown, so this test run remains unverified.

The earlier macOS build-test and emulator-start failures passed on rerun. All six new R8 cases passed on Linux.

@jonathanpeppers
jonathanpeppers merged commit 8fa045d into release/10.0.1xx Nov 24, 2026
2 of 3 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-backport-r8-field-rules-to-net-10 branch November 24, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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