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

- **ID:** `android/unsatisfiedlinkerror-native-lib-not-found`
- **领域:** android
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

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

## 解决方案

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.
   ```

## 无效尝试

- **** — Cleaning the project and rebuilding often fails because the root cause (missing ABI folder in jniLibs) persists. (70% 失败率)
- **** — Adding a random .so file from another project doesn't match the expected native API, causing different crashes. (85% 失败率)
- **** — Enabling minification (ProGuard/R8) may strip native libraries if not properly configured, making the error worse. (60% 失败率)
