I am developing an application in Flutter (for Android) whose core is based on a library developed only in C++ and python. Therefore, I would like to know how I can use this library in my dart code (either the C++ version or the Python version).
From @FacundoFarall comment to the original question:
Try this video by Richard Heap, it helped me quiet a lot. He explains with an example how to interact between the Dart code of your Flutter app, and the C++ library you're using, all through dart:ffi. I'd also recommend checking out this post for a way to debug the C++ code while running it through a Flutter app.
Today has been released Dart 2.5 (and Flutter 1.9). One of the additions to Dart 2.5 is "the dart:ffi foreign function interface for calling C code directly from Dart." I still haven't checked it, but it should provide a more direct path to interface with C (and C++) code.
See also the announcement video (confirms both old and new methods).
I would take a look at Platform Channels, which are a way to communicate Flutter code to platform native code (e.g. Java/Kotlin on Android, Objective C/Swift in iOS). From there, you can use your C++ library using the regular NDK mechanisms.
You can see an introduction to Flutter Platform Channels and Getting Started with the NDK.
Maybe there's a more direct route, but that's the one I know could work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With