h3-java
h3-java copied to clipboard
Android, can't use library
How I can use this library in Android oS?
I got following exception: java.lang.UnsatisfiedLinkError: No native resource found at /android-armv7l/libh3-java.so at com.uber.h3core.H3CoreLoader.copyResource(H3CoreLoader.java:67) at com.uber.h3core.H3CoreLoader.loadNatives(H3CoreLoader.java:99) at com.uber.h3core.H3Core.newInstance(H3Core.java:68)
Thank you.
Hi, thanks for reporting this.
I believe this is an issue with how the library is trying to detect what architecture of native library to use. It tries to use what it got from the system property os.arch
, which was armv7l
, when the resource path expects arm
. For x86 we have a bunch of aliases in H3CoreLoader to handle this kind of situation.
We should add some aliases in H3CoreLoader to handle common architecture names on Android. We should probably also expose an API for the user to specify the OS/architecture to use in case the automatic detection doesn't get it right.
Hi Isaac and thanks for your response.
I see, but I don;t want to build the h3-Java library at least for now to add aliases in H3CoreLoader. After I unpacked my apk I noticed that there;s no android directory with h3 library, I can see only: darwin-x64, windows-x64, windows-x86 folders, it's ok?
Also I tried using newSystemInstance() method that loads library directly and I get another exception: "java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "lround" referenced by "/data/app/com.myapp-1/lib/arm/libh3-java.so".
Thanks.
@NickRadu that doesn't sound right - what version of h3-java are you using? Could you try 3.0.4? There should be a directory android-arm
which should have the library for armv7l.
@ isaacbrodsky I'm using already version 3.0.4. implementation 'com.uber:h3:3.0.4' Thanks.
I experimented with a test Android app, and was able to get it working with newSystemInstance
and modifying H3-Java a little.
I faced an issue like you mention where only the windows-x64 and windows-x86 native libraries are copied into the APK (I didn't get darwin-x64 copied.) Without repackaging H3-Java as an Android library, I was only able to work around that by using the jniLibs
feature (place the library at src/main/jniLibs/arm64-v8a/libh3-java.so
in my case.) I also added splits { abi { enable false } }
to the android
section of my app's build.gradle
.
Unfortunately this did not work as loading the library failed with an exception very similar to yours: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "tan" referenced by ...
. This looks like the library was unable to load libm. I changed the H3-Java build script to link to libm, using the same pattern as H3 in CMakeLists.txt
. This allowed me to load H3 into an Android app.
I'll update my PR with the change to link to libm, and a couple fixes for accessibility (especially of H3CoreLoader.) In the future, we might want to package an H3-Java specifically for Android, which might help with the need to copy the native library into your project.
Hi Isaac,
Great news, thank you for help. Do you have any ETA for this fix?
Thank.
Hi, the fix for libm should be included in the v3.1.0 of the H3-Java library.
Hi Isaac, thanks for the fix.
I'm using version 3.2.0 and still getting UnsatisfiedLinkError with couldn't find "libh3-java.so"
. Could you please help me to run it?
Hi, I think the missing part is the native library resource being copied into the Android application. I'll leave this issue reopened to track that.
Could you try the above steps of copying the native library files into the jniLibs
folder for your project (so they get included in the built APK)?
where do I find libh3-java.so
please?
@yterletskyi You can find the resource files android-arm/libh3-java.so
and android-arm64
/libh3-java.soinside the downloaded
h3-3.2.0.jar` file.
any updates on this?
I've added them to my
jniLibs
but still UnsatisfiedLinkError
This is how I call it.
Hi, I don't have an update on packaging the library for Android. Could you check if the files are copied to the APK? I needed to add specific build option (splits { abi { enable false } }
in android
in build.gradle
) to get the libraries packaged in.
i am still having the same issue :
java.lang.UnsatisfiedLinkError: No native resource found at /android-x86/libh3-java.so
i will post some photos
The cross compiling system we use (Dockcross) doesn't seem to offer an android-x86 option, so I assume we do not currently support that. Could you try running on ARM with the workaround posted above regarding copying the so
files and setting the splits ...
option?
I still get the error java.lang.UnsatisfiedLinkError: No native resource found at /android-arm64/libh3-java.so
running on ARM even when applying the listed fixes (manually copying .so files, adding the splits { ... }
option). I'm using Android studio 3.4 and Gradle 5.4
Solved by using H3Core.newSystemInstance()
instead of H3Core.newInstance()
The cross compiling system we use (Dockcross) doesn't seem to offer an android-x86 option, so I assume we do not currently support that. Could you try running on ARM with the workaround posted above regarding copying the
so
files and setting thesplits ...
option?
i have copied the whole library folder to jinLibs
folder and added the splits
option to my gradle file, but when i run the emulator it took to much time to install the app then an error should up Session 'app': Install failed. The device timed out while trying to install the application. Rerun
do i need to reference something in local.properties
file ?
do i need to load the library in the Activity ?
Hi everybody,
Some update? I'm trying use H3 in android and still show this error: java.lang.UnsatisfiedLinkError: No native resource found at /android-arm64/libh3-java.so
.
I'm already added android-arm64/libh3-java.so
in jniLib and didn't work.
I also came across this issue. I was able to manually load the *.so by adding the jniLibs
folder and adding splits {... }
to the build.gradle folder as suggested.
Then I set a breakpoint on line 67 in H3CoreLoader.java
if (resource == null) {
After starting the app in debug mode, the breakpoint is hit and the debug console appears. I had to set the resource
variable as:
H3CoreLoader.class.getClassLoader().getResourceAsStream("lib/android-arm64/libh3-java.so")
Where android-arm64/
is the folder that was copied and pasted from the jar into the jniLibs
folder
This is all on Android Studio
Hi everybody, Some update? I'm trying use H3 in android and still show this error:
java.lang.UnsatisfiedLinkError: No native resource found at /android-arm64/libh3-java.so
.I'm already added
android-arm64/libh3-java.so
in jniLib and didn't work.
Rename your android-arm64
to just arm64
.
I just managed to make the library work on my end myself. I added a StackOverflow answer here: Android h3: A Hexagonal Hierarchical Geospatial Indexing System
Here's a sample project
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/base.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_dependencies_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_resources_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_0_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_1_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_2_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_3_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_4_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_5_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_6_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_7_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_8_apk.apk", zip file "/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/buhari.teetech.com.dinkkydriver-j2qNhxNft14nXEBYMehitQ==/lib/arm64, /system/lib64]]] couldn't find "libh3-java.so"
I'm having the same problem has anybody got a solution to
armeabi, armeabi-v7a, arm64-v8a are ABIs supported in Android and this library doesn't support for x86 and x86_64
In your case, android-armv7l doesn't look like regular ABI for Android device
For regular Android device
Currently all android devices running on ARM (Except outdated device like Asus ZenPhone 5 and Chrome OS device). x86 and x86_64 are available in Android Emulator only.
So you can config your app to support ARM only in build.gradle
like this
android {
/* ... */
defaultConfig {
/* ... */
ndk {
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
}
}
}
I also faced this issue, @yelsane solution worked for me, thanks. It would be great if this library could be repackaged for Android
I am facing the same problem. Got it working but after a Android Studio update it failed to work for me. Is it possible to fix this without the need for a workaround. Would be very nice :)
@mrQuidome What are the minimum and target android API's in your project?
Started all over again and have it working (again). That's very nice. But, the problem was something different. It works when I run it on my device It does not work when I use the emulator. Somebody an idea?