how to bundle flutter ffi plugin

333

I have managed to get this running, the pubspec.yaml was incorrectly formatted and required:

flutter:
  plugin:
    platforms:
      android:
        package: com.example.h3
        pluginClass: H3Plugin
      ios:
        pluginClass: H3Plugin

Adding in at the end.

In doing this the package was properly attached.

libh3.so needs to be added into android/src/main/jniLibs to naturally be attached however I also moved the code:

final DynamicLibrary h3 = Platform.isAndroid
        ? DynamicLibrary.open("libh3.so")
        : DynamicLibrary.process();

Back into h3.dart and removed main.dart to get this to run.

I think these were the main issues to get the code running. I had issues working out what was wrong as I am new to plugins - so it was a long process to sit and work out all the ins and outs. In doing this I ended up reworking all of the code to understand what was going on. If none of these points work or you wants eyes on the working code let me know and I can upload it to Github.

Share:
333
LeaveTrails
Author by

LeaveTrails

Updated on December 26, 2022

Comments

  • LeaveTrails
    LeaveTrails over 1 year

    I am writing uber h3 plugin for flutter. I have working source code but I have problems with creating package more precisely I have problems to bundle libh3.so

    Quick overview:

    1. there is uber h3 c source code which is downloaded by. download_deps.sh
    2. then android/build.gradle has build commands
        externalNativeBuild {
            cmake {
                path "../ios/CMakeLists.txt"
            }
        }
    
    1. then example/lib/main.dart has some initialization code.
      initializeH3((String name) => Platform.isAndroid
          ? DynamicLibrary.open("lib${name}.so")
          : DynamicLibrary.process());
    

    but when I try to build it library file can not be found. -I tried different locations. It seems that library native .so is not bundled into application

    But I don't konw why

    According to tutorial https://flutter.dev/docs/development/platform-integration/c-interop it should be bundled.

    Here is the source code https://github.com/fmatuszewski/h3