whoami
Lucas Jenß
cat /etc/motd
The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.
ls -la ~/languages/
- drwxr-xr-x
- ▶ PHP
- ▶ Ruby
- ▶ Scala
- ▶ C#
- ▶ JavaScript
- ▶ Objective-C
- ▶ Shell Scripting
ls -la ~/toolchain/
- drwxr-xr-x
- ▶ Typo3
- ▶ Akka
- ▶ Capistrano
- ▶ Git
- ▶ MAMP
- ▶ Adobe Illustrator
- ▶ NSTrackingArea (Cocoa)
uname -a
- drwxr-xr-x
- ▶ Mac OS X
- ▶ Unix
Fixing missing libc++_shared.so in Android NDK builds
The libc++_shared.so error usually means an Android native library was built against the NDK’s shared C++ runtime, but that runtime was not included in the installable package. A build can compile successfully and still fail on installation or first use with UnsatisfiedLinkError, dlopen failed, or “library not found”. Native C++ code needs this runtime for standard-library and low-level support routines.
The repair depends on where the failure occurs: configuration, packaging, installation, or runtime loading. Confirm the library’s ELF dependencies and the ABIs inside the APK before changing code. For Australian teams, that check also prevents a fix from working on a Melbourne x86_64 emulator while failing on a Sydney tester’s arm64 Samsung or Pixel handset.
Know what the shared C++ runtime provides
Android’s native loader resolves a .so dependency before it calls the module’s entry point. When libnative_app.so records libc++_shared.so as NEEDED, the latter must exist in the APK’s native-library directory for the same ABI. A project that reads motion or environmental sensors from C++, as described in Android NDK hardware sensors, is exposed to the same packaging rule as any other native module.
Using the static runtime instead removes this separate dependency, but it can enlarge the APK and duplicate C++ runtime code when several native libraries are present. The shared runtime is usually cleaner for multi-library apps: package one copy per supported ABI and let every native module resolve the same runtime.
Configure CMake and ndk-build correctly
With CMake, locate the NDK-provided runtime and link it to the module that uses C++. Do not hard-code a workstation path in the project.
find_library(CPP_SHARED c++_shared)
if(NOT CPP_SHARED)
message(FATAL_ERROR "c++_shared was not found in the selected NDK")
endif()
add_library(native_app SHARED native_app.cpp)
target_link_libraries(native_app PRIVATE ${CPP_SHARED})
find_library resolves the library for the ABI and platform being compiled. target_link_libraries then records the dependency and allows the linker to report missing symbols or unavailable runtimes during the build, rather than leaving discovery to the device. Keep the variable name and imported target consistent across the project.
For ndk-build, set the shared STL in Application.mk and preload the runtime from Android.mk when C++ is used:
# Application.mk
APP_STL := c++_shared
# Android.mk
LOCAL_LD_PRELOAD := libc++_shared.so
After changing from static to shared linking, delete the external native build directory or run a clean task. Stale CMake cache files can preserve the old runtime choice and make a corrected configuration appear ineffective.
Package one runtime copy for each ABI
When packaging the runtime manually, place it in the conventional source set, with the ABI directory exactly matching the target device:
app/src/main/jniLibs/arm64-v8a/libc++_shared.so
app/src/main/jniLibs/armeabi-v7a/libc++_shared.so
app/src/main/jniLibs/x86_64/libc++_shared.so
Gradle must include that source set and request the same ABIs:
android {
defaultConfig {
ndk {
abiFilters "arm64-v8a", "armeabi-v7a", "x86_64"
}
}
sourceSets {
main {
jniLibs.srcDirs += ["src/main/jniLibs"]
}
}
}
Source the file from the NDK version declared by the project, normally under toolchains/llvm/prebuilt/<host>/sysroot/usr/lib/<triple>/. Avoid copying an arbitrary file from another NDK release. An arm64 binary cannot run on an x86_64 emulator, and an x86_64 binary cannot run on a 32-bit-only Android device. Check for duplicate source directories as well; two copies can produce an unpredictable winner during packaging.
Match the error message to its cause
Configuration failures, package-inspection failures and launch failures have different causes. Treating them as one “missing file” problem often sends developers to the wrong layer.
Use the point of failure to narrow the diagnosis:
| Failure point | Typical evidence | Likely cause | Corrective action |
|---|---|---|---|
| CMake configuration | c++_shared cannot be found |
The wrong NDK is selected or its toolchain files are unavailable | Select the declared NDK, clear the CMake cache and rerun configuration |
| APK inspection | No libc++_shared.so appears under lib/<abi> |
The shared runtime was linked but never exported into the package | Add the runtime to jniLibs and confirm Gradle includes that source set |
| Device installation | UnsatisfiedLinkError or dlopen failed |
The required .so is absent from the installed APK |
Inspect the exact artifact being installed and package the matching ABI |
| Device installation | Wrong ELF class or architecture message | An arm64, x86_64 or 32-bit binary was copied into the wrong directory | Install an ABI-specific runtime for every supported architecture |
| First native call | The application module loads but a dependency fails | Another native library transitively requires the C++ runtime | Inspect the NEEDED entries of every bundled .so |
Two quick inspections settle most cases. List the APK contents with unzip -l app-debug.apk | grep libc++_shared, then use the NDK’s llvm-readelf -d on each native library to view its NEEDED entries. If the top-level module does not name the runtime, inspect its dependencies too; a second .so may be the component that requires it.
Validate emulators and physical Android devices
Android’s ABI split matters during validation. An x86_64 emulator image exercises a different native binary from a modern arm64 phone, and a 32-bit image or old armeabi-v7a device needs another package. Confirm the target with adb shell getprop ro.product.cpu.abi and ro.product.cpu.abilist, then install the exact variant produced by Gradle.
Use the channel mix relevant to the Australian market: test the Google Play build and, where distributed through it, the Samsung Galaxy Store package. Both services consume the same signed artifact, so differences in install permissions or native-library extraction should be caught before rollout. For projects that extend into companion hardware, the AtmOSPHERE project resources provide wider context, but they do not replace ABI-correct Android packaging.
A practical Australian habit is to retry an app while moving between office Wi-Fi and a train connection. An offline cold-start check is useful here because native libraries load before many network-dependent screens appear. A launch that works tethered on a workstation but fails on the handset usually points to packaging rather than connectivity.
Prevent regressions across build variants
Make the fix reproducible across debug, release and App Bundle outputs. Clean stale outputs after changing the STL, inspect the merged native libraries, and confirm that release minification or ABI filtering has not removed a required file. useLegacyPackaging may help when installation must extract compressed libraries, but it cannot compensate for a runtime that was never packaged.
Diagnostic logging also needs release discipline. If crash data contains device, advertising or user identifiers, covered organisations must assess their handling against the Privacy Act 1988 and Australian Privacy Principles. Keep verbose loader messages in a development build, redact identifiers from production reports and document what is collected.
Keep native loading separate from other rendering problems. If the same project animates SVG inside a WebView, the pattern in SVG requestAnimationFrame transitions addresses frame scheduling; it does not resolve an Android linker error. Separating those layers prevents a UI performance tweak from being used as a substitute for correcting the runtime package.
Make the repair repeatable and release-ready
These checks turn a one-off repair into a repeatable release process:
- Inspect every native library with
llvm-readelf -dand identify which module first requireslibc++_shared.so. - Link the shared runtime in CMake or
ndk-build, then package an ABI-matched copy from the declared NDK. - Align
abiFilters, supported devices and native outputs so no shipped architecture is left untested. - Clean, assemble and inspect both APK and App Bundle artefacts before uploading to Google Play.
- Retain a minimal install log and run one physical-device launch test outside the emulator.
Open the failing project now, identify the first missing dependency and correct the package at that layer. Then rebuild from a clean state and verify the same artefact on both an emulator and a real Android device before release.
cat ~/interests.json
| Key | Value |
|---|---|
| editor | Terminal-first workflow |
| os | Mac OS X / Unix |
| vcs | Git, distributed version control |
| deploy | Capistrano, cron automation |
| graphics | SVG, Adobe Illustrator troubleshooting |
| networking | IP validation, SSH, VPN |
git log --oneline --reverse
Solving SVG import issues in Adobe Illustrator CS6 and CC
When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.
Solving NDK build issues on OS X
Troubleshooting native development kit compilation problems on Mac OS X.
Programmatically adding PHP generated TypoScript to the backend configuration
Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.
ArgumentError: Could not parse PKey: no start line
Debugging an SSH key parsing error encountered during deployment.
Validating IP-Addresses in PHP
Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.
Cocoa: Using NSTrackingArea
A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.
cat ~/contact.txt