Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android, can't use library #23

Open
NickRadu opened this issue Aug 27, 2018 · 46 comments
Open

Android, can't use library #23

NickRadu opened this issue Aug 27, 2018 · 46 comments

Comments

@NickRadu
Copy link

NickRadu commented Aug 27, 2018

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.

@isaacbrodsky
Copy link
Collaborator

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.

@NickRadu
Copy link
Author

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.

@isaacbrodsky
Copy link
Collaborator

@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.

@NickRadu
Copy link
Author

NickRadu commented Aug 29, 2018

@ isaacbrodsky I'm using already version 3.0.4.
implementation 'com.uber:h3:3.0.4'
Thanks.

@isaacbrodsky
Copy link
Collaborator

isaacbrodsky commented Sep 2, 2018

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.

@NickRadu
Copy link
Author

NickRadu commented Sep 3, 2018

Hi Isaac,

Great news, thank you for help. Do you have any ETA for this fix?

Thank.

@isaacbrodsky
Copy link
Collaborator

Hi, the fix for libm should be included in the v3.1.0 of the H3-Java library.

@NickRadu
Copy link
Author

Hi Isaac, thanks for the fix.

@yterletskyi
Copy link

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?

@isaacbrodsky
Copy link
Collaborator

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)?

@isaacbrodsky isaacbrodsky reopened this Oct 18, 2018
@yterletskyi
Copy link

where do I find libh3-java.so please?

@isaacbrodsky
Copy link
Collaborator

