Skip to content

h3-android crashes on Android: unresolved symbol cos (libm.so missing from DT_NEEDED) #206

@JesusCabrera84

Description

@JesusCabrera84

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:

H3Core.newInstance()

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:

readelf -d libh3-java.so

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:

libm.so

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions