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 [.github] Lock closed issues and PRs after 30 days of inactivity. (#1213) 2024-04-12 11:34:11 -10:00
.vscode [java-source-utils] Add Java source code utilities (#623) 2020-07-31 15:18:49 -04:00
Documentation [generator] enum map.csv can set `@deprecated-since` for enum values (#1070) 2023-01-06 21:57:05 -05:00
Localize LEGO: Merge pull request 1117 2023-05-30 00:35:37 -07:00
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 Update README.md (#1227) 2024-06-13 13:25:00 -04:00
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 [build] Enable string operations globalization code analyzers. (#879) 2021-09-09 15:11:11 -04:00
.gitattributes [generator] Make warning and error messages localizable. (#689) 2020-08-20 19:56:45 -04:00
.gitignore Update .gitignore (#375) 2018-09-25 07:36:45 -04:00
.gitmodules Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
CODE-OF-CONDUCT.md Update README.md (#1227) 2024-06-13 13:25:00 -04:00
Configuration.Override.props.in [build] Remove support for JDK 8. (#1120) 2023-06-02 16:45:02 -04:00
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-source-utils] Add Java source code utilities (#623) 2020-07-31 15:18:49 -04:00
Java.Interop.sln Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
LICENSE Add MIT/X11 License. 2016-04-26 11:50:52 -04:00
Makefile Revert "Update dotnet/android-tools submodule (#1228)" (#1229) 2024-06-13 15:56:52 -04:00
NuGet.Config Revert "[build] Enable NuGet's Central Package Management (#1114)" (#1138) 2023-08-23 14:42:58 -04:00
README.md [build] Improve support for building on GitHub Codespaces (#1241) 2024-08-09 13:26:30 -04:00
SECURITY.md Add SECURITY.md (#846) 2021-05-24 18:07:20 -04:00
TargetFrameworkDependentValues.props [build] Remove use of 'net472' Target Framework (#1099) 2023-05-18 11:00:10 -04:00
ThirdPartyNotices.txt [Xamarin.Android.Tools.Bytecode] Honor Kotlin class visibility (#499) 2019-10-15 15:55:32 -04:00
before.Java.Interop.sln.targets [build] Fix -t:Prepare on Linux (#892) 2021-10-13 00:10:14 -04:00
global.json [build] target net6.0 instead of netcoreapp3.1 (#829) 2021-05-05 11:12:06 -04:00
product.snk [Java.Interop, Java.Interop.Dynamic, Java.Interop.Export] Sign assemblies (#32) 2016-05-10 15:50:48 +01:00

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.