Skip to content
pubscout

jnigen

1.1.0, released yesterday by tools.dart.dev

A Dart bindings generator for Java and Kotlin APIs using JNI and dart:ffi.

$ flutter pub add jnigen
Source repository

What it does

JNIgen scans compiled JAR files or Java source files to generate Dart bindings. The generated Dart code communicates with C bindings that call Java functions via the Java Native Interface (JNI).

AI-written summary of version 1.0.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to call custom Java or Kotlin APIs from a Flutter or Dart application on Android or desktop platforms.
  • You want automated generation of type-safe Dart wrappers around Java classes and methods.

Skip it when

  • You are writing a pure Dart app without JVM dependencies.
  • You do not have a JDK installed or configured for your build environment.

Strengths

  • Automates tedious FFI boilerplate for Java/Kotlin interop.
  • Supports Gradle and Android SDK dependencies out of the box.

Weaknesses

  • Requires manual configuration and a working JDK environment.
  • Class and symbol resolution can fail at runtime if ProGuard prunes classes on Android.

Setup

Kind
Pure Dart
Effort
High
Code generation
Yes (build_runner)
Direct dependencies
11

Requires a JDK (Java 17 to 21), CMake, and a C toolchain. For non-Android targets, manual JVM spawning via Jni.spawn is required.

import 'package:jnigen/jnigen.dart';

void main(List<String> args) async {
  final generator = JniGenerator(
    input: Input(
      classes: ['com.example.MyClass'],
    ),
    output: Output(
      dart: DartOutput(
        path: Uri.parse('lib/src/generated_bindings.dart'),
      ),
    ),
  );
  await generator.generate();
}

Alternatives

Packages that do the same job and could replace jnigen.

Works with

Packages commonly used together with jnigen: ones it builds on, ones built on it, and its own family.