phxql / argon2-jvm

Argon2 Binding for the JVM
GNU Lesser General Public License v3.0
330 stars 32 forks source link

UnsatisfiedLinkError: Native library (com/sun/jna/android-aarch64/libjnidispatch.so) not found in resource path #65

Closed tuancoltech closed 4 years ago

tuancoltech commented 4 years ago

Hi there, So as the title says, we are having this crash when running our app (which implements your library) in 64 bit device. To be specific, it's running arm64-v8a architecture. Below is the crash stack trace:

java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-aarch64/libjnidispatch.so) not found in resource path (.) at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:962) at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922) at com.sun.jna.Native.<clinit>(Native.java:190) at com.sun.jna.NativeLong.<clinit>(NativeLong.java:35) at de.mkammerer.argon2.Argon2Factory$Argon2Types.<init>(Argon2Factory.java:137) at de.mkammerer.argon2.Argon2Factory$Argon2Types.<clinit>(Argon2Factory.java:119)

Is this an issue from your lib, or if we are mis-using it, kindly give us a guideline.

Thanks.

phxql commented 4 years ago

The problem is that the bundled native libraries inside argon2-jvm don't support arm64-v8a.

You either have to compile the Argon2 lib for the architecture yourself or install one via your package manager.

tuancoltech commented 4 years ago

The problem is that the bundled native libraries inside argon2-jvm don't support arm64-v8a.

You either have to compile the Argon2 lib for the architecture yourself or install one via your package manager.

Thanks for your quick response @phxql . I haven't got what you mean yet by install one via your package manager. Could you make it more clear?

By the way, the libjnidispatch.so library seems to be built from net.java.dev.jna:jna package, which is just being imported into your library. Hence, I guess the architecture re-build should be done from that package. Am I correct?

phxql commented 4 years ago

Ah, you're right. Apparently JNA uses a C library to do the native calling. If JNA has no support of arm64-v8a, I'm not sure if this works at all.

phxql commented 4 years ago

I don't have Android expertise, but it looks like JNA doesn't ship the android native library for JNA (libjnidispatch.so) by default. Maybe this will help? https://stackoverflow.com/questions/47800043/android-arm-libjnidispatch-so-not-found-error

tuancoltech commented 4 years ago

Hi @phxql , thank you for the suggested reference link. Yeah that does help us. We actually checked the jna's binaries, tried extracting .so from their jar before, but with a wrong one (which was supposed for linux arch).

Now by extracting from their jars with android- prefix, it's working perfectly. Thanks again for your support.

phxql commented 4 years ago

That's really interesting. Is this running on an Android ARM64 phone? Did you compile the Argon2 C Library yourself or did it just work out of the box?

tuancoltech commented 4 years ago

Hi @phxql , yes we are supporting 64 bit powered Android devices (including both arm-based and x86-based ones). Just tested in arm64-v8a and it works now. The libs are actually newly supported by the jna team. I just got from their released binaries, so we don't need to compile the lib ourselves.

phxql commented 4 years ago

There are two libs in play here:

I would have thought that after fixing the problem with libjnidispatch.so, you would run into trouble with the missing libargon2.so (because Argon2-JVM doesn't contain binaries for Android ARM 64). That's why I'm surprised.