h3-java: Failure on MacBook M1

Hi,

I tried to build our software using the H3 library on a new MacBook M1. Unfortunately I do get the following error:

java.lang.UnsatisfiedLinkError: No native resource found at /darwin-arm64/libh3-java.dylib at com.uber.h3core.H3CoreLoader.copyResource(H3CoreLoader.java:68) at com.uber.h3core.H3CoreLoader.loadNatives(H3CoreLoader.java:120) at com.uber.h3core.H3CoreLoader.loadNatives(H3CoreLoader.java:89) at com.uber.h3core.H3Core.newInstance(H3Core.java:79)

I already found out that this is because there simply is no native library for the combination of operating system (darwin) and architecture (arm64). So my questions are: Is a fix already planned? Is there a workaround?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (1 by maintainers)

Most upvoted comments

v3.7.2 should now be released to Maven Central which should include the darwin-arm64 binary!

@g-derzhavets

Does this mean I can not run v3.7.2 on Ubuntu 16.04?

I believe this is the same issue as #85 and #88. While I can take a look at pinning dockcross to a far back enough version, Ubuntu 16.04 is out of standard support so I would suggest upgrading to the latest LTS if possible.

I am also on M1 mac with Monterey macOs. I have a gradle project, that uses the com.uber:h3:3.4.1 lib. I’ve managed to build the libs locally via mvn clean install -Dh3.use.docker=false and I see that the new libs (3.7.2) were copied into my .m2 repository. I am not that proficient with dependencies, so would you be able to explain, where should I put these jars so my gradle project in Intellij could use them? @isaacbrodsky thanks

upd: I managed to make gradle (with this recommendation) to use the lib from my .m2 and my build ran successfully. Thanks a lot @muthenberg for raising the issue and @isaacbrodsky for fixing it 😃

I hope the lib for arm will be soon published to the maven repository.

@muthenberg Would you be able to upload a complete build log to Gist?

I think the issue you are running into may be due to the Docker cross compiling failing (it needs to use a JNI header from the host platform.) Please try instead mvn clean install -Dh3.use.docker=false

Could you also post the output of uname -sm? The file build-h3.sh may need to be updated to put the library in the right place. Probably something like adding:

   "Darwin arm64") LIBRARY_DIR=darwin-arm64 ;;

(There’s also the possibility that H3CoreLoader.java will need a small update to detect the right library to load. If that’s the case you should be able to use H3Core.newInstance(H3CoreLoader.OperatingSystem.DARWIN, "arm64") as a workaround.)

BTW.: If I try to build the newest version (commit #661bea1) with mvn clean install I get:

[INFO] ...
[INFO]
[INFO] -- Configuring done
[INFO] -- Generating done
[INFO] -- Build files have been written to: /work/target/h3-java-build-linux-arm64
[INFO] + make h3-java
[INFO] [ 50%] Building C object CMakeFiles/h3-java.dir/src/jniapi.c.o
[INFO] In file included from /work/src/main/c/h3-java/src/jniapi.c:19:
[INFO] /work/src/main/c/h3-java/src/com_uber_h3core_NativeMethods.h:2:10: fatal error: jni.h: No such file or directory
[INFO]     2 | #include <jni.h>
[INFO]       |          ^~~~~~~
[INFO] compilation terminated.
[INFO] make[3]: *** [CMakeFiles/h3-java.dir/build.make:76: CMakeFiles/h3-java.dir/src/jniapi.c.o] Error 1
[INFO] make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/h3-java.dir/all] Error 2
[INFO] make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/h3-java.dir/rule] Error 2
[INFO] make: *** [Makefile:124: h3-java] Error 2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:08 min
[INFO] Finished at: 2021-08-30T15:38:00+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1.1:exec (build-h3-c) on project h3: Result of /bin/sh -c cd /Users/muthmann/Development/h3-java && /Users/muthmann/Development/h3-java/src/main/c/h3-java/build-h3.sh https://github.com/uber/h3.git v3.7.2 true false execution is: '2'. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

It seems that the system tries to build H3 for Linux ARM64, which will obviously not work. Unfortunately my Make knowledge is not great enough to fix that issue.