Skip to content

Fix Android native math library linkage#211

Open
geirsagberg wants to merge 1 commit into
uber:masterfrom
geirsagberg:geir/fix-android-libm
Open

Fix Android native math library linkage#211
geirsagberg wants to merge 1 commit into
uber:masterfrom
geirsagberg:geir/fix-android-libm

Conversation

@geirsagberg

Copy link
Copy Markdown

Summary

  • link libm explicitly when building libh3-java.so for Android
  • retain the existing find_library behavior on other platforms
  • fail Android cross-builds when the generated ELF does not declare libm.so

Fixes #206.

Reproduction

Using com.uber:h3-android:4.4.0 on an Android 16 ARM64 emulator, H3Core.newSystemInstance() failed with:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "cos" referenced by "libh3-java.so"

The published library's dynamic section declared liblog.so, libdl.so, and libc.so, but not libm.so.

Verification

  • reproduced the failure with an Android instrumentation test on an Android 16 ARM64 emulator
  • rebuilt the Android ARM64 native library with this change
  • verified readelf -d includes NEEDED Shared library: [libm.so]
  • repackaged the AAR and reran the same instrumentation test successfully
  • ran ./gradlew spotlessCheck compileJava

This pull request was created using Codex with GPT-5.6 Sol (Medium reasoning).

@CLAassistant

CLAassistant commented Jul 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@geirsagberg

Copy link
Copy Markdown
Author

Here are simulator setup details that reproduce this without a physical device.

Environment

  • macOS ARM64 host
  • Android Emulator 36.6.11
  • Android 16 / API 36.1
  • ARM64 system image: system-images;android-36.1;google_apis_playstore;arm64-v8a
  • Dependency: com.uber:h3-android:4.4.0

I used an AVD named Medium_Phone_API_36.1 and launched it headlessly:

$ANDROID_SDK_ROOT/emulator/emulator @Medium_Phone_API_36.1 \
  -no-window \
  -no-audio \
  -no-boot-anim \
  -gpu swiftshader_indirect \
  -no-snapshot

Minimal instrumentation test

@RunWith(AndroidJUnit4::class)
class H3AndroidIntegrationTest {
    @Test
    fun loadsNativeH3() {
        val h3 = H3Core.newSystemInstance()
        val cell = h3.latLngToCell(59.9109, 10.7522, 12)

        assertEquals(0x08c09993866141ffL, cell)
        assertTrue(h3.cellToBoundary(cell).size >= 5)
    }
}

Run it with the emulator serial selected:

ANDROID_SERIAL=emulator-5554 ./gradlew connectedDebugAndroidTest

With the published 4.4.0 AAR, this deterministically fails during H3Core.newSystemInstance():

java.lang.UnsatisfiedLinkError:
dlopen failed: cannot locate symbol "cos" referenced by ".../lib/arm64-v8a/libh3-java.so"

I rebuilt the ARM64 AAR with this PR, installed it into the same test app, and reran the unchanged instrumentation test on the same AVD. It passes.

This reproduction and verification were performed using Codex with GPT-5.6 Sol (Medium reasoning).

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 649

Coverage remained the same at 96.954%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 570
Covered Lines: 559
Line Coverage: 98.07%
Relevant Branches: 185
Covered Branches: 173
Branch Coverage: 93.51%
Branches in Coverage %: Yes
Coverage Strength: 0.98 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants