android runtime_error ai_generated true

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

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Android NDK r25c active
Android NDK r26b active
AGP 8.1.0 active
AGP 8.2.2 active
Gradle 8.4 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

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

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    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% fail

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

  3. 90% fail

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