Viewing version 0.6.1. Open the latest package page.

jni

0.6.1

A library to access JNI from Dart and Flutter that acts as a support library for package:jnigen.

Download archive

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 GlobalJniEnv type 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).
  • JObject class, 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.6.1

  • Depend on the stable version of Dart 3.1.

0.6.0

  • Breaking Change (#131): Renamed delete* to release*.
  • Added PortProxy and 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.List and the numeric types like java.lang.Integer, java.lang.Boolean, ... are now included in package:jni.

0.4.0

  • Type classes now have superCount and superType getters used for type inference.

0.3.0

  • Added PortContinuation used for suspend fun in Kotlin.
  • dartjni now depends on dart_api_dl.h.

0.2.1

  • Added .clang-format to pub.

0.2.0

  • Added array support
  • Added generic support
  • JniX turned into JX for 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.6.1'
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.6.1
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
      macos:
        ffiPlugin: true
      android:
        ffiPlugin: true
        package: com.github.dart_lang.jni
        pluginClass: JniPlugin

Version history

VersionPublishedArchiveSHA-256
0.1.0Cached · Upstream SHA-256 matchedDownloadb237560e…ae6db4
0.1.1Cached · Upstream SHA-256 matchedDownload47000d71…3f9cd8
0.2.0Cached · Upstream SHA-256 matchedDownloadbea8d106…48d578
0.2.1Cached · Upstream SHA-256 matchedDownload075d1622…ff4e27
0.3.0Cached · Upstream SHA-256 matchedDownloadd1361580…7feb3d
0.4.0Cached · Upstream SHA-256 matchedDownload1b5c3708…9946d7
0.5.0Cached · Upstream SHA-256 matchedDownloada19d9f63…b0143c
0.6.0Cached · Upstream SHA-256 matchedDownloadef31e778…1ad72b
0.6.1Cached · Upstream SHA-256 matchedDownloadb4bed1f4…d2d02d
0.7.0Cached · Upstream SHA-256 matchedDownload6b322776…1baa72
0.7.1Cached · Upstream SHA-256 matchedDownloade63e1cca…76ffa2
0.7.2Cached · Upstream SHA-256 matchedDownload0d88790b…885b43
0.7.3Cached · Upstream SHA-256 matchedDownload499558e9…4e6611
0.8.0Cached · Upstream SHA-256 matchedDownload63984817…c39222
0.9.0Cached · Upstream SHA-256 matchedDownload4f20a803…3176af
0.9.1Cached · Upstream SHA-256 matchedDownload2a99a0cc…49f21c
0.9.2Cached · Upstream SHA-256 matchedDownload6f8e0433…8b665d
0.9.3Cached · Upstream SHA-256 matchedDownload85cf3fbc…8988a8
0.10.0Cached · Upstream SHA-256 matchedDownload08a0074b…ca2270
0.10.1Cached · Upstream SHA-256 matchedDownloadf377c585…acba4b
0.11.0Cached · Upstream SHA-256 matchedDownloadcaefbbf9…0d126f
0.12.0Cached · Upstream SHA-256 matchedDownload100fd0a7…5e595b
0.12.2Cached · Upstream SHA-256 matchedDownload459727a9…62ac4e
0.13.0Cached · Upstream SHA-256 matchedDownload3296e432…ca5faa
0.14.0Cached · Upstream SHA-256 matchedDownload302f50fd…db3b1f
0.14.1Cached · Upstream SHA-256 matchedDownloadcfd663ec…6adba6
0.14.2Cached · Upstream SHA-256 matchedDownloadd2c36108…2b3da1
0.15.0Cached · Upstream SHA-256 matchedDownload5b8d72fa…cdf76b
0.15.1Cached · Upstream SHA-256 matchedDownloadb4d27985…61f3df
0.15.2Cached · Upstream SHA-256 matchedDownload8706a77e…3ea12d
1.0.0Cached · Upstream SHA-256 matchedDownloadc2230682…b2e68f
1.0.1Cached · Upstream SHA-256 matchedDownloadca1efa31…93a4f4
1.0.2Cached · Upstream SHA-256 matchedDownload5bc9a9da…d978d1
1.0.3Cached · Upstream SHA-256 matchedDownloadf038e58b…04cbd3
1.1.0Cached · Upstream SHA-256 matchedDownload6b9ca060…2f402d
1.1.1Cached · Upstream SHA-256 matchedDownloadd8df6dab…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"