Closed yishais closed 4 years ago
We have the same issue - Native library (linux-x86-64/libsodium.so) not found in resource path
. I believe it is because of new library loading introduced in 4.1.0.
@gurpreet- could you please take a look at that?
Hi both, can you please use version 4.2.0
as version 4.1.0
had a missing dependency. Please see #55
@gurpreet- this issue applies to 4.2.0
as well (I'm using 4.2.0
).
How strange! Do you have a full stacktrace that I can see?
I added a new library to manage the handling of resource loading because resource loading is a surprisingly difficult task to do.
Sure!
java.lang.ExceptionInInitializerError
at com.exonum.binding.common.message.TransactionMessageBuilderTest.<clinit>(TransactionMessageBuilderTest.java:47)
Caused by: co.libly.resourceloader.ResourceLoaderException: Failed to load the library using sodium
at com.exonum.binding.common.message.TransactionMessageBuilderTest.<clinit>(TransactionMessageBuilderTest.java:47)
Caused by: java.lang.UnsatisfiedLinkError:
Unable to load library 'sodium':
libsodium.so: cannot open shared object file: No such file or directory
libsodium.so: cannot open shared object file: No such file or directory
Native library (linux-x86-64/libsodium.so) not found in resource path ([file:/home/.../target/surefire/surefirebooter5421832691743038575.jar])
As OP mentioned - it feels like library loader looks for the library in linux
/linux64
folders, while it is in linux-x86-64
folder.
How are you instantiating Lazysodium? What are the lines of code you are using?
LazySodiumJava ls = new LazySodiumJava(new SodiumJava());
?
Yes, lazySodium = new LazySodiumJava(new SodiumJava(Mode.PREFER_SYSTEM));
Seems to not affect anyone using bundled mode Mode.BUNDLED_ONLY
If you're using it in Mode.PREFER_SYSTEM
have you installed libsodium using your package manager? E.g sudo apt install libsodium-dev
?
Make sure to install Libsodium 1.0.18
or above.
Or you can provide an absolute path to your libsodium.so file: new SodiumJava("/path/to/libsodium.so")
I used new SodiumJava("/path/to/libsodium.so") as a workaround.
It might be that Mode.PREFER_SYSTEM does Mode.SYSTEM_ONLY?
Thank you @yishais so absolute paths worked but not loading from the system. How strange 🤔
Makarov, could you try System.loadLibrary("sodium")
before you instantiate lazysodium?
System.loadLibrary("sodium")
LazySodiumJava ls = new LazySodiumJava(new SodiumJava(Mode.PREFER_SYSTEM));
Maybe that might work 🤞
I believe Mode.PREFER_SYSTEM
doesn't switch to bundled version because of a new library loading introduced in 4.1.0
.
@gurpreet- please take a look https://github.com/terl/lazysodium-java/pull/57
Hi both,
Version 4.2.1
should fallback correctly now. Sorry for the inconvenience, and thank you for the PR it gave me a lot of inspiration.
Will test the new version asap, but the change looks good! Thanks.
Unfortunately it still doesn't work correctly :( Here's another PR - https://github.com/terl/lazysodium-java/pull/58
Thank you again @MakarovS!
This is a very annoying bug, I must admit. When I first created this library, I thought the hardest part would be programming it to make it easier for developers to use, but in fact, the hardest part is loading it out of the resources folder as Java and the JAR system make it so difficult! 🤕 I could have leveraged other libraries to load it for me but they were out of date and difficult to use with shared libraries (.so
, .dylib
and .dll
files).
I will create a new release ASAP.
@gurpreet- Thank you for maintaining this library and being so responsive :)
@MakarovS,
No problem, it has always been my wish that people use my work 🙂
Version 4.2.2
has your changes in. Thank you for your contributions.
I'm still seeing this on our Jenkins instance, works fine locally on OSx
Still getting this Native library (linux-x86-64/libsodium.so) not found in resource path
Appears to just be misleading logging, the actual error is happening somewhere else during loading
Do you have a full stacktrace @carbotaniuman? I'm having difficulty debugging this as it's very OS dependent. Time to fire up my VMs 🙂
One case is ResourceLoader#getFileFromFileSystem fails with spaces in the name. I'll get you more as I get them.
PS F:\BLAH> java -Dfile-level=trace -Dstdout-level=info -jar test.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\Arnold\AppData\Local\Temp\resource-loader15060737488612266253\windows64\libsodium.dll':
The specified module could not be found.
The specified module could not be found.
Native library (win32-x86-64/C:\Users\Arnold\AppData\Local\Temp\resource-loader15060737488612266253\windows64\libsodium.dll) not found in resource path (test.jar)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:302)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)
at com.sun.jna.Native.register(Native.java:1722)
at co.libly.resourceloader.SharedLibraryLoader.registerLibraryWithClasses(SharedLibraryLoader.java:74)
at co.libly.resourceloader.SharedLibraryLoader.load(SharedLibraryLoader.java:57)
at com.goterl.lazycode.lazysodium.utils.LibraryLoader.loadBundledLibrary(LibraryLoader.java:133)
at com.goterl.lazycode.lazysodium.utils.LibraryLoader.loadLibrary(LibraryLoader.java:94)
at com.goterl.lazycode.lazysodium.SodiumJava.<init>(SodiumJava.java:34)
at com.goterl.lazycode.lazysodium.SodiumJava.<init>(SodiumJava.java:23)
at mdnet.base.Main.main(Main.kt:94)
Suppressed: java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
... 9 more
Suppressed: java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:204)
... 9 more
Suppressed: java.io.IOException: Native library (win32-x86-64/C:\Users\Arnold\AppData\Local\Temp\resource-loader15060737488612266253\windows64\libsodium.dll) not found in resource path (test.jar)
at com.sun.jna.Native.extractFromResourcePath(Native.java:1095)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:276)
... 9 more
@carbotaniuman how do you initialise Lazysodium? Do you have some code you could share?
Looking at it closely why does your path start with win32-x86-64/C:\Users\....
? win32-x86-64/
is completely wrong at the start. If you just used C:\Users\Arnold\AppData\Local\Temp\resource-loader15060737488612266253\windows64\libsodium.dll
then it would work.
Are you supplying a path or doing anything extra?
No path, just 'LazySodiumJava lazySodium = new LazySodiumJava(new SodiumJava());'
This is not related to the space in path issue btw.
Could you try:
LazySodiumJava lazySodium = new LazySodiumJava(new SodiumJava(LibraryLoader.Mode.BUNDLED_ONLY));
LazySodiumJava lazySodium = new LazySodiumJava(new SodiumJava(LibraryLoader.Mode.SYSTEM_ONLY));
and post both results/stacktraces here?
I have just migrated to AzureCI to be able to test Lazysodium in an isolated Windows/Linux/MacOS environment. Previously it was on SemaphoreCI and Lazysodium was only being tested in a Linux environment. Now that it's being tested across different isolated platforms, we will be able to easily point out if it's a problem with the developer's machine or not, so tickets like this will be less of a likelihood.
Please keep raising tickets if you encounter a problem.
@carbotaniuman The tests are passing in an isolated Windows environment, therefore I suspect the issue is something to do with your system. This might help https://stackoverflow.com/questions/49596360/native-library-not-found-in-resource-path
It would seem that you have both 64-bit and 32-bit JRE's installed.
Please open a new ticket if the issue persists and you need more help.
Might be my misunderstanding... Upgraded from 4.01 to 4.10.
With 4.0.1 the jar will find and load the libsodion.so.
With 4.1.0 is does not. It looks like it looks for it in /lazysodium-java-4.1.0.jar/linux-x86-64/..., but there are only /lazysodium-java-4.1.0.jar/linux64 & /lazysodium-java-4.1.0.jar/linux.
"libsodium.so: cannot open shared object file: No such file or directory Native library (linux-x86-64/libsodium.so) not found in resource path"
4.0,1 & 4.1.0 tried on the same server with the exact same setting, so i suspect it is some setting in the jar.
-Yishai