Summary
h3-android crashes on physical Android devices when initializing H3Core because the packaged native library (libh3-java.so) appears to be missing an explicit dependency on libm.so.
This causes unresolved symbol failures for math functions like cos.
Environment
- Library:
com.uber:h3-android:4.4.0
- Also reproduced with:
4.3.2
- Device: physical Android device
- ABI:
arm64-v8a
- Android version: [fill yours]
Minimal reproduction
val h3 = H3Core.newSystemInstance()
Crash:
java.lang.UnsatisfiedLinkError:
dlopen failed: cannot locate symbol "cos" referenced by "/data/app/.../lib/arm64/libh3-java.so"
Additional note
Using:
fails differently:
java.lang.UnsatisfiedLinkError:
No native resource found at /android-arm64/libh3-java.so
This appears expected, since Android should use newSystemInstance().
Investigation
Inspecting the packaged native library:
Shows:
NEEDED Shared library: [liblog.so]
NEEDED Shared library: [libdl.so]
NEEDED Shared library: [libc.so]
libm.so is missing.
However, libh3-java.so references math symbols such as cos.
This suggests the native library was built in a way that does not correctly declare the runtime dependency on Android.
Why preloading libm does not help
Tried:
System.loadLibrary("m")
val h3 = H3Core.newSystemInstance()
Same failure.
Likely due to Android linker namespace isolation: preloading a library into the app namespace does not satisfy unresolved symbols unless the dependency exists in the library’s own DT_NEEDED chain.
Workaround
Patch libh3-java.so to explicitly add:
to DT_NEEDED.
After patching:
NEEDED Shared library: [libm.so]
NEEDED Shared library: [liblog.so]
NEEDED Shared library: [libdl.so]
NEEDED Shared library: [libc.so]
Then:
System.loadLibrary("h3-java")
val h3 = H3Core.newSystemInstance()
works correctly.
Confirmed working:
latLngToCellAddress(...)
cellToBoundary(...)
Expected fix
The Android native library should be rebuilt so libm.so is correctly included as a runtime dependency.
This seems to affect all currently published Android artifacts.
Summary
h3-androidcrashes on physical Android devices when initializingH3Corebecause the packaged native library (libh3-java.so) appears to be missing an explicit dependency onlibm.so.This causes unresolved symbol failures for math functions like
cos.Environment
com.uber:h3-android:4.4.04.3.2arm64-v8aMinimal reproduction
Crash:
Additional note
Using:
H3Core.newInstance()fails differently:
This appears expected, since Android should use
newSystemInstance().Investigation
Inspecting the packaged native library:
Shows:
libm.sois missing.However,
libh3-java.soreferences math symbols such ascos.This suggests the native library was built in a way that does not correctly declare the runtime dependency on Android.
Why preloading libm does not help
Tried:
Same failure.
Likely due to Android linker namespace isolation: preloading a library into the app namespace does not satisfy unresolved symbols unless the dependency exists in the library’s own
DT_NEEDEDchain.Workaround
Patch
libh3-java.soto explicitly add:to
DT_NEEDED.After patching:
Then:
works correctly.
Confirmed working:
latLngToCellAddress(...)cellToBoundary(...)Expected fix
The Android native library should be rebuilt so
libm.sois correctly included as a runtime dependency.This seems to affect all currently published Android artifacts.