Saturday, January 4, 2014

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 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) 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 set-up 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 were 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 build with the NDK. This can result in dependencies on function or libraries that don't exists 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, than 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 explicit path of native library while starting JVM e.g. java -Djava.library.path =" native library path "

If you are working in Linux than check if your native library path exists in LD_LIBRARY_PATH environment variable. You can see it's value 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 than you can also share with us by commenting.


No comments:

Post a Comment

Java67 Headline Animator