How to handle native dependencies in Flutter plugin

Viewed 196

I'm trying to create a Flutter plugin which wraps some C++ code. That code has multiple dependencies, so steps need to be taken to provide those dependencies to the C++ build system (currently based on cmake, building for windows desktop), particularly where to find headers and libraries. There are a number of ways to do this with CMake, and we happen to be using Conan to fetch and provided dependencies, but in any case, I need a way to do a pre-build step and/or provide arguments to Flutter's execution of cmake to help it locate these dependencies.

I have ascertained that Flutter doesn't support a lot of (or any) customizability of the build. There are the build and build_runner packages, but I don't believe they will have knowledge of the build output directory for my platform nor provide a way to inject arguments to the cmake invocation.

How can I feed dependencies to the native build of the Flutter plugin? These dependencies may be static or dynamic libraries.

1 Answers

The only possible official way to interop with C/C++ code is ffi library. There is not much info about it online, but there is the official documentation.

Keep in mind that C-interop is parent platform dependent.

To properly generate binding with the needed native code, you have ffigen library. I think it will also help you with your dependencies issue.

Hope it helps

Related