h3-java icon indicating copy to clipboard operation
h3-java copied to clipboard

Android, can't use library

Open NickRadu opened this issue 5 years ago • 45 comments

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.

NickRadu avatar Aug 27 '18 12:08 NickRadu

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.

isaacbrodsky avatar Aug 27 '18 17:08 isaacbrodsky

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 avatar Aug 28 '18 06:08 NickRadu

@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 avatar Aug 28 '18 17:08 isaacbrodsky

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

NickRadu avatar Aug 29 '18 06:08 NickRadu

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.

isaacbrodsky avatar Sep 02 '18 23:09 isaacbrodsky

Hi Isaac,

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

Thank.

NickRadu avatar Sep 03 '18 07:09 NickRadu

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

isaacbrodsky avatar Oct 08 '18 20:10 isaacbrodsky

Hi Isaac, thanks for the fix.

NickRadu avatar Oct 10 '18 06:10 NickRadu

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?

yterletskyi avatar Oct 17 '18 13:10 yterletskyi

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 avatar Oct 18 '18 04:10 isaacbrodsky

where do I find libh3-java.so please?

yterletskyi avatar Oct 18 '18 06:10 yterletskyi

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

isaacbrodsky avatar Oct 19 '18 04:10 isaacbrodsky

any updates on this?

long1eu avatar Mar 08 '19 13:03 long1eu

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

long1eu avatar Mar 08 '19 14:03 long1eu

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

long1eu avatar Mar 08 '19 14:03 long1eu

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.

isaacbrodsky avatar Mar 08 '19 19:03 isaacbrodsky

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

MaGoOoDy avatar Apr 21 '19 17:04 MaGoOoDy

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?

isaacbrodsky avatar Apr 30 '19 00:04 isaacbrodsky

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 avatar May 11 '19 18:05 lkoelman

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

lkoelman avatar May 14 '19 16:05 lkoelman

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 ?

MaGoOoDy avatar May 17 '19 13:05 MaGoOoDy

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.

AmaroNeto avatar May 29 '19 13:05 AmaroNeto

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

alphanota avatar Jul 05 '19 21:07 alphanota

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 avatar Jul 15 '19 09:07 yelsane

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

tijanja avatar Jul 21 '19 17:07 tijanja

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

akexorcist avatar Feb 08 '21 09:02 akexorcist

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

ma-rp avatar Feb 23 '21 16:02 ma-rp

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 avatar Jun 29 '21 18:06 mrQuidome

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

alphanota avatar Jun 30 '21 20:06 alphanota

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?

mrQuidome avatar Jul 02 '21 18:07 mrQuidome