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

- **ID:** `android/unsatisfiedlinkerror-libc++-shared-not-found`
- **领域:** android
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

应用使用带有 C++ STL 的原生代码，但未打包共享库 libc++_shared.so 或 APK 打包配置错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Android NDK r25c | active | — | — |
| Android NDK r26b | active | — | — |
| AGP 8.1.0 | active | — | — |
| AGP 8.2.2 | active | — | — |
| Gradle 8.4 | active | — | — |

## 解决方案

1. ```
   Add `packagingOptions { pickFirst '**/libc++_shared.so' }` in app/build.gradle to ensure the library is included from all dependencies without duplicates.
   ```
2. ```
   Set `android.defaultConfig.ndk.abiFilters 'arm64-v8a', 'x86_64'` to limit native builds to specific ABIs and bundle the correct libc++_shared.so.
   ```

## 无效尝试

- **** — Adding android:extractNativeLibs="true" in AndroidManifest.xml may help with extraction but does not fix missing library packaging; the library must be explicitly included. (70% 失败率)
- **** — Manually copying libc++_shared.so into jniLibs without matching CPU architectures often leads to UnsatisfiedLinkError for unsupported ABIs. (80% 失败率)
- **** — Setting android.useAndroidX=true alone does not resolve native library dependencies; it only affects Java/Kotlin dependencies. (90% 失败率)
