flutter module_error ai_generated true

Invalid argument(s): 加载动态库 'libmy_native.so' 失败:dlopen 失败:找不到库

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

ID: flutter/dart-ffi-missing-library

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
3.13.0 active — — —
3.16.0 active — — —
3.22.0 active — — —

根因分析

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

English

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

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 50% 失败

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

  2. 30% 失败

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

  3. 20% 失败

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