Skip to content

Remove $(AndroidGenerateJniMarshalMethods) support#1405

Open
jonathanpeppers wants to merge 5 commits intomainfrom
jonathanpeppers/dev-peppers-remove-jni-marshal-methods
Open

Remove $(AndroidGenerateJniMarshalMethods) support#1405
jonathanpeppers wants to merge 5 commits intomainfrom
jonathanpeppers/dev-peppers-remove-jni-marshal-methods

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Context: dotnet/android@4296716

Summary

Remove the $(AndroidGenerateJniMarshalMethods) infrastructure from java-interop, which was already removed from dotnet/android.

44 files changed, 54 insertions, 5,513 deletions

What's removed

  • tools/jnimarshalmethod-gen/ — the marshal method generator tool
  • src/Java.Interop.Export/MarshalMemberBuilder implementation + [JavaCallable] attributes
  • tests/Java.Interop.Export-Tests/ — tests for the above
  • src/Java.Interop.Tools.Expressions/ — Expression-to-IL compiler used only by jnimarshalmethod-gen
  • tests/Java.Interop.Tools.Expressions-Tests/ — tests for the above

What's kept (marked [Obsolete])

All public APIs in Java.Interop.dll are retained but obsoleted:

  • CreationOptions.UseMarshalMemberBuilder
  • CreationOptions.MarshalMemberBuilder
  • JniRuntime.MarshalMemberBuilder
  • JniRuntime.JniMarshalMemberBuilder abstract class + all members

Non-abstract methods now throw NotSupportedException.

Runtime simplification

  • JreTypeManager.RegisterNativeMembers — removed the MarshalMemberBuilder fallback path; now throws if TryRegisterNativeMembers fails
  • ManagedValueManager.ActivatePeer — always uses reflection activation
  • MonoRuntimeValueManager.ActivatePeer — uses reflection activation instead of MarshalMemberBuilder.CreateConstructActivationPeerFunc

dotnet/android impact

dotnet/android sets UseMarshalMemberBuilder = false in two places. After this change, those lines should be removed (they'll generate [Obsolete] warnings):

  • src/Mono.Android/Android.Runtime/AndroidRuntime.cs
  • src/Microsoft.Android.Runtime.NativeAOT/Android.Runtime.NativeAOT/JavaInteropRuntime.cs

Build & test

  • Solution builds successfully
  • Java.Interop-Tests: 665 passed, 0 failed
  • JCW-Tests: 47 passed, 0 failed

Delete the jnimarshalmethod-gen tool, Java.Interop.Export library,
Java.Interop.Export-Tests, and Java.Interop.Tools.Expressions projects.

All public APIs in Java.Interop.dll (JniMarshalMemberBuilder,
CreationOptions.UseMarshalMemberBuilder, etc.) are retained but marked
[Obsolete] with no-op implementations.

Runtime code in JreTypeManager, ManagedValueManager, and
MonoRuntimeValueManager is simplified to remove MarshalMemberBuilder
fallback paths.

NativeAOT samples, Makefile, and CI pipeline are updated accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers added a commit to dotnet/android that referenced this pull request Apr 16, 2026
Bump \�xternal/Java.Interop\ to dotnet/java-interop#1405, which removes
\Java.Interop.Export\, \jnimarshalmethod-gen\, and
\Java.Interop.Tools.Expressions\.

Changes in dotnet/android:
- Remove \UseMarshalMemberBuilder = false\ from AndroidRuntime and
  NativeAOT JavaInteropRuntime (property is now obsolete/no-op).
- Remove deleted \Java.Interop.Export\ and
  \Xamarin.Android.Tools.JniMarshalMethodGenerator\ projects from
  \Xamarin.Android.sln\.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eManager trim warnings

- JreTypeManager: Simplify RegisterNativeMembers to return early when
  methods is empty (types like JavaProxyThrowable register with no
  methods), and throw for non-empty methods without static registration.
- MonoRuntimeValueManager: Add trim suppression attributes for
  GetUninitializedObject call to fix NativeAOT publish errors.
- Java.Base-Tests: Add explicit marshal methods and static registration
  to MyRunnable and MyIntConsumer test types, since dynamic marshal
  method generation via MarshalMemberBuilder is no longer available.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/dev-peppers-remove-jni-marshal-methods branch from 01256d8 to 5cb82cd Compare April 17, 2026 13:51
jonathanpeppers and others added 3 commits April 17, 2026 11:58
…hal methods

ManagedType.cs used [JavaCallable] attributes which relied on the
now-removed jnimarshalmethod-gen tool. Replace with explicit n_*
marshal methods and [JniAddNativeMethodRegistration] static registration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ration

jcw-gen uses Cecil to find [JavaCallable] and [JavaCallableConstructor]
by attribute name to emit Java-side methods. These attributes must still
exist at compile time for the JCW to include getString() and the
constructor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NativeAOT requires delegate types used for JNI callbacks to have
[UnmanagedFunctionPointer] for proper marshalling data generation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers added a commit to dotnet/android that referenced this pull request Apr 22, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers added a commit to dotnet/android that referenced this pull request Apr 22, 2026
…et/java-interop#1405

- Remove UseMarshalMemberBuilder = false from AndroidRuntime and
  NativeAOT JavaInteropRuntime (property is now obsolete/no-op).
- Remove deleted Java.Interop.Export and
  Xamarin.Android.Tools.JniMarshalMethodGenerator projects from
  Xamarin.Android.sln.
- Bump external/Java.Interop submodule to PR 1405 head.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
Copy link
Copy Markdown
Member Author

The dotnet/android test PR looks OK:

There are some flaky tests, but everything builds.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 23, 2026 18:27
Copilot AI review requested due to automatic review settings April 23, 2026 18:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the legacy $(AndroidGenerateJniMarshalMethods)-driven marshal-method generation infrastructure from java-interop, aligning with the earlier removal in dotnet/android, while keeping the public surface area in Java.Interop.dll as [Obsolete] stubs that now throw NotSupportedException.

Changes:

  • Removes the jnimarshalmethod-gen tool and the Java.Interop.Export / Java.Interop.Tools.Expressions projects (plus associated tests and pipeline hooks).
  • Simplifies runtime activation/registration paths to rely on reflection and explicit [JniAddNativeMethodRegistration] patterns instead of MarshalMemberBuilder.
  • Updates samples and tests to no longer depend on Java.Interop.Export and generated marshal methods.

Reviewed changes

Copilot reviewed 44 out of 46 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/jnimarshalmethod-gen/Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj Deletes the marshal-method generator tool project.
tools/jnimarshalmethod-gen/TypeMover.cs Removes type-moving logic used by the generator.
tools/jnimarshalmethod-gen/Message.cs Removes generator-specific localized messages.
tools/jnimarshalmethod-gen/App.cs Removes generator app entrypoint and processing pipeline.
tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop/JavaCallableConstructorAttribute.cs Adds local test-only attribute type to replace removed Export assembly dependency.
tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop/JavaCallableAttribute.cs Adds local test-only attribute type to replace removed Export assembly dependency.
tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers-Tests.csproj Stops compiling attribute sources from Java.Interop.Export.
tests/Java.Interop.Tools.Expressions-Tests/Usings.cs Removes global using as the Expressions test project is removed.
tests/Java.Interop.Tools.Expressions-Tests/Java.Interop.Tools.ExpressionsTests/ExpressionAssemblyBuilderTests.cs Deletes tests for the removed Expressions toolchain.
tests/Java.Interop.Tools.Expressions-Tests/Java.Interop.Tools.Expressions-Tests.csproj Deletes the Expressions test project.
tests/Java.Interop.Export-Tests/java/net/dot/jni/test/UseJavaCallableExample.java Deletes Export test Java sources.
tests/Java.Interop.Export-Tests/java/net/dot/jni/test/ExportType.java Deletes Export test Java sources.
tests/Java.Interop.Export-Tests/Java.Interop/MarshalMemberBuilderTest.cs Deletes Export/MarshalMemberBuilder test coverage.
tests/Java.Interop.Export-Tests/Java.Interop/JavaVMFixture.cs Deletes fixture used only by Export tests.
tests/Java.Interop.Export-Tests/Java.Interop/JavaCallableExampleTests.cs Deletes JavaCallable example tests tied to Export infra.
tests/Java.Interop.Export-Tests/Java.Interop/JavaCallableExample.cs Deletes JavaCallable example type tied to Export infra.
tests/Java.Interop.Export-Tests/Java.Interop/ExportTest.cs Deletes ExportTest type which relied on MarshalMemberBuilder.
tests/Java.Interop.Export-Tests/Java.Interop.Export-Tests.targets Deletes MSBuild targets used to build Export test jar and wrappers.
tests/Java.Interop.Export-Tests/Java.Interop.Export-Tests.csproj Deletes Export tests project.
tests/Java.Interop-Tests/Java.Interop/TestType.cs Stops using MarshalMemberBuilder.CreateMarshalToManagedDelegate(); returns existing delegate directly.
tests/Java.Interop-Tests/Java.Interop/JniRuntimeTest.cs Removes ProxyMarshalMemberBuilder test shim as marshal builder is no longer supported.
tests/Java.Base-Tests/Java.Base/JavaToManagedTests.cs Adds explicit native registration methods instead of relying on marshal builder infrastructure.
src/Java.Runtime.Environment/Java.Runtime.Environment.csproj Removes project reference to Java.Interop.Export.
src/Java.Runtime.Environment/Java.Interop/MonoRuntimeValueManager.cs Switches activation to reflection-based creation instead of CreateConstructActivationPeerFunc().
src/Java.Runtime.Environment/Java.Interop/ManagedValueManager.cs Removes marshal-member-builder activation branch; always uses reflection path.
src/Java.Runtime.Environment/Java.Interop/JreTypeManager.cs Removes marshal-member-builder fallback; now throws if registration isn’t handled explicitly.
src/Java.Interop/Java.Interop/JniRuntime.cs Removes initialization/disposal of marshal member builder.
src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs Obsoletes marshal member builder APIs; replaces behavior with NotSupportedException.
src/Java.Interop/GlobalSuppressions.cs Drops suppression for removed IsDirectMethod analyzer case.
src/Java.Interop.Tools.Expressions/Java.Interop.Tools.Expressions/ExpressionMethodRegistration.cs Deletes Expressions helper type.
src/Java.Interop.Tools.Expressions/Java.Interop.Tools.Expressions/ExpressionAssemblyBuilder.cs Deletes Expressions-to-IL compiler utility.
src/Java.Interop.Tools.Expressions/Java.Interop.Tools.Expressions/CecilCompilerExpressionVisitor.cs Deletes Expressions-to-IL compiler visitor.
src/Java.Interop.Tools.Expressions/Java.Interop.Tools.Expressions.csproj Deletes Expressions project.
src/Java.Interop.Export/Java.Interop/MarshalMemberBuilder.cs Deletes Export-side MarshalMemberBuilder implementation.
src/Java.Interop.Export/Java.Interop.Export.csproj Deletes Export assembly project.
samples/Hello-NativeAOTFromJNI/ManagedType.cs Adds explicit native registration/marshal method stub instead of post-build generator.
samples/Hello-NativeAOTFromJNI/JavaInteropRuntime.cs Removes UseMarshalMemberBuilder=false usage.
samples/Hello-NativeAOTFromJNI/JavaCallableAttributes.cs Adds local attribute definitions for the sample (no Export dependency).
samples/Hello-NativeAOTFromJNI/Hello-NativeAOTFromJNI.targets Removes post-build _AddMarshalMethods target.
samples/Hello-NativeAOTFromJNI/Hello-NativeAOTFromJNI.csproj Removes references to Export + jnimarshalmethod-gen tool projects.
samples/Hello-NativeAOTFromAndroid/JavaInteropRuntime.cs Removes UseMarshalMemberBuilder=false usage.
samples/Hello-NativeAOTFromAndroid/Hello-NativeAOTFromAndroid.targets Removes _AddMarshalMethods target and dependency ordering.
samples/Hello-NativeAOTFromAndroid/Hello-NativeAOTFromAndroid.csproj Removes references to Export + jnimarshalmethod-gen tool projects.
build-tools/automation/templates/core-tests.yaml Removes CI steps that ran Export tests and marshal-method generator.
Makefile Removes Export test target and jnimarshalmethod-gen test recipe.
Java.Interop.sln Removes Export/Expressions/tool projects from the solution.

Comment thread samples/Hello-NativeAOTFromJNI/ManagedType.cs
Comment thread Java.Interop.sln
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, thanks! label Apr 24, 2026
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, thanks!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants