Bumps [ffigen](https://github.com/dart-lang/native/tree/main/pkgs) from 14.0.1 to 15.0.0. <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/dart-lang/native/commits/HEAD/pkgs">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>
FFIgen + JNIgen pedometer
This is a demo for some of our tooling around calling platform APIs directly from dart code. This repository represents a demo of a plugin that leverages FFIgen & JNIgen. There is also an example pedometer app that uses the bindings generated from these tools.
- FFIgen is used to generate bindings for C, Objective-C and Swift APIs.
- JNIgen is used to generate bindings for Java and Kotlin APIs.
These tools are both experimental and are currently a work in progress. If you find any issues or have feedback, please file it on the corresponding GitHub repositories.
Re-generating bindings
The bindings that allow the Dart code to call the platform code have
already been generated in the \lib folder.
You can regenerate them by following the steps below:
FFIgen
Configuration of FFIgen for the
CoreMotion framework
is in the ffigen.yaml file.
FFIgen currently does not support autogenerating code to handle callbacks.
So, there are a few extra steps needed to
appropriately handle callbacks in Objective-C.
You can read more about this limitation on
dart.dev.
dart run ffigen --config ffigen.yaml
JNIgen
Configuration of JNIgen for the
HealthConnect API
is in the jnigen.yaml file.
-
Build an Android APK file from the example app. Currently, JNIgen requires at least one APK build to obtain the classpaths of Android Gradle libraries.
cd example && flutter build apk -
Return to the
/pedometerdirectory and runjnigen:cd .. && dart run jnigen --config jnigen.yaml
Running the example app
The example app is located in the /example directory,
and the following commands assume they are being run from that location.
Note that step counting is only available on physical devices.
iOS
- Run
flutter runand choose your physical device. - Allow the pedometer app access to step counting.
Android
- Make sure that Google Fit is installed (to ensure that steps are being counted).
- Run
flutter runand choose your physical device. - Install Health Connect and grant access to Google Fit and the jni_demo app.
Project structure
-
src: Contains the native source code, and aCMakeLists.txtfile for building that source code into a dynamic library. -
lib: Contains the Dart code that defines the API of the plugin and calls into the native code usingdart:ffi. -
platform folders (
iosetc.): Contain the build files for building and bundling the native code library with the platform application. -
example: Contains the native source code for building that source code into a dynamic library.