Android app crashes because libc++_shared.so is missing from the APK
Your error
java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found1 more line it can showFix it fast
Most common cause, 1 of 3CMake uses its default static runtime while another library expects the shared one
Pass -DANDROID_STL=c++_shared in android.defaultConfig.externalNativeBuild.cmake.arguments.
// app/build.gradle.kts
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments.add("-DANDROID_STL=c++_shared")
}
}
}
}Short answer
UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found means one of the app's native libraries was linked against the NDK's shared C++ runtime, but the APK does not carry it. libc++ is not an Android system library. Select c++_shared (ANDROID_STL for CMake, APP_STL for ndk-build) so Gradle packages it, or copy it into jniLibs. Applies to NDK r28 with AGP 9.5.
Which cause do you have?
List the native libraries inside the built APK, then read the dynamic section of the library that fails to load. When libc++_shared.so shows up as NEEDED but is absent from the APK folder for that ABI, the runtime was never packaged, and the causes below differ only in how your project builds native code.
unzip -l app-debug.apk | grep "lib/.*\.so"
NDK=/path/to/your/ndk # for example the ndk/28.2.13676358 folder of your Android SDK
$NDK/toolchains/llvm/prebuilt/*/bin/llvm-readelf --dynamic app/src/main/jniLibs/arm64-v8a/libvendor.so | grep NEEDEDThen find the line you see in this list and open its fix:
- 1CMake uses its default static runtime while another library expects the shared one
An externalNativeBuild cmake block exists, no ANDROID_STL argument is set, and a prebuilt or imported library lists libc++_shared.so as NEEDED - 2ndk-build runs with no C++ runtime selected
The module builds with Android.mk, and Application.mk has no APP_STL line - 3The app only ships prebuilt .so files, with no NDK build of its own
There is no externalNativeBuild block; the libraries sit in src/main/jniLibs or come from a vendor SDK
What does the error look like?
java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not foundThe app crashes in System.loadLibrary at start-up; the APK contains your .so files but no libc++_shared.so
Cause 1 of 3
CMake uses its default static runtime while another library expects the shared one
You seeAn externalNativeBuild cmake block exists, no ANDROID_STL argument is set, and a prebuilt or imported library lists libc++_shared.so as NEEDED
Check
In a CMake project the NDK links c++_static unless ANDROID_STL says otherwise, so no libc++_shared.so is produced for Gradle to add. Any prebuilt library compiled against the shared runtime then reports it as not found when the app starts.
grep -rn "ANDROID_STL" app/build.gradle* app/src/main/cppFix
Pass -DANDROID_STL=c++_shared in android.defaultConfig.externalNativeBuild.cmake.arguments. Gradle then includes libc++_shared.so for every ABI it builds. Use the same runtime in all native code of the app: the NDK guide allows only one C++ runtime per app.
// app/build.gradle.kts
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments.add("-DANDROID_STL=c++_shared")
}
}
}
}Verify
The APK listing now has lib/<abi>/libc++_shared.so beside your own libraries, and the app opens.
unzip -l app-debug.apk | grep "libc++_shared.so"Confirmed by developer.android.com
Cause 2 of 3
ndk-build runs with no C++ runtime selected
You seeThe module builds with Android.mk, and Application.mk has no APP_STL line
Check
ndk-build's default runtime is none, which means no C++ standard library at all. Code or a prebuilt module that was linked against libc++_shared.so finds nothing to load, because nothing was packaged.
grep -rn "APP_STL" --include=Application.mk .Fix
Choose the shared runtime in Application.mk. ndk-build takes a single runtime for the whole app and reads it only from that file; Gradle then packages libc++_shared.so with the build.
# Application.mk
APP_STL := c++_sharedVerify
After a clean build, unzip -l shows libc++_shared.so in each ABI folder and System.loadLibrary returns normally.
./gradlew clean :app:assembleDebugConfirmed by developer.android.com
Cause 3 of 3
The app only ships prebuilt .so files, with no NDK build of its own
You seeThere is no externalNativeBuild block; the libraries sit in src/main/jniLibs or come from a vendor SDK
Check
Gradle packages prebuilt libraries that no external native build uses from src/main/jniLibs/<ABI>. The NDK's maintainer guide says a library using the shared runtime needs libc++_shared.so inside the APK, so a vendor .so dropped into jniLibs without it fails to load.
Fix
Copy libc++_shared.so from the NDK sysroot into the jniLibs folder of each ABI you ship. Prefer the NDK version that built the vendor libraries, since the C++ support guide recommends matching NDK versions for the best compatibility.
NDK=/path/to/the/ndk/that/built/the/vendor/libs
cp $NDK/toolchains/llvm/prebuilt/*/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so app/src/main/jniLibs/arm64-v8a/
cp $NDK/toolchains/llvm/prebuilt/*/sysroot/usr/lib/x86_64-linux-android/libc++_shared.so app/src/main/jniLibs/x86_64/Verify
Both lib/arm64-v8a/libc++_shared.so and lib/x86_64/libc++_shared.so appear in the APK, and the app loads on a phone and on an x86_64 emulator.
unzip -l app-debug.apk | grep "libc++_shared.so"Confirmed by android.googlesource.com
How do I stop it coming back?
- Add a CI step that unzips the release build and fails when any packaged library needs libc++_shared.so but that ABI folder lacks it.
- Write down the NDK version and runtime choice next to every vendor .so you add, and ask the vendor for builds that match your own.
- If you publish an AAR with JNI code, link it with c++_static; the NDK guide says libraries distributed in AARs must not use the shared runtime.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: QistLock, Nuclear Home Video.