java.lang.UnsatisfiedLinkError: Library not found tibrvnative or android

When I was working in JNI and using native code, actually an in-house library,  I realized that java.lang.UnsatisfiedLinkError: Library not found comes mainly due to two reasons

1) First reason, which happens in 90% scenarios is that the library which you are using directly or indirectly (some external JAR is using native library or native dll e.g. if your Java application is using TIBCO libraries for messaging or fault tolerance then tibrv.jar uses tibrvnative.dll library and throws java.lang.UnsatisfiedLinkError: Library not found tibrvnative if that library (the dll) is not in the path. In order to fix this problem, you need to update your PATH environment variable to include native libraries binary. see last section for more details.

2) The second reason which is bit rare is that the library might not have right kind of permissions e.g. placed under a home directory of a user, which is not accessible. This has only happened to me once when I copied another colleagues settings to setup my environment and forget to change the PATH of Tibco dll, which was local to him. This one is rather simple to fix but hard to find, all I need to do is given installation folder a read-write permission for a developer group. Alternatively, you can also copy that dll to your local home directory.

This was the case with core Java application running on Windows and Linux. In Android, there could be another reason of java.lang.UnsatisfiedLinkError, where the library wasn't built with the NDK. This can result in dependencies on function or libraries that don't exist on the device.

How to fix java.lang.UnsatisfiedLinkError: Library not found in Java

In order to fix this exception, just check if your PATH contains required native library or not. If PATH contains, then verify java.library.path system property, in case your application is using to find native libraries. If that doesn't work, try running your Java program by providing an explicit path of a native library while starting JVM e.g. java -Djava.library.path =" native library path "

If you are working in Linux then check if your native library path exists in LD_LIBRARY_PATH environment variable. You can see it's valued as ${LD_LIBRARY_PATH} and can further use grep command to check for your native library. That's all about this Java troubleshooting tips to fix java.lang.UnsatisfiedLinkError: Library not found. If you have already faced this issue and your solution differ than mine then you can also share with us by commenting.

Further Learning
Complete Java Masterclass
Java Fundamentals: The Java Language
Java In-Depth: Become a Complete Java Engineer!

No comments:

Post a Comment