Skip to content

[jnienv-gen] Remove the obsolete raw JNI backend - #13100

Merged
simonrozsival merged 2 commits into
mainfrom
simonrozsival-legacy-jni-generator-cleanup
Oct 13, 2026
Merged

simonrozsival merged 2 commits into
mainfrom
simonrozsival-legacy-jni-generator-cleanup

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

The product generates Android.Runtime.JNIEnv through Java.Interop. The unused raw JNI backend is no longer usable and still emits a call to the unavailable exception-lookup helper. Delete that backend instead of maintaining unreachable alternate implementations.

Remove the raw JNI struct/invoker, delegates, Env wrappers, exception and null-check helpers, and exclusive prototype/throw/null-check metadata. Keep the complete shared JNI function table, current forwarders, params overloads, and hand-bound skips. The authoritative metadata input has no in-tree producer; rename it from Generator.g.cs to JNIEnvEntries.cs to distinguish it from generated output.

Intentional tooling contract change: retire the legacy default mode and --use-java-interop mode selection. Output is now always Java.Interop. Update the in-tree invocation and directly related docs. There are no shipped runtime behavior, public API, ownership, GC, or nullability changes, and no changes under external/Java.Interop.

Independent follow-up to the discussion on #13092, not a prerequisite or stacked PR. Base: c36449d35ab022bd78230c474ad63d254cd8d2e8 (main). Validated commit: 4593581d1ab37051d0e26ef8675c3e28b4968acb; tested source tree: a8ed4e32ce0a824fa52dccbc0df99854d08f3f16.

Output equivalence

Before edits, build the generator in this worktree and save --use-java-interop output. After edits, build and run without the flag. cmp passes for file output, -o=-, and the actual generated src/Mono.Android/Android.Runtime/JNIEnv.g.cs. No generated output was hand-edited or included in this PR.

Generation/comparison commands (baseline commands run before edits):

ARTIFACTS=/Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files
dotnet bin/BuildDebug/jnienv-gen.dll --use-java-interop -o "$ARTIFACTS/JNIEnv.baseline.cs"
dotnet bin/BuildDebug/jnienv-gen.dll --use-java-interop -o=- > "$ARTIFACTS/JNIEnv.baseline.stdout.cs"
dotnet bin/BuildDebug/jnienv-gen.dll -o "$ARTIFACTS/JNIEnv.cleanup.cs"
dotnet bin/BuildDebug/jnienv-gen.dll -o=- > "$ARTIFACTS/JNIEnv.cleanup.stdout.cs"
cmp "$ARTIFACTS/JNIEnv.baseline.cs" "$ARTIFACTS/JNIEnv.cleanup.cs"
cmp "$ARTIFACTS/JNIEnv.baseline.stdout.cs" "$ARTIFACTS/JNIEnv.cleanup.stdout.cs"
cmp src/Mono.Android/Android.Runtime/JNIEnv.g.cs "$ARTIFACTS/JNIEnv.baseline.cs"

All commands passed.

Output Bytes SHA-256 before and after
File / actual JNIEnv.g.cs 40,237 3e3d86192ef85b16540a17b8e0b8fb708854727c030521423698e3de80e98bec
Stdout (-o=-) 40,238 9b9508c4b60fe515e21e306e36314294d5593b17142eaa2864118cdf239361d7

LF newlines and stdout's additional trailing newline are preserved. Executable checks also pass for short/long output options, --root with default output and with stdout, unchanged-file timestamps, and write failures returning 1 with the original exception diagnostic.

Local validation

All product outputs and SDK/test binaries are built in this worktree; none are borrowed from a sibling. Host commands use DOTNET_CLI_USE_MSBUILD_SERVER=0 MSBUILDDISABLENODEREUSE=1. The shared-host lease is released before publishing. Native builds use the verified session-only wrapper /Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files/ninja-j2, which executes the prepared absolute Ninja with -j2; logs confirm it was used. No global tools/build files were changed for concurrency.

