System.loadLibrary loads something else - java

In my java code, I call System.loadLibrary(A); to load the A.so library. However, my app crashes at run time with this error:
java.lang.UnsatisfiedLinkError: dlopen failed: library "B.so" not found
Admittedly, the B.so library is a dependency of A.so library. But I did not explicitly call System.loadLibrary() on B.so anywhere. I was under the impression that B.so will be covered by A.so. Why is the Java runtime trying to load B.so?
Thanks!

Related

Native error when trying to implement libwebp

I seemed to be getting a
JNI- java.lang.UnsatisfiedLinkError: Native error: method not found
when I try to implement libwebp into my project. I followed this link.
and it first gave me an error that it couldn't find the lib "webp". Then I used System.loadLibrary("MYPROJECT"); and it fixed the error, but generated another one saying
Native error: method not found
Every function from libwebp and libwebpJNI are generating the error, so it may have something to do with the native C code.
Any help?

java Opencv unsatisfiedLinkError, native Library is loaded

I am trying to run some program on opencv, but I am getting this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0(Ljava/lang/String;)J
I have already loaded the library, libopencv_java310.so by using this code:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
I have also added the path to the native library.
I have searched a lot on the internet, but the only reason this error comes, is due to native library is not loaded. What could be the other reason of getting this error.
Can anyone help....! Any help will be appreciated.
you might move your System.loadLibrary(Core.NATIVE_LIBRARY_NAME); to a static block so the dll gets loaded before any instruction of opencv .

jna : Could not find JNA native support

I am using this tutorial to use C in android, but I have an error at this line:
CTest ctest = (CTest) Native.loadLibrary("ctest", CTest.class);
This is the error:
Caused by: java.lang.UnsatisfiedLinkError: Could not find JNA native
support
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:754)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:736)
at com.sun.jna.Native.(Native.java:131)
... 15 more
I put libctest.so in libs folder.
What's the problem?
JNA is trying to load libjnidispatch.o and cannot find it. If not found on the system, JNA attempts to unpack the appropriate library from jna.jar, which is apparently not in your classpath.
EDIT
In the case of android, you have to bundle libjnidispatch.o with your application explicitly. Android will not allow JNA to unpack and load the native library on its own.
See also this answer.

Mac + jni + java

A little background:
I have a java application that needs to talk to a third party hardware on mac. They have given me the sdk but it is not in Java. So I am trying to make jnilib that will act as a bridge between my java application and the SDK.
The issue:
I have made a small sample jnilib that talks to the SDK but when I try to use it in my java program I get the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/john.doe/Desktop/eclipse/workspace/Lesson13_Jni_Smart7/bin/libSmartTest7.jnilib: Library not loaded: build/Release/SMARTResponseSDK.framework/Versions/A/SMARTResponseSDK Referenced from: /Users/john.doe/Desktop/eclipse/workspace/Lesson13_Jni_Smart7/bin/libSmartTest7.jnilib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1742)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at com.learning.lesson13.JniSmart7.<clinit>(JniSmart7.java:6)
From the error it looks like my libSmartTest7.jnilib is looking for the library SMARTResponseSDK.
What I have tried
I know where the library SMARTResponseSDK is on my Mac. I tried copying it over to my working folder in eclipse but I still get the error. I have tried using the -DJava.library.path but I still get the error.
Any ideas on what the best possible approach would be.
Once you are inside JNI code, it no longer matters what java.library.path points at.
Once you are inside JNI code, all you can do is to make sure library is visible to your code via LD_LIBRARY_PATH/DYLD_LIBRARY_PATH, or you can dynamically load your library file from any location you like.
So, for you, I suggest to take a look here:
dynamic loading of library in JNI - http://jnicookbook.owsiak.org/recipe-No-018/
Calling code from shared library (adapter pattern) - http://jnicookbook.owsiak.org/recipe-No-023/
You can also benefit from compilation flags while building your JNI library and use rpath.

What is the cause of an UnsatisfiedLinkError?

When i am trying to run my program it is giving the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob-1.14.3-x86 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at com.jacob.com.LibraryLoader.loadJacobLibrary(LibraryLoader.java:184)
at com.jacob.com.JacobObject.<clinit>(JacobObject.java:108)
at javaSMSTest.main(javaSMSTest.java:18)
please help
From the Javadoc:
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
It is an error related to JNI. loadJacobLibrary is trying to load the native library called jacob-1.14.3-x86 and it is not found on the path defined by java.library.path. This path should be defined as a system property when you start the JVM. e.g.
-Djava.library.path=<dir where jacob library is>
On Windows, the actual native library file will be called jacob-1.14.3-x86.dll while on Linux it would be called libjacob-1.14.3-x86.so
You need the jacob-1.14.3-x86 library on your java library path.
On windows, this would be jacob-1.14.3-x86.dll.
This is a binary file which is used by java to run native methods. It's probably required by some library (jar) you're using.
In here you can see not only a jar, but also the binary required by the jar. Pick the one for your platform.
To quote http://www.velocityreviews.com/forums/t143642-jni-unsatisfied-link-error-but-the-method-name-is-correct.html:
There are two things that cause UnsatisfiedLinkError. One is when
System.loadLibrary() fails to load the library, the other is when the
JVM fails to find a specific method in the library. The text of the
error message itself will indicate which is the case...
The error which you describe clearly cannot find the library at all. As the others have said, include it in your Java library path.
The other error—when the library can be found but the method within the library is not found—looks as follows:
java.lang.UnsatisfiedLinkError: myObject.method([Ljava/lang/Object;)V
In this case you either have the wrong method name, or will have to go back and add the method and recompile the code...

Categories

Resources