android runtime_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2023-06-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Android 12 (API 31) active
Android 13 (API 33) active
Android 14 (API 34) active
NDK r26c active
Gradle 8.2 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 90% success 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.
    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. 75% success In build.gradle (app level), add a packaging block to exclude unused ABIs: android { packagingOptions { jniLibs { useLegacyPackaging = true } } }
    In build.gradle (app level), add a packaging block to exclude unused ABIs: android { packagingOptions { jniLibs { useLegacyPackaging = true } } }
  3. 80% success 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.
    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. 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.

Dead Ends

Common approaches that don't work:

  1. 70% fail

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

  2. 85% fail

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

  3. 60% fail

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