Command Result
dotnet build build-tools/jnienv-gen/jnienv-gen.csproj -c Debug --disable-build-servers -m:1 -v minimal Baseline passed, 0 warnings/errors
./dotnet-local.sh build build-tools/jnienv-gen/jnienv-gen.csproj -c Debug --disable-build-servers -m:1 -nr:false -v minimal Final passed, 0 warnings/errors
MSBUILD_ARGS='-m:1 -nr:false' make prepare CONFIGURATION=Debug Passed, 0 warnings/errors
MSBUILD_ARGS='-m:1 -nr:false -p:NinjaPath=/Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files/ninja-j2' make all CONFIGURATION=Debug Final unchanged retry passed; solution 30 warnings, 0 errors; workload configuration 0 warnings/errors
./dotnet-local.sh build src/Mono.Android/Mono.Android.csproj -c Debug -f net11.0 --disable-build-servers -m:1 -nr:false -v minimal -bl:/Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files/mono-android-debug-retry.binlog Passed, 29 warnings, 0 errors; PublicAPI analyzers enabled; ApiCompat Total Issues: 0
./dotnet-local.sh build src/Mono.Android.Runtime/Mono.Android.Runtime.csproj -c Debug -f net11.0 --disable-build-servers -m:1 -nr:false Passed, 0 warnings/errors
./dotnet-local.sh build build-tools/scripts/Prepare.proj -t:BuildExtraApiLevels -c Debug --disable-build-servers -m:1 -nr:false -v minimal API 37.1/37.2 passed, 62 warnings, 0 errors
./dotnet-local.sh build build-tools/create-packs/Microsoft.Android.Sdk.proj -t:ConfigureLocalWorkload -c Debug --disable-build-servers -m:1 -nr:false -v minimal Passed, 0 warnings/errors
./dotnet-local.sh test external/Java.Interop/tests/generator-Tests/generator-Tests.csproj -c Debug --disable-build-servers -m:1 -nr:false -v minimal --logger 'trx;LogFileName=generator-tests.trx' --results-directory /Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files/test-results 478 passed, 0 failed, 0 skipped (net10.0)
./dotnet-local.sh test external/Java.Interop/tests/generator-Tests/generator-Tests.csproj --no-build -c Debug --disable-build-servers -m:1 -nr:false -v minimal --logger 'trx;LogFileName=generator-tests-final.trx' --results-directory /Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files/test-results Final binaries: 478 passed, 0 failed, 0 skipped
python3 /Users/simon/.copilot/session-state/a7bac364-f7fc-4856-8a8d-8854f5b64b8f/files/validate-generator.py All output, newline, CLI, timestamp and write-error checks passed
git diff --cached --check Passed before commit

Initial make all failed with 32 API37 binding errors: binlog replay showed the first compilation lacked the generated ANDROID_* defines. An unchanged explicit managed rebuild imported the generated Mono.Android.projitems and passed. The next make all completed the solution but workload setup lacked API37.1 refs. The existing BuildExtraApiLevels and ConfigureLocalWorkload targets supplied the missing own refs; the final unchanged make all passed. No binding metadata, SDK pins, source files, or API gates were patched to resolve these provisioning/first-build failures. Logs, binlogs, TRX files and baseline/output artifacts are preserved locally.

Device tests are not run: the complete generated JNI output is byte-identical, this changes only repository build tooling, and no device lease was requested or used.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

No issue is closed; #13092 is related context only.

The product has always selected Java.Interop when generating
Android.Runtime.JNIEnv.  The alternate backend is no longer usable and
still emits a call to the unavailable exception-lookup helper.

Remove raw JNI structs, invokers, delegates, array wrappers, exception
handling, null checks, and their exclusive metadata.  Keep the shared
JNI function table and current Java.Interop forwarders unchanged.
Rename the authoritative metadata input to JNIEnvEntries.cs to
distinguish it from generated output.

Retire the legacy default mode and --use-java-interop CLI selection.
Generation is now always Java.Interop; update the in-tree invocation
and documentation.  Generated file and stdout bytes match the previous
Java.Interop mode exactly, including newline behavior.

Validate the own Debug SDK, explicit net11.0 managed/API builds, and
478 existing generator/codegen tests.  No shipped runtime behavior or
public API changes.

Context: #13092 (comment)

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

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 cleanup consistently removes the inactive backend while preserving the active generated output and updating all in-tree references.

0 open findings

What changed in this PR

Removes the obsolete raw JNI generation backend so jnienv-gen exclusively emits Java.Interop forwarders.

Changes:

  • Removes legacy backend code and metadata.
  • Renames the metadata input to JNIEnvEntries.cs.
  • Updates invocation and documentation for the simplified CLI.
File Description
Documentation/​project-docs/​ExploringSources.md Documents Java.Interop-only generation.
build-tools/​jnienv-gen/​JNIEnvEntries.cs Removes raw-backend metadata.
build-tools/​jnienv-gen/​Generator.cs Deletes raw generation and mode selection.
build-tools/​create-android-api/​create-android-api.csproj Removes the retired CLI flag.

🧠 Review effort: Balanced

Remove the description of the retired backend and mode-selection option.  Keep the documentation focused on current Java.Interop generation, output options, and the metadata input.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival enabled auto-merge (squash) October 13, 2026 07:29
@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto review

@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 13, 2026
@simonrozsival
simonrozsival merged commit 9df295b into main Oct 13, 2026
42 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-legacy-jni-generator-cleanup branch October 13, 2026 13:15
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 13, 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