Search code examples
flutterdartffidart-ffi

How can I load a C dynamic library for FFI by specifying path in flutter?


I want to load a C Dynamic Library in flutter, how can I specify the path, and open it? is it possible to add .so file to the asset folder?

final dynamicLibrary = DynamicLibrary.open(libraryPath);

final Pointer<Utf8> Function() _someMethod = dynamicLibrary
    .lookup<NativeFunction<Pointer<Utf8> Function()>>(
      'native_some_method',
    )
    .asFunction();

Solution

  • No, you can't, Because Android has multiple system kernels for example X86, X86-32 etc. If you add some .so (shared library) under the asset folder maybe you can use just one simulator. That's the way .c or .cpp files should compile with Android NDK.