@yterletskyi You can find the resource files android-arm/libh3-java.so and android-arm64/libh3-java.soinside the downloadedh3-3.2.0.jar` file.

@long1eu
Copy link

long1eu commented Mar 8, 2019

any updates on this?

@long1eu
Copy link

long1eu commented Mar 8, 2019

screen shot 2019-03-08 at 16 17 08
I've added them to my jniLibs but still UnsatisfiedLinkError

@long1eu
Copy link

long1eu commented Mar 8, 2019

screen shot 2019-03-08 at 16 18 36
This is how I call it.

@isaacbrodsky
Copy link
Collaborator

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.

@MaGoOoDy
Copy link

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
1
2
3

@isaacbrodsky
Copy link
Collaborator

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?

@lkoelman
Copy link

lkoelman commented May 11, 2019

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

@lkoelman
Copy link

Solved by using H3Core.newSystemInstance() instead of H3Core.newInstance()

@MaGoOoDy
Copy link

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 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 ?

@AmaroNeto
Copy link

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.

@alphanota
Copy link

alphanota commented Jul 5, 2019

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
debug_h3coreloader

@yelsane
Copy link

yelsane commented Jul 15, 2019

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

@tijanja
Copy link

tijanja commented Jul 21, 2019

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

@akexorcist
Copy link

akexorcist commented Feb 8, 2021

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"
        }
    }
}

@ma-rp
Copy link

ma-rp commented Feb 23, 2021

I also faced this issue, @yelsane solution worked for me, thanks.
It would be great if this library could be repackaged for Android

@mrQuidome
Copy link

mrQuidome commented Jun 29, 2021

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 :)

@alphanota
Copy link

@mrQuidome What are the minimum and target android API's in your project?

@mrQuidome
Copy link

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?

@alphanota
Copy link

@mrQuidome What architecture is your emulator using? When I had issues it was because the libh3.so didn't match the architecture of my emulator. If you're using the JNIlibs/libh3-java.so approach one thing you could do is make sure you have a libh3.so copy that is built for your emulator architecture (x86,arm,arm64, etc)

@mrQuidome
Copy link

@mrQuidome What architecture is your emulator using? When I had issues it was because the libh3.so didn't match the architecture of my emulator. If you're using the JNIlibs/libh3-java.so approach one thing you could do is make sure you have a libh3.so copy that is built for your emulator architecture (x86,arm,arm64, etc)

Thank you for your reply :)
I have put all the *.so files into their respective directories under JniLibs. Still no luck with the emulator. I am using Nexus 6, API 30 as my emulated phone.

@ben-ying
Copy link

ben-ying commented Nov 2, 2021

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

@yelsane did you change so files? It does work if using your so files in your demo project. But when I used so files in h3-3.7.1.jar or h3-3.4.1.jar it didn't work.
I can see you used the 3.4.1 library but your so file sha1 is different from so in h3-3.4.1.jar.

H3Core.newInstance() throws error: java.lang.UnsatisfiedLinkError: dlopen failed: library "libh3-java.so" not found.
H3Core.newSystemInstance() throws error: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "lroundl" referenced by "/data/app/~~BreO23DLqqHC0NYue8lizA==/place.hexagon-LcpT7zLBDPKCQa0h5Qw1og==/base.apk!/lib/arm64-v8a/libh3-java.so"...

@ben-ying
Copy link

ben-ying commented Nov 2, 2021

I'm using 3.6.2 and it's working.

@yelsane
Copy link

yelsane commented Nov 4, 2021

@yelsane did you change so files? It does work if using your so files in your demo project. But when I used so files in h3-3.7.1.jar or h3-3.4.1.jar it didn't work. I can see you used the 3.4.1 library but your so file sha1 is different from so in h3-3.4.1.jar.

H3Core.newInstance() throws error: java.lang.UnsatisfiedLinkError: dlopen failed: library "libh3-java.so" not found. H3Core.newSystemInstance() throws error: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "lroundl" referenced by "/data/app/~~BreO23DLqqHC0NYue8lizA==/place.hexagon-LcpT7zLBDPKCQa0h5Qw1og==/base.apk!/lib/arm64-v8a/libh3-java.so"...

@ben-ying it's been a while since I touched this lib, but with regard to the h3 files, I didn't change anything. I just used them as is.

@bkhall
Copy link

bkhall commented Jan 7, 2022

Using library 3.7.1...

I can confirm that copying the library android jni files to the analogous android project jniLibs folders and using the newSystemInstance() call works, mostly - until we encounter a 64-bit android device. On those devices, I can further confirm that the library fails to load with aforementioned, cannot locate symbol "lroundl", error.

Update:
I also get this same error when trying to run in the emulator on a 64-bit windows machine.

@bareq
Copy link

bareq commented Feb 8, 2022

v 3.7.2
For me worked:
Screen Shot 2022-02-08 at 11 05 19 AM
arm64-v8a/libh3-java.so copied from extracted lib jar android-arm64 folder
armeabi-v7a/libh3-java.so copied from extracted lib jar android-arm folder

Initialize lib with
H3Core.newSystemInstance()

@woodii
Copy link

woodii commented Apr 11, 2022

I am facing the same issue when using this lib (3.7.2) in my project.
Using the above workaround with copying the *.so files into the jniLibs folder does not work for the current version.

I am still get the following error:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "lroundl" referenced by "/data/app/~~cEniqwudw1DOL3oqPc5FzQ==/at.***.***-7KGgzWNftH-hbpzNs6zYcA==/base.apk!/lib/arm64-v8a/libh3-java.so"...

using older *.so files from e.g. @yelsane 's sample project works somehow.

@bareq
Copy link

bareq commented Apr 11, 2022

Ok... It worked for me because I was using H3 together with Mapbox SDK. It forces using libc++_shared.so in app. This native library contains lroundl function which is missing in libh3-java.so. I can't find a way to use h3 lib without mapbox sdk for now. Does someone know how to include that C++ support to the app?

@woodii
Copy link

woodii commented Apr 12, 2022

Something is weird about this lib in android apps. It packages *.dlls and *.dylibs but no *.so files.
Then tries to load the missing files from android- prefixed directories which is imo not common.
And furthermore its missing functions.
In my case i would have libc++_shared.so in the correct folders aswell but its not using them when it cant find it in the libh3-java.so files.

@gdogaru
Copy link

gdogaru commented May 25, 2023

Any plans to support Android in the future? I could not get v4 nor v3 to work with the latest Android development libraries, tried all suggestions above.

@Firsto
Copy link

Firsto commented Sep 26, 2023

same here, any alternatives?

@Firsto
Copy link

Firsto commented Sep 27, 2023

That's it, I hucked the system, awesome workaround, just great.
I took .so lib for arm, stupidly renamed it to .dll and load it into H3CoreLoader as windows_x64 (otherwise I couldn't throw the path to the file, classloader gave null when opening the resource), on emulators 9 and 11 android under x86 this trick works. 😂

!!! Use only for debugging, not in prod!

image

image


image This is original libh3-java.so file from library's \arm64\ folder, lol. 😂

@Firsto
Copy link

Firsto commented Sep 27, 2023

add to app build.gradle
debug { ndk { abiFilters "armeabi" } }

Works fine with x86 emulator API30.

@simonvar
Copy link

Hello!
Any updates on android?

@isaacbrodsky
Copy link
Collaborator

I've created a sample application for demonstrating how to use h3-java on Android: https://github.com/isaacbrodsky/h3-android-sample It is still a bit hacky, and requires some odd steps like manually copying the library files into the project. I'm hoping this will be helpful for those looking to use h3-java and for testing the library.

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

No branches or pull requests