flutter module_error ai_generated true

Invalid argument(s): Failed to load dynamic library 'libmy_native.so': dlopen failed: library not found

ID: flutter/dart-ffi-missing-library

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.13.0 active — — —
3.16.0 active — — —
3.22.0 active — — —

Root Cause

The native library (.so file) is not bundled with the app or not placed in the correct ABI directory.

generic

中文

本机库(.so 文件)未与应用捆绑或未放置在正确的 ABI 目录中。

Official Documentation

https://api.flutter.dev/flutter/dart-ffi/dart-ffi-library.html

Workarounds

  1. 85% success Place the .so files in the correct jniLibs directory structure (e.g., android/app/src/main/jniLibs/arm64-v8a/).
    Place the .so files in the correct jniLibs directory structure (e.g., android/app/src/main/jniLibs/arm64-v8a/).
  2. 90% success Use the flutter_ffi plugin's built-in bundling mechanism by declaring the library in pubspec.yaml under 'ffi_native_libraries'.
    Use the flutter_ffi plugin's built-in bundling mechanism by declaring the library in pubspec.yaml under 'ffi_native_libraries'.
  3. 80% success Configure Gradle to include the library by adding jniLibs sourceSets in android/app/build.gradle.
    Configure Gradle to include the library by adding jniLibs sourceSets in android/app/build.gradle.

中文步骤

  1. Place the .so files in the correct jniLibs directory structure (e.g., android/app/src/main/jniLibs/arm64-v8a/).
  2. Use the flutter_ffi plugin's built-in bundling mechanism by declaring the library in pubspec.yaml under 'ffi_native_libraries'.
  3. Configure Gradle to include the library by adding jniLibs sourceSets in android/app/build.gradle.

Dead Ends

Common approaches that don't work:

  1. 50% fail

    Flutter's Gradle build does not automatically include libs/ unless jniLibs sourceSets are configured.

  2. 30% fail

    Android will not load the library if the ABI does not match the device's architecture.

  3. 20% fail

    Prevents extraction of native libs from APK; library file remains inaccessible at runtime.