android runtime_error ai_generated true

java.lang.UnsatisfiedLinkError: dlopen 失败:找不到库 "libmylib.so"

java.lang.UnsatisfiedLinkError: dlopen failed: library "libmylib.so" not found

ID: android/unsatisfiedlinkerror-native-lib-not-found

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
1证据数
2023-06-15首次发现

版本兼容性

版本状态引入弃用备注
Android 12 (API 31) active
Android 13 (API 33) active
Android 14 (API 34) active
NDK r26c active
Gradle 8.2 active

根因分析

原生库 (.so) 缺少设备 ABI 对应的版本,未打包到 APK 中,或从错误路径加载。

English

Native library (.so) is missing for the device's ABI, not bundled in APK, or loaded from wrong path.

generic

官方文档

https://developer.android.com/ndk/guides/abis

解决方案

  1. Place the correct .so file for each target ABI under app/src/main/jniLibs/<abi>/libmylib.so. For example: arm64-v8a, armeabi-v7a, x86_64. Then rebuild.
  2. In build.gradle (app level), add a packaging block to exclude unused ABIs: android { packagingOptions { jniLibs { useLegacyPackaging = true } } }
  3. If using a third-party SDK, verify the SDK version supports your target ABI and update the dependency. For example, if using OpenCV, ensure you include the correct ABI in the SDK distribution.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Cleaning the project and rebuilding often fails because the root cause (missing ABI folder in jniLibs) persists.

  2. 85% 失败

    Adding a random .so file from another project doesn't match the expected native API, causing different crashes.

  3. 60% 失败

    Enabling minification (ProGuard/R8) may strip native libraries if not properly configured, making the error worse.