Skip to content

Preserve explicit Java exports during full trimming - #13224

Merged
simonrozsival merged 1 commit into
mainfrom
simonrozsival-preserve-java-exports
Oct 22, 2026
Merged

simonrozsival merged 1 commit into
mainfrom
simonrozsival-preserve-java-exports

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • Treat explicit [Export], [ExportField], and exported constructor declarations as Java entry points for trimmable typemap rooting on CoreCLR and NativeAOT.
  • Preserve the exported peer, generated callbacks, and Java-facing constructors without rooting unrelated peers or managed members; [Register] alone and inherited exports do not root a peer.
  • Add alias/model coverage, full-trim and NativeAOT typemap-key regressions, Java-to-managed device coverage, and release-note documentation.

Validation

  • make prepare CONFIGURATION=Release — passed.
  • make all CONFIGURATION=Release — passed after generating missing API 37.1 and 37.2 reference outputs with ./dotnet-local.sh build src/Mono.Android/Mono.Android.csproj -c Release -p:AndroidApiLevel=37.1 -p:AndroidPlatformId=37.1 -p:AndroidFrameworkVersion=v17.1 -v minimal and the corresponding 37.2/v17.2 command.
  • Focused standalone typemap/linker tests — 104 passed, 0 failed.
  • Focused CoreCLR/NativeAOT host build tests — 5 passed, 0 failed.
  • CoreCLR/NativeAOT Java-only export device tests on an arm64 API 35 emulator — 2 passed, 0 failed.
  • Confirmed the new full-trim regression fails for both runtimes when run against the original conditional-rooting behavior.
  • git diff --check — passed.

Treat explicit Export and ExportField declarations as unconditional trimmable typemap entries on CoreCLR and NativeAOT. Preserve the generated proxy's Java-facing methods and constructors without rooting unrelated peers or managed members.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 08:20

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 narrowly scoped rooting change has layered regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

Preserves explicit Java exports during full trimming on CoreCLR and NativeAOT without retaining unrelated peers or managed members.

Changes:

  • Makes explicitly exporting peers unconditional typemap entries.
  • Adds model, build, and device regression coverage.
  • Documents export preservation behavior.
File Description
tests/​MSBuildDeviceIntegration/​Tests/​ExportAttributeBuildTest.cs Tests Java-to-managed exports after full trimming.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Verifies exported peers survive while unrelated members are trimmed.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Generator/​ModelBuilder.cs Roots peers declaring explicit exports.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​GenerateTrimmableTypeMapTests.cs Tests export rooting, aliases, and exclusions.
Documentation/​release-notes/​mono-android-export-removal.md Explains preservation guarantees and limits.

Review effort: Balanced

@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

❌ Android PR Reviewer failed. Please review the logs for details.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Generated by Android PR Reviewer for #13224

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

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.

Explicit Export and ExportField declarations, including exported constructors, now become unconditional typemap entries through their generated proxies. The declared-versus-inherited and alias handling preserves the Java-facing callback/constructor surface without blanket-rooting unrelated managed members; Register-only peers remain conditional. I checked the CoreCLR and NativeAOT consumer contracts and the Java-only/negative trimming controls. Source review only; no runtime execution is certified, and the separate automated-reviewer model-endpoint failure is not treated as validation.

@simonrozsival
simonrozsival merged commit 2b6f3de into main Oct 22, 2026
42 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-preserve-java-exports branch October 22, 2026 05:52
@simonrozsival

Copy link
Copy Markdown
Member Author

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@simonrozsival backporting to release/11.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 2b6f3defea928bc13a1aee3c74acf224d3e5e46f

CONFLICT (modify/delete): Documentation/release-notes/mono-android-export-removal.md deleted in HEAD and modified in 2b6f3defe (Preserve explicit Java exports during full trimming (#13224)).  Version 2b6f3defe (Preserve explicit Java exports during full trimming (#13224)) of Documentation/release-notes/mono-android-export-removal.md left in tree.
Auto-merging src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs
CONFLICT (content): Merge conflict in src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs
Auto-merging src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ModelBuilder.cs
Auto-merging src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
Auto-merging tests/MSBuildDeviceIntegration/Tests/MonoAndroidExportTest.cs
error: could not apply 2b6f3defe... Preserve explicit Java exports during full trimming (#13224)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Preserve explicit Java exports during full trimming
Using index info to reconstruct a base tree...
A	Documentation/release-notes/mono-android-export-removal.md
M	src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs
M	src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ModelBuilder.cs
M	src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
A	tests/MSBuildDeviceIntegration/Tests/ExportAttributeBuildTest.cs
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): Documentation/release-notes/mono-android-export-removal.md deleted in HEAD and modified in Preserve explicit Java exports during full trimming.  Version Preserve explicit Java exports during full trimming of Documentation/release-notes/mono-android-export-removal.md left in tree.
Auto-merging src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs
CONFLICT (content): Merge conflict in src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/GenerateTrimmableTypeMapTests.cs
Auto-merging src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ModelBuilder.cs
Auto-merging src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs
Auto-merging tests/MSBuildDeviceIntegration/Tests/MonoAndroidExportTest.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Preserve explicit Java exports during full trimming
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

simonrozsival added a commit that referenced this pull request Oct 27, 2026
Manual backport of #13224 (2b6f3de).

Explicit `[Export]`, `[ExportField]`, and exported constructors are Java-to-managed entry points even when there are no managed callers. Make their trimmable typemap entries unconditional on CoreCLR and NativeAOT so full trimming preserves the Java-facing callbacks and constructors, without preserving unrelated managed members or peers. `[Register]` alone and inherited exports still do not root a peer.

### Backport adaptations

- Keep .NET 11's `Mono.Android.Export` references and explicitly select `AndroidTypeMapImplementation=trimmable` in the host/device regressions.
- Put the alias/model regressions in the existing standalone `ModelBuilderTests`, which already has access to the generator's internal model APIs. Use the existing metadata round-trip helper rather than adding friend access or a Cecil dependency to the build-task tests.
- Inspect surviving CoreCLR typemap attributes, NativeAOT's DGML-derived R8 keep rules, and retained/pruned DEX classes. This branch does not emit main's `typemap.keys.txt` or have `_AndroidEnableTypemapR8Trimming`.
- Add a .NET 11 release note instead of importing main's `Mono.Android.Export` removal document.
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-review 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