flutter module_error ai_generated true

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

ID: flutter/dart-ffi-library-not-found

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
1Evidence
2023-05-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Flutter 3.7 active
Dart 3.0 active
Android 12 active
iOS 15 active
Linux active

Root Cause

A Dart FFI binding references a native shared library that is not bundled with the app or not placed in the correct directory for the target platform (Android jniLibs, iOS Frameworks, or Linux/MacOS library paths).

generic

中文

Dart FFI 绑定引用的原生共享库未随应用打包,或未放置在目标平台的正确目录中(Android jniLibs、iOS Frameworks 或 Linux/MacOS 库路径)。

Official Documentation

https://dart.dev/guides/libraries/c-interop

Workarounds

  1. 85% success Place the shared library in the correct platform-specific directory: android/app/src/main/jniLibs/<abi>/ for Android, or use a Flutter plugin with native code.
    Place the shared library in the correct platform-specific directory: android/app/src/main/jniLibs/<abi>/ for Android, or use a Flutter plugin with native code.
  2. 70% success Use the ffi package's DynamicLibrary.process() to load symbols from the main process if the library is linked at compile time.
    Use the ffi package's DynamicLibrary.process() to load symbols from the main process if the library is linked at compile time.

中文步骤

  1. Place the shared library in the correct platform-specific directory: android/app/src/main/jniLibs/<abi>/ for Android, or use a Flutter plugin with native code.
  2. Use the ffi package's DynamicLibrary.process() to load symbols from the main process if the library is linked at compile time.

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Assets are not loaded as shared libraries; FFI requires the library to be in the system library path or bundled as a native dependency.

  2. 70% fail

    FFI resolves library paths from the system loader, not the Dart script's location; relative paths are platform-dependent and often fail.

  3. 60% fail

    On mobile platforms (Android/iOS), environment variables are not accessible to the app process; this only works on desktop.