how to use c++ code in flutter (android) application? how to use c++ code in flutter (android) application? dart dart

how to use c++ code in flutter (android) application?


Additional information (2021-05-05)

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.

Update (2019-09-10)

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).

Old answer (still valid)

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.