android runtime_error ai_generated true

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

java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found

ID: android/unsatisfiedlinkerror-libc++-shared-not-found

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

版本兼容性

版本状态引入弃用备注
Android NDK r25c active
Android NDK r26b active
AGP 8.1.0 active
AGP 8.2.2 active
Gradle 8.4 active

根因分析

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

English

App uses native code with C++ STL but the shared library libc++_shared.so is not bundled or its APK packaging is misconfigured.

generic

官方文档

https://developer.android.com/ndk/guides/cpp-support#shared_runtime

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Adding android:extractNativeLibs="true" in AndroidManifest.xml may help with extraction but does not fix missing library packaging; the library must be explicitly included.

  2. 80% 失败

    Manually copying libc++_shared.so into jniLibs without matching CPU architectures often leads to UnsatisfiedLinkError for unsupported ABIs.

  3. 90% 失败

    Setting android.useAndroidX=true alone does not resolve native library dependencies; it only affects Java/Kotlin dependencies.