Debugging java.lang.UnsatisfiedLinkError

1,480 views
Skip to first unread message

Tom Bova

unread,
Mar 9, 2009, 9:34:50 AM3/9/09
to andro...@googlegroups.com
Hi,

I'm working on a project that has a native library and a Java application that calls it via JNI.  I've used the sample code as a starting point and had my calls working fine. 

I've done some more development of the native library and now I am getting a java.lang.UnsatisfiedLinkError error when I launch my Java app and its tries to load the JNI library.

Here is what I see in logcat:

D/dalvikvm(  717): Trying to load lib /system/lib/libXYZ_interaction_library_jni.so 0x4370a788
I/dalvikvm(  717): Unable to dlopen(/system/lib/libXYZ_interaction_library_jni.so): Cannot find library
E/JNI     (  717): WARNING: Could not load XYZ_interaction_library_jni.soLibrary XYZ_interaction_library_jni not found
W/System.err(  717): java.lang.UnsatisfiedLinkError: Library XYZ_interaction_library_jni not found
W/System.err(  717):     at java.lang.Runtime.loadLibrary(Runtime.java:489)
W/System.err(  717):     at java.lang.System.loadLibrary(System.java:557)

I wonder if there is an unresolved symbol in the  libXYZ_interaction_library_jni.so instead of an actual problem loading the library.
The library is in /system/lib and its permissions are 777.

Does anyone have a suggestion on how to debug this problem?   I'm testing on both a emulator and a G1 phone.  I see the problem in both places.

Thanks,
Tom


JayBird

unread,
Mar 9, 2009, 11:00:20 AM3/9/09
to android-ndk
Hi Tom,

I'm guessing that when you built you shared library, you forgot to
include all the shared library dependencies. All the shared
libraries you need to link against should be list in the
LOCAL_SHARED_LIBRARIES variable. e.g.

LOCAL_SHARED_LIBRARIES:= \
libz \
libutils

I hope this helps.

Cheers,
Jay

Tom Bova

unread,
Mar 9, 2009, 2:51:44 PM3/9/09
to andro...@googlegroups.com
Jay,

Thanks for the suggestion, but that didn't solve my problem. 

- Tom

Mattaku Betsujin

unread,
Mar 9, 2009, 3:49:46 PM3/9/09
to andro...@googlegroups.com
Try to use strace to find out what's happening. You can do this by putting a sleep in your test app (just before System.loadLibrary()). Then, use strace -p $pid to attach to the process.

strace is available at /system/xbin/strace on the emulator.

This happened to be before. libXYZ_interaction_library_jni.so is there, but it depends on another shared library foobar.so, which is not there. From strace, it tells me that foobar.so is not found.

The error message in the linux dynamic loader is definitely misleading here ....

fadden

unread,
Mar 9, 2009, 7:47:03 PM3/9/09
to android-ndk
On Mar 9, 12:49 pm, Mattaku Betsujin <mattaku.betsu...@gmail.com>
wrote:
> The error message in the linux dynamic loader is definitely misleading here

The Android dynamic loader has just the one error message for all
occasions.

From dalvik/vm/Native.c:

* The current android-arm dynamic linker implementation tends to
* return "Cannot find library" from dlerror() regardless of the
actual
* problem. A more useful diagnostic may be sent to stdout/
stderr,
* but often that's not visible. Some things to try:
* - make sure the library exists on the device
* - verify that the right path is being opened (the debug log
message
* above can help with that)
* - check to see if the library is valid
* - check config/prelink-linux-arm.map to ensure that the
library
* is listed and is not being overrun by the previous entry
(if
* loading suddenly stops working, this is a good one to
check)

These are a little old and framework-centric; in fact, it no longer
prints diagnostics anywhere, and the prelink map only matters if your
library is prelinked.

Debugging the failure to load a shared library is easiest if you
rebuild ld.so with debugging enabled and then run a trivial program
that calls dlopen() on the target library. (Whether or not this
qualifies as "easy" depends on your setup.) See bionic/linker/
linker_debug.h.

Using strace is a good idea.

Tom Bova

unread,
Mar 10, 2009, 5:12:43 PM3/10/09
to andro...@googlegroups.com
I added the sleep to Java app before System.loadLibrary() and  saw these errors in the strace output:

write(1, "bionic/linker/linker.c:623| ERROR: OOPS:    32 prelinked library \'libwebcore.so\' mapped at 0x449f4000, not at 0xaa000000\n", 121) = 121
munmap(0x449f4000, 5750784)             = 0
close(26)                               = 0
write(1, "bionic/linker/linker.c:1519| ERROR:    32 could not load \'libwebcore.so\'\n", 73) = 73
write(1, "bionic/linker/linker.c:1579| ERROR: failed to link /system/lib/libXYZ_interaction_library_jni.so\n", 106) = 106
munmap(0x80300000, 16384)               = 0
writev(3, [{"\4", 1}, {"dalvikvm\0", 9}, {"Unable to dlopen(/system/lib/libXYZ_interaction_library_jni.so): Cannot find library\n\0", 95}], 3) = 105

I did modify the Android.mk of libwebcore.so to remove the -fvisibility=hidden flag so that I could call some functions inside the Javascript code.  This must be the cause of my troubles.

I rebuilt the libwebcore.so file with LOCAL_PRELINK_MODULE set to  false and I am now able to load my JNI library from my app.
 
Thanks,
Tom
--
Xtone Networks
P 703.318.1679
C 703.203.0382
www.xtone.com
___________________________________________
The information transmitted herewith is sensitive and confidential information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender by reply email and destroy all copies of the original message and attached materials from your computer.


Reply all
Reply to author
Forward
0 new messages