Repository navigation
[release/10.0.1xx] [R8] Preserve bound Java fields - #13740
jonathanpeppers merged 1 commit into
Conversation
Backport the generated keep rules from #13239 to the .NET 10 linker step. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟢 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
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed 80c3ca2 statically against release/10.0.1xx (merge-base ad1dc6c); I didn't build or run anything.
- Upstream #13239 changed the
GenerateProguardConfigurationMSBuild task, which doesn't exist on this branch. On .NET 10 the trimmer step inMicrosoft.Android.Sdk.ILLinkis 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 noallow*modifiers, so they fix the name over the looser private-members rules. The output (proguard_project_references.cfg) reaches R8 through--pg-conffor 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.
|
The CI rerun still has two failures that do not appear related to this backport:
The earlier macOS build-test and emulator-start failures passed on rerun. All six new R8 cases passed on Linux. |
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