Skip to content

Conversation

goderbauer
Copy link
Contributor

@goderbauer goderbauer commented Oct 6, 2025

Fixes #1640.

This adds a simple "getting started" section to the readme to guide newcomers through setting up jnigen for a Flutter app. It also shuffles some sections around and reflows the text.

Copy link

github-actions bot commented Oct 6, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

License Headers ✔️
// Copyright (c) 2025, 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.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

@coveralls
Copy link

coveralls commented Oct 6, 2025

Coverage Status

coverage: 81.228% (+0.4%) from 80.804%
when pulling 45719d8 on goderbauer:jnigenreadme
into 0924cb0 on dart-lang:main.

Copy link
Collaborator

@dcharkes dcharkes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have auto-line-break on, but it's not at 80 but 120? Is that intentional?

Should we have some standard for markdown files in this repo and enforce it with a ci check?

If it's not intentional, prefer not adding line-breaks to keep the git diff smaller and easier to review.

## Migrating to 0.14.2

When regenerating bindings after an upgrade to JNIgen in the one file per class mode, you will need to delete the old bindings once to fix `A file that was not generated by JNIgen was found in ...` error.
When regenerating bindings after an upgrade to JNIgen in the one file per class mode, you will need to delete the old
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in the changelog instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already in there. I'll add some highlight to it and remove it from here.

Experimental bindings generator for Java bindings through dart:ffi and JNI.

`jnigen` scans compiled JAR files or Java source code to generate a description of the API, then uses it to generate Dart bindings. The Dart bindings call the C bindings, which in-turn call the Java functions through JNI. Shared functionality and base classes are provided through the support library, `package:jni`.
Bindings generator to simplify calling Java APIs from Dart code via `dart:ffi` and JNI.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to simply calling -> to call

Bindings are generated for methods, constructors, and fields. Exceptions thrown in Java are rethrown in Dart with stack
trace from Java.

More advanced features such as callbacks are not supported yet. Support for these features is tracked in the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this supported by now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Currently basic features of the Java language are supported in the bindings. Each Java class is mapped to a Dart class. Bindings are generated for methods, constructors and fields. Exceptions thrown in Java are rethrown in Dart with stack trace from Java.

More advanced features such as callbacks are not supported yet. Support for these features is tracked in the [issue tracker](https://github.com/dart-lang/native/issues?q=is%3Aopen+is%3Aissue+label%3Apackage%3Ajni%2Cpackage%3Ajnigen).
Currently basic features of the Java language are supported in the bindings. Each Java class is mapped to a Dart class.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rephrase this. We're no longer interested in mapping features 1-to-1 due to impedance mismatches. JNIgen is a layer-1 tool.

Side note: We should add the 3-layer markdown file on the repo here somewhere so that we can refer to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggested phrasing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just: Bindings are generated for classes, methods, constructors, and fields. (leaving out how they are mapped or generated.)


Dart standalone target is supported, but due to some problems with pubspec format, the `dart` command must be from Flutter SDK and not Dart SDK. See [dart-lang/pub#3563](https://github.com/dart-lang/pub/issues/3563).
Dart standalone target is supported, but due to some problems with pubspec format, the `dart` command must be from the
Flutter SDK and not Dart SDK. See [dart-lang/pub#3563](https://github.com/dart-lang/pub/issues/3563).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to make it Dart standalone when we have native assets in stable, and when we split out the android context into package:jni_flutter. cc @HosseinYousefi will know for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now let's leave the readme like this.

@dcharkes
Copy link
Collaborator

dcharkes commented Oct 7, 2025

LGTM to overall flow! 🙏

to the pubspec of your app by running:

Check out the [examples](example/) to see some sample configurations.
```shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it's possible to do flutter pub add jni dev:jnigen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Bindings are generated for methods, constructors, and fields. Exceptions thrown in Java are rethrown in Dart with stack
trace from Java.

More advanced features such as callbacks are not supported yet. Support for these features is tracked in the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually they are supported, I forgot to update this section!


Dart standalone target is supported, but due to some problems with pubspec format, the `dart` command must be from Flutter SDK and not Dart SDK. See [dart-lang/pub#3563](https://github.com/dart-lang/pub/issues/3563).
Dart standalone target is supported, but due to some problems with pubspec format, the `dart` command must be from the
Flutter SDK and not Dart SDK. See [dart-lang/pub#3563](https://github.com/dart-lang/pub/issues/3563).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now let's leave the readme like this.

@goderbauer
Copy link
Contributor Author

You have auto-line-break on, but it's not at 80 but 120? Is that intentional?

The reflow was intentional since most other markdowns in this repo also seem to implicitly follow a limit and it does make the file easier to read in environments that don't render the markdown. Not intentional was the 120 limit, should have been 80. That's fixed now.

@goderbauer
Copy link
Contributor Author

cc @stuartmorgan-g Are you interested in taking a look at the revamped readme to incorporate your feedback?

Copy link

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new intro is great! This definitely addresses the core of #1640 from my perspective. I think the notes in that issue about the Requirements section are probably still valid, but it also makes sense to address those separately, so we can split them into a new issue.

I flagged a couple of nits that I happened to notice while re-reading the whole doc, but they are for pre-existing sections so feel free to ignore them here.

| Android | n/a | Supported |
| Linux | Supported | Supported |
| Windows | Supported | Supported |
| MacOS | Supported | Not Yet |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit while the file is being overhauled: the name of the OS is macOS, not MacOS. (It's confusing because it used to be Mac OS X.)

## Note on Dart (standalone) target
`package:jni` is an FFI plugin containing native code, and any bindings generated from jnigen contains native code too.
`package:jni` is an FFI plugin containing native code, and any bindings
generated from jnigen contains native code too.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: contain

application targeting Android. It assumes that Flutter has been set up to build
apps for Android
([instructions](https://docs.flutter.dev/platform-integration/android/setup))
and that the Flutter app was created via `flutter create in_app_java`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth adding a forward-link to the Requirements section here? Maybe something like "If you encounter issues running the commands below, check [the detailed setup requirements](...)".

@auto-submit auto-submit bot merged commit 2760e5d into dart-lang:main Oct 8, 2025
36 checks passed
@goderbauer goderbauer deleted the jnigenreadme branch October 9, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[jnigen] README structure doesn't provide a simple getting started flow
5 participants