From 1a832b72c5101f02564b6813359f6b96e43a8553 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Fri, 11 Oct 2024 09:58:04 +0200 Subject: [PATCH] [jnigen] Add a helper for sending jobjects through method channels (#1648) --- pkgs/jni/CHANGELOG.md | 6 ++++++ .../java/com/github/dart_lang/jni/JniUtils.java | 13 +++++++++++++ pkgs/jni/pubspec.yaml | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 pkgs/jni/java/src/main/java/com/github/dart_lang/jni/JniUtils.java diff --git a/pkgs/jni/CHANGELOG.md b/pkgs/jni/CHANGELOG.md index ab49de1ea..29c7fb34f 100644 --- a/pkgs/jni/CHANGELOG.md +++ b/pkgs/jni/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.12.1-wip + +- Add `JniUtils.fromReferenceAddress` which helps with sending `JObject`s + through method channels. You can send the address of the pointer as `long` and + reconstruct the class using the helper method. + ## 0.12.0 - **Breaking Change**: Renamed `castTo` to `as`. diff --git a/pkgs/jni/java/src/main/java/com/github/dart_lang/jni/JniUtils.java b/pkgs/jni/java/src/main/java/com/github/dart_lang/jni/JniUtils.java new file mode 100644 index 000000000..0758f5a18 --- /dev/null +++ b/pkgs/jni/java/src/main/java/com/github/dart_lang/jni/JniUtils.java @@ -0,0 +1,13 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +package com.github.dart_lang.jni; + +public class JniUtils { + static { + System.loadLibrary("dartjni"); + } + + public static native Object fromReferenceAddress(long address); +} diff --git a/pkgs/jni/pubspec.yaml b/pkgs/jni/pubspec.yaml index 4dea4acfe..e75140057 100644 --- a/pkgs/jni/pubspec.yaml +++ b/pkgs/jni/pubspec.yaml @@ -4,7 +4,7 @@ name: jni description: A library to access JNI from Dart and Flutter that acts as a support library for package:jnigen. -version: 0.12.0 +version: 0.12.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/jni topics: