Viewing version 0.1.0. Open the latest package page.

jni

0.1.0

Library to access JNI from dart and flutter

Download archive

Readme

jni (experimental module)

This is a utility library to access JNI from Dart / Flutter code, intended as a supplement for jnigen code generator, as well as provide the common base components (such as managing the JVM instance) to the code generated by jnigen.

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).

  • JniObject class, which provides base class for classes generated by jnigen.

This is intended for one-off / debugging uses of JNI, as well as providing a base library for code generated by jnigen.

To generate type-safe bindings from Java libraries, use jnigen.

Version note

This library is at an early stage of development and we do not provide backwards compatibility of the API at this point.

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.

jnigen

This library is a part of jnigen - a 2022 GSoC project.

The broader aim of jnigen is making Java APIs accessible from dart in an idiomatic way.

Changelog

0.1.0

  • Initial version: Android and Linux support, JniObject API

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'jni:0.1.0'
pubspec.yaml
name: jni
description: Library to access JNI from dart and flutter
version: 0.1.0
homepage: https://github.com/dart-lang/jnigen

environment:
  sdk: ">=2.17.1 <3.0.0"
  flutter: ">=2.11.0"

dependencies:
  plugin_platform_interface: ^2.0.2
  ffi: ^2.0.0
  path: ^1.8.0
  package_config: ^2.1.0
  args: ^2.3.1

dev_dependencies:
  ## After running `dart run ffigen --config ffigen.yaml` there
  ## should be no changes.
  ffigen:
    path: third_party/ffigen_patch_jni
  flutter_lints: ^2.0.0
  test: ^1.21.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"

ffi "^2.0.0"

package_config "^2.1.0"

path "^1.8.0"

plugin_platform_interface "^2.0.2"