Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Перейти к файлу
Jonathan Pryor 2bdf2bc693
[Java.Base] Bind package java.util.concurrent (#1274)
Context: 0aec86ac40

Commit 0aec86ac mentioned:

>  * Use of `JNIEnv.GetJniName()`
>
>        string __id = "(L" + global::Android.Runtime.JNIEnv.GetJniName (GetType ().DeclaringType) + ";)V";
>
>    Impacts: NestedTypes.cs

This issue also impacts
[`java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject`][0].

Update `Java.Base` to bind the `java.util.concurrent` package, which
will cause `AbstractQueuedSynchronizer` to be bound, which in turn
forces us to update `generator` to not emit `JNIEnv.GetJniName()`.
Instead of using `JNIEnv.GetJniName(GetType().DeclaringType)`, use:

	JniEnvironment.Runtime.TypeManager.GetTypeSignature (GetType ().DeclaringType).SimpleReference

Update NestedTypes.cs to enable `TryJavaInterop1 => true`.

Update `Java.Base.csproj` to ignore C# warning [CS0109][1], as
[`CompletableFuture.handle()`][2] is emitted with a `new` which is
not required:

	Java.Util.Concurrent.CompletableFuture.cs(629,76): warning CS0109: The member
	'CompletableFuture.Handle(IBiFunction?)' does not hide an accessible member.
	The new keyword is not required.

Add a test to `tests/Java.Base-Tests` which tests nested type support.

Update `JavaNativeTypeManager.cs` so that `IsNonStaticInnerClass()`
supports JavaInterop1-style attributes, not just XAJavaInterop1.

Aside: I updated my local JDK to JDK-17 (from JDK-11), which caused
many changes to `src/Java.Base-ref.cs`, particularly parameter names.

TODO? Update `Java.Interop.Tools.JavaCallableWrappers` so that
non-static inner classes don't have a prefix of their declaring type.
This would result in `example/MyQueuedSynchronizer$MyConditionObject`
instead of
`example/MyQueuedSynchronizer$MyQueuedSynchronizer_MyConditionObject`.

[0]: https://developer.android.com/reference/java/util/concurrent/locks/AbstractQueuedSynchronizer.ConditionObject
[1]: https://learn.microsoft.com/dotnet/csharp/misc/cs0109
[2]: https://developer.android.com/reference/java/util/concurrent/CompletableFuture#handle(java.util.function.BiFunction%3C?%20super%20T,java.lang.Throwable,?%20extends%20U%3E)
2024-10-28 15:20:03 -04:00
.devcontainer [build] Improve support for building on GitHub Codespaces (#1241) 2024-08-09 13:26:30 -04:00
.github
.vscode
Documentation
Localize
build-tools [generator] Fix StackOverflow when copying DIM via private interfaces (#1261 2024-10-21 17:43:57 -04:00
external Bump to dotnet/android-tools/main@60fae19 (#1270) 2024-10-23 17:22:19 -04:00
samples
src [Java.Base] Bind package java.util.concurrent (#1274) 2024-10-28 15:20:03 -04:00
tests [Java.Base] Bind package java.util.concurrent (#1274) 2024-10-28 15:20:03 -04:00
tools [Java.Base] Bind package java.util.concurrent (#1274) 2024-10-28 15:20:03 -04:00
.editorconfig
.gitattributes
.gitignore
.gitmodules Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
CODE-OF-CONDUCT.md
Configuration.Override.props.in
Directory.Build.props Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
Directory.Build.targets [Java.Base] Update to Microsoft.DotNet.GenAPI 8.0.0-beta.24516.1 (#1272) 2024-10-22 15:23:54 -04:00
GitInfo.txt [build] `main` *conceptually* targets .NET 9 (#1259) 2024-09-25 13:31:39 -04:00
Java.Interop.code-workspace
Java.Interop.sln Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
LICENSE
Makefile Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
NuGet.Config
README.md [build] Improve support for building on GitHub Codespaces (#1241) 2024-08-09 13:26:30 -04:00
SECURITY.md
TargetFrameworkDependentValues.props
ThirdPartyNotices.txt
before.Java.Interop.sln.targets
global.json
product.snk

README.md

Java.Interop

Java.Interop is a binding of the Java Native Interface for use from managed languages such as C#, and an associated set of code generators to allow Java code to invoke managed code.

This allows one to bridge code running on .NET's CLR and code running on a Java VM.

Note this does not mean that one can run Java code on .NET, or vice-versa.

Java.Interop currently does not ship independently. It is shipped as part of Microsoft's .NET for Android product, available via Visual Studio or .NET 6+. However, it is designed to be fully independent of Android and should be usable by other Java implementations. For other uses, please compile and distribute from source.

Some additional context for this project is documented in the Motivation and Architecture pages.

Building

  • The main branch is configured to build with .NET 7, available here.
  • The release/6.0.3xx branch is configured to build with .NET 6.

Java.Interop.sln must first run some "preparatory" tasks before it can be built:

dotnet build -t:Prepare

Once Java.Interop.sln has been prepared, it can be built in Visual Studio 2022 or with dotnet:

dotnet build

Additional build options are documented here.

Feedback and Contributing

This project welcomes issues and PRs.

License

Copyright (c) .NET Foundation Contributors. All rights reserved. Licensed under the MIT License.