jnigen
1.1.0, released yesterday by tools.dart.dev
A Dart bindings generator for Java and Kotlin APIs using JNI and dart:ffi.
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.
- objective_c
Support library for accessing Objective C via ffigen in Flutter
90Compare - flutter_rust_bridge
Flutter/Dart and Rust binding generator
92Compare - native_toolchain_c
Invoke the native C compiler installed on the host machine.
85Compare - swiftgen
A tool for generating bindings that allow interop between Dart and Swift code.
78Compare
Works with
Packages commonly used together with jnigen: ones it builds on, ones built on it, and its own family.
- yamljnigen depends on itA Dart library for parsing YAML documents into Dart data structures.
- pub_semverjnigen depends on itVersions and version constraints implementing pub's versioning policy.
- package_configjnigen depends on itRead and write Dart package configuration files.
- json_annotationjnigen depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- argsjnigen depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.
- loggingjnigen depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- cli_configjnigen depends on itLibrary to read config from CLI args, env vars, and JSON/YAML files
- analyzerSame familyPerforms static analysis of Dart code for tool integration and embedding.