|
1 | 1 | # FFIgen + JNIgen pedometer
|
2 | 2 |
|
3 |
| -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. |
| 3 | +This is a demo for some of our tooling around |
| 4 | +calling platform APIs directly from dart code. |
| 5 | +This repository represents a demo of a plugin that leverages FFIgen & JNIgen. |
| 6 | +There is also an example pedometer app that |
| 7 | +uses the bindings generated from these tools. |
4 | 8 |
|
5 |
| -- [FFIgen](https://pub.dev/packages/ffigen) is used to generate bindings for C, Objective-C and Swift APIs |
6 |
| -- [JNIgen](https://pub.dev/packages/jnigen) is used to generate bindings for Java and Kotlin APIs |
7 |
| - |
8 |
| -**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. |
| 9 | +- [FFIgen](https://pub.dev/packages/ffigen) is used to generate |
| 10 | + bindings for C, Objective-C and Swift APIs. |
| 11 | +- [JNIgen](https://pub.dev/packages/jnigen) is used to generate |
| 12 | + bindings for Java and Kotlin APIs. |
9 | 13 |
|
| 14 | +**These tools are both experimental and are currently a work in progress.** |
| 15 | +If you find any issues or have feedback, |
| 16 | +please file it on the corresponding GitHub repositories. |
10 | 17 |
|
11 | 18 | ## Re-generating bindings
|
12 |
| -The bindings that allow the dart code to call the platform code have already been generated [here](/lib). You can regenerate them by following the steps below. |
| 19 | + |
| 20 | +The bindings that allow the Dart code to call the platform code have |
| 21 | +already been generated in the [`\lib` folder](./lib). |
| 22 | +You can regenerate them by following the steps below: |
13 | 23 |
|
14 | 24 | ### FFIgen
|
15 |
| -Configuration for FFIgen is [here](/ffigen.yaml) for the [CoreMotion](https://developer.apple.com/documentation/coremotion) framework. FFIgen currently does not support autogenerating the code to handle callbacks. So, there were a few steps needed to appropriately handle callbacks in Objective-C. You can [read more here](https://dart.dev/guides/libraries/objective-c-interop#callbacks-and-multithreading-limitations). |
16 | 25 |
|
17 |
| -`dart run ffigen --config ffigen.yaml` |
| 26 | +Configuration of FFIgen for the |
| 27 | +[CoreMotion framework](https://developer.apple.com/documentation/coremotion) |
| 28 | +is in the [`ffigen.yaml` file](./ffigen.yaml). |
| 29 | +FFIgen currently does not support autogenerating code to handle callbacks. |
| 30 | +So, there are a few extra steps needed to |
| 31 | +appropriately handle callbacks in Objective-C. |
| 32 | +You can read more about this limitation on |
| 33 | +[dart.dev]((https://dart.dev/guides/libraries/objective-c-interop#callbacks-and-multithreading-limitations). |
| 34 | + |
| 35 | +```bash |
| 36 | +dart run ffigen --config ffigen.yaml |
| 37 | +``` |
| 38 | + |
18 | 39 |
|
19 | 40 | ### JNIgen
|
20 |
| -Configuration for JNIgen is [here](/jnigen.yaml) for the [HealthConnect API](https://developer.android.com/guide/health-and-fitness/health-connect). |
21 | 41 |
|
22 |
| -1. `cd Example && flutter build apk` |
23 |
| -2. `cd .. && dart run jnigen --config jnigen.yaml` |
| 42 | +Configuration of JNIgen for the |
| 43 | +[HealthConnect API](https://developer.android.com/guide/health-and-fitness/health-connect) |
| 44 | +is in the [`jnigen.yaml` file](./jnigen.yaml). |
| 45 | + |
| 46 | +1. Build an Android APK file from the example app. |
| 47 | + Currently, JNIgen requires at least one APK build |
| 48 | + to obtain the classpaths of Android Gradle libraries. |
| 49 | + |
| 50 | + ```bash |
| 51 | + cd example && flutter build apk |
| 52 | + ``` |
24 | 53 |
|
| 54 | +2. Return to the `/pedometer` directory and run `jnigen`: |
| 55 | + |
| 56 | + ```bash |
| 57 | + cd .. && dart run jnigen --config jnigen.yaml |
| 58 | + ``` |
25 | 59 |
|
26 | 60 | ## Running the example app
|
27 |
| -The example app is located in the `experimental/pedometer/example` directory, |
28 |
| -and the commands below assume they are being run from that location. |
| 61 | + |
| 62 | +The example app is located in the [`/example`](./example) directory, |
| 63 | +and the following commands assume they are being run from that location. |
29 | 64 |
|
30 | 65 | Note that step counting is only available on physical devices.
|
31 | 66 |
|
32 | 67 | ### iOS
|
33 |
| -- `flutter run` |
34 |
| -- Allow *pedometer* app access to step counting |
| 68 | + |
| 69 | +- Run `flutter run` and choose your physical device. |
| 70 | +- Allow the *pedometer* app access to step counting. |
35 | 71 |
|
36 | 72 | ### Android
|
37 |
| -- Make sure that Google Fit is installed (to ensure that steps are being counted) |
38 |
| -- `flutter run` |
39 |
| -- Install Health Connect and grant access to Google Fit and the *jni_demo* app |
40 | 73 |
|
| 74 | +- Make sure that [Google Fit](https://play.google.com/store/apps/details?id=com.google.android.apps.fitness) |
| 75 | + is installed (to ensure that steps are being counted). |
| 76 | +- Run `flutter run` and choose your physical device. |
| 77 | +- Install [Health Connect](https://play.google.com/store/apps/details?id=com.google.android.apps.healthdata) |
| 78 | + and grant access to Google Fit and the *jni_demo* app. |
41 | 79 |
|
42 |
| -## Project stucture |
43 | 80 |
|
44 |
| -* `src`: Contains the native source code, and a CMakeLists.txt file for building |
45 |
| - that source code into a dynamic library. |
| 81 | +## Project structure |
| 82 | + |
| 83 | +* `src`: Contains the native source code, and a `CMakeLists.txt` file for |
| 84 | + building that source code into a dynamic library. |
46 | 85 |
|
47 |
| -* `lib`: Contains the Dart code that defines the API of the plugin, and which |
| 86 | +* `lib`: Contains the Dart code that defines the API of the plugin and |
48 | 87 | calls into the native code using `dart:ffi`.
|
49 | 88 |
|
50 |
| -* platform folders (`ios` etc.): Contains the build files |
51 |
| - for building and bundling the native code library with the platform application. |
| 89 | +* platform folders (`ios` etc.): Contain the build files for |
| 90 | + building and bundling the native code library with the platform application. |
52 | 91 |
|
53 | 92 | * `example`: Contains the native source code for building
|
54 | 93 | that source code into a dynamic library.
|
0 commit comments