Viewing version 0.7.3. Open the latest package page.
jni
0.7.3A library to access JNI from Dart and Flutter that acts as a support library for package:jnigen.
Readme
jni
This is a support library to access JNI from Dart / Flutter code. This provides the common infrastructure to bindings generated by jnigen, as well as some utility methods.
This library contains:
- Functions to access the JNIEnv and JavaVM variables from JNI, and wrapper functions to those provided by JNI. JNIEnv is exposed via
GlobalJniEnvtype which provides a thin abstraction over JNIEnv, so that it can be used from multiple threads. - Functions to spawn a JVM on desktop platforms (
Jni.spawn). - Some Android-specific helpers (get application context and current activity references).
JObjectclass, which provides base class for classes generated by jnigen.- Commonly used Java classes like
JList,JMap,JInteger, ...
Apart from being the base library for code generated by jnigen this can also be used for one-off uses of the JNI and debugging. To generate type-safe bindings from Java libraries, use jnigen.
Documentation
The test/ directory contains files with comments explaining the basics of this module, and the example/ directory contains a flutter example which also touches some Android-specifics.
Using this library assumes some familiarity with JNI - it's threading model and object references, among other things.
Changelog
0.7.3
- Fixed a bug where
get(Static)MethodIDandget(Static)FieldIDcould access null and throw.
0.7.2
- Fixed a bug where reading non-null terminated strings would overflow.
0.7.1
- Removed macOS Flutter plugin until package:jni supports it (#41).
0.7.0
- Breaking Change (#387):
Added
JBufferandJByteBufferclasses as default classes forjava.nio.Bufferandjava.nio.ByteBufferrespectively. - Breaking Change: Made the type classes
final. - Fixed a bug where
addAll,removeAllandretainAllinJSetwould run their respective operation twice. - Fixed a bug where
JList.insertAllwould not throw the potentially thrown Java exception.
0.6.1
- Depend on the stable version of Dart 3.1.
0.6.0
- Breaking Change (#131):
Renamed
delete*torelease*. - Added
PortProxyand related methods used for interface implementation. - Added the missing binding for
java.lang.Character.
0.5.0
- Breaking Change (#137):
Java primitive types are now all lowercase like
jint,jshort, ... - The bindings for
java.util.Set,java.util.Map,java.util.Listand the numeric types likejava.lang.Integer,java.lang.Boolean, ... are now included inpackage:jni.
0.4.0
- Type classes now have
superCountandsuperTypegetters used for type inference.
0.3.0
- Added
PortContinuationused forsuspend funin Kotlin. dartjninow depends ondart_api_dl.h.
0.2.1
- Added
.clang-formatto pub.
0.2.0
- Added array support
- Added generic support
JniXturned intoJXfor a more terse code.
0.1.1
- Windows support for running tests and examples on development machines.
0.1.0
- Initial version: Android and Linux support, JObject API
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'jni:0.7.3'pubspec.yaml
# Copyright (c) 2022, 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.
name: jni
description: A library to access JNI from Dart and Flutter that acts as a support library for package:jnigen.
version: 0.7.3
repository: https://github.com/dart-lang/jnigen/tree/main/jni
topics:
- interop
- ffi
- java
- kotlin
- jni
environment:
sdk: '>=3.1.0 <4.0.0'
flutter: '>=2.11.0'
dependencies:
collection: ^1.0.0
plugin_platform_interface: ^2.0.2
ffi: ^2.0.1
path: ^1.8.0
package_config: ^2.1.0
args: ^2.3.1
dev_dependencies:
## Pin ffigen version because we are depending on internal APIs.
ffigen: 8.0.2
flutter_lints: ^2.0.0
test: ^1.21.1
logging: ^1.1.1
# The following section is specific to Flutter packages.
flutter:
plugin:
platforms:
linux:
ffiPlugin: true
windows:
ffiPlugin: true
android:
ffiPlugin: true
package: com.github.dart_lang.jni
pluginClass: JniPlugin
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | b237560e…ae6db4 |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | 47000d71…3f9cd8 |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | bea8d106…48d578 |
| 0.2.1 | Cached · Upstream SHA-256 matched | Download | 075d1622…ff4e27 |
| 0.3.0 | Cached · Upstream SHA-256 matched | Download | d1361580…7feb3d |
| 0.4.0 | Cached · Upstream SHA-256 matched | Download | 1b5c3708…9946d7 |
| 0.5.0 | Cached · Upstream SHA-256 matched | Download | a19d9f63…b0143c |
| 0.6.0 | Cached · Upstream SHA-256 matched | Download | ef31e778…1ad72b |
| 0.6.1 | Cached · Upstream SHA-256 matched | Download | b4bed1f4…d2d02d |
| 0.7.0 | Cached · Upstream SHA-256 matched | Download | 6b322776…1baa72 |
| 0.7.1 | Cached · Upstream SHA-256 matched | Download | e63e1cca…76ffa2 |
| 0.7.2 | Cached · Upstream SHA-256 matched | Download | 0d88790b…885b43 |
| 0.7.3 | Cached · Upstream SHA-256 matched | Download | 499558e9…4e6611 |
| 0.8.0 | Cached · Upstream SHA-256 matched | Download | 63984817…c39222 |
| 0.9.0 | Cached · Upstream SHA-256 matched | Download | 4f20a803…3176af |
| 0.9.1 | Cached · Upstream SHA-256 matched | Download | 2a99a0cc…49f21c |
| 0.9.2 | Cached · Upstream SHA-256 matched | Download | 6f8e0433…8b665d |
| 0.9.3 | Cached · Upstream SHA-256 matched | Download | 85cf3fbc…8988a8 |
| 0.10.0 | Cached · Upstream SHA-256 matched | Download | 08a0074b…ca2270 |
| 0.10.1 | Cached · Upstream SHA-256 matched | Download | f377c585…acba4b |
| 0.11.0 | Cached · Upstream SHA-256 matched | Download | caefbbf9…0d126f |
| 0.12.0 | Cached · Upstream SHA-256 matched | Download | 100fd0a7…5e595b |
| 0.12.2 | Cached · Upstream SHA-256 matched | Download | 459727a9…62ac4e |
| 0.13.0 | Cached · Upstream SHA-256 matched | Download | 3296e432…ca5faa |
| 0.14.0 | Cached · Upstream SHA-256 matched | Download | 302f50fd…db3b1f |
| 0.14.1 | Cached · Upstream SHA-256 matched | Download | cfd663ec…6adba6 |
| 0.14.2 | Cached · Upstream SHA-256 matched | Download | d2c36108…2b3da1 |
| 0.15.0 | Cached · Upstream SHA-256 matched | Download | 5b8d72fa…cdf76b |
| 0.15.1 | Cached · Upstream SHA-256 matched | Download | b4d27985…61f3df |
| 0.15.2 | Cached · Upstream SHA-256 matched | Download | 8706a77e…3ea12d |
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | c2230682…b2e68f |
| 1.0.1 | Cached · Upstream SHA-256 matched | Download | ca1efa31…93a4f4 |
| 1.0.2 | Cached · Upstream SHA-256 matched | Download | 5bc9a9da…d978d1 |
| 1.0.3 | Cached · Upstream SHA-256 matched | Download | f038e58b…04cbd3 |
| 1.1.0 | Cached · Upstream SHA-256 matched | Download | 6b9ca060…2f402d |
| 1.1.1 | Cached · Upstream SHA-256 matched | Download | d8df6dab…79813f |
Dependencies
args "^2.3.1"
collection "^1.0.0"
ffi "^2.0.1"
package_config "^2.1.0"
path "^1.8.0"
plugin_platform_interface "^2.0.2"