Skip to content

[r8-obfuscation] Enable R8 JNI name obfuscation for NativeAOT - #12634

Draft
simonrozsival wants to merge 4 commits into
simonrozsival-coreclr-r8-jni-integrationfrom
simonrozsival-nativeaot-r8-jni-integration
Draft

[r8-obfuscation] Enable R8 JNI name obfuscation for NativeAOT#12634
simonrozsival wants to merge 4 commits into
simonrozsival-coreclr-r8-jni-integrationfrom
simonrozsival-nativeaot-r8-jni-integration

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Sep 1, 2026

Copy link
Copy Markdown
Member

Related to #12535

Depends on #12632

Layer 6 of 6 and the top of the replacement stack for draft PR #12575. Extends the shared two-pass R8 JNI name-obfuscation pipeline to NativeAOT, including incremental pre-ILC assembly rewriting, conservative JNI class/member reachability, seed-compatible final keep rules, and prebuilt runtime JNI startup keeps.

Testing:

  • Modified target XML parses successfully.
  • Xamarin.Android.Build.Tasks.csproj builds successfully.
  • Complete Xamarin.Android.Build.Tests.csproj builds successfully.
  • NativeAOT and direct-manifest generator tests: 28/28 passed.
  • Cumulative focused R8/JNI unit suites: 165/165 passed.
  • TypeMapAssemblyGeneratorTests: 121/121 passed, including owner-specific JNI method-name FieldRVA coverage.
  • Independent Opus 5 correctness review found no remaining high-confidence issues and separately confirmed skipped incremental targets still evaluate item redirection.
  • All three NativeAOT R8/JNI integration variants were attempted, but the local SDK stops before project code with NETSDK1147: To build this project, the following workloads must be installed: android; no unrelated workload was installed.

@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch 7 times, most recently from a7bff4c to a8fff0b Compare September 2, 2026 06:31
@simonrozsival

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@simonrozsival

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@simonrozsival

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@simonrozsival

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch 2 times, most recently from 4c591ed to 80dbc97 Compare September 2, 2026 10:21
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from 80dbc97 to 2099dc9 Compare September 2, 2026 11:23
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from 2099dc9 to 07eaa87 Compare September 2, 2026 12:02
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from 07eaa87 to 7c2485f Compare September 2, 2026 13:21
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from cbb6df2 to f547135 Compare September 2, 2026 15:05
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from f547135 to ec9422a Compare September 2, 2026 15:29
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from ec9422a to c544a34 Compare September 2, 2026 17:55
simonrozsival and others added 4 commits September 2, 2026 23:39
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
NativeAOT correctly removes an unreferenced managed peer from the final R8 reachability set. Keep the test peer live through MainActivity and assert its exact reachability provenance before checking the final mapping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The generated ACW keep file is intentionally excluded from final R8, so NativeAOT correctly removed the unreferenced library peer. Reference it from the app and assert its reachability provenance before validating the public mapping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsival force-pushed the simonrozsival-nativeaot-r8-jni-integration branch from c544a34 to 1912f90 Compare September 2, 2026 21:42
@MichalStrehovsky

Copy link
Copy Markdown
Member

Why is this rewriting necessary? Can't we tell R8 not to rename things we need? There must be an escape hatch for reflection. What we're doing is reflection.

Bugs in rewritten assemblies pretty much always land on runtime team's plate to troubleshoot. dotnet/maui#37782 (comment) was the most recent one and that one was extra annoying because people who knew about the rewriting (they edited the rewriter files in the past) were on the thread and did not say there was a rewrite. I'm not a big fan of these approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants