UnsatisfiedLinkError: Library myLibrary not found

2,033 views
Skip to first unread message

Guian

unread,
Nov 22, 2010, 11:50:55 AM11/22/10
to android-ndk
Hi all !

I've got this error at runtime on System.loadlib("myLibrary");

I build my library usin the ndk-build script -> no error at compil
time

the libmyLibrary.so is generated and well packaged :
placed in <my project>/libs/armeabi in eclipse
and in
data/data/myPackageName/libs on the phone after the app is
installed...

I've tried to get some trace with this method :

http://groups.google.com/group/android-ndk/browse_thread/thread/44281d6d9fa47489/9be9f800688b4c1b?lnk=gst&q=UnsatisfiedLinkError+how+to+debug#9be9f800688b4c1b

but the strace command just got me a "permission denied" :/

I'm loosing hope... can anyone help me ?

Guian

unread,
Nov 22, 2010, 12:30:46 PM11/22/10
to android-ndk
update :

it seems like someother lib need to be load before :

I added :
System.loadLibrary("aDynamicLib"); // this one works fine, I
guess I've got libaDynamicLib.so loaded...
System.loadLibrary("anotherLib"); // this one makes the app crash
with the same error as above... I've got libanotherLib.a
System.loadLibrary("myLibrary"); //I've got libmyLibrary.so

Do I need to load the static libs the same way ? (.a)
any help on this ?




On 22 nov, 17:50, Guian <guiandou...@gmail.com> wrote:
> Hi all !
>
> I've got this error at runtime on System.loadlib("myLibrary");
>
> I build my library usin the ndk-build script -> no error at compil
> time
>
> the libmyLibrary.so is generated and well packaged :
> placed in  <my project>/libs/armeabi in eclipse
> and  in
> data/data/myPackageName/libs on the phone after the app is
> installed...
>
> I've tried to get some trace with this method :
>
> http://groups.google.com/group/android-ndk/browse_thread/thread/44281...

fadden

unread,
Nov 22, 2010, 12:30:56 PM11/22/10
to android-ndk
On Nov 22, 8:50 am, Guian <guiandou...@gmail.com> wrote:
> I've got this error at runtime on System.loadlib("myLibrary");

Check the output of "logcat". It may have helpful details.

Igor R

unread,
Nov 22, 2010, 12:42:37 PM11/22/10
to andro...@googlegroups.com
> I added :
>        System.loadLibrary("aDynamicLib"); // this one works fine,  I guess I've got libaDynamicLib.so loaded...
>        System.loadLibrary("anotherLib"); // this one makes the app crash with the same error as above...   I've got libanotherLib.a

Static lib cannot be loaded, it's not an executable module.

Guian

unread,
Nov 23, 2010, 3:34:11 AM11/23/10
to android-ndk
Thank you for your answers

I removed the static libs ("*.a") from the java Sytem loading (I
guess those are include at compile time).

here is my logcat output, does it say something I didn't see ?


11-23 09:29:13.643: ERROR/AndroidRuntime(5905): FATAL EXCEPTION: main
11-23 09:29:13.643: ERROR/AndroidRuntime(5905):
java.lang.ExceptionInInitializerError
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
com.myPackage.packageName.activityName.onCreate(activityName.java:36)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1066)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2797)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2854)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.app.ActivityThread.access$2300(ActivityThread.java:136)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.os.Handler.dispatchMessage(Handler.java:99)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.os.Looper.loop(Looper.java:143)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
android.app.ActivityThread.main(ActivityThread.java:5068)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
java.lang.reflect.Method.invokeNative(Native Method)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
java.lang.reflect.Method.invoke(Method.java:521)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
dalvik.system.NativeStart.main(Native Method)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): Caused by:
java.lang.UnsatisfiedLinkError: Library myLibrary not found
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
java.lang.Runtime.loadLibrary(Runtime.java:461)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
java.lang.System.loadLibrary(System.java:557)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): at
com.myPackage.anOtherPackage.myJNIInterfaceClass.<clinit>(myJNIInterface.java:
42)
11-23 09:29:13.643: ERROR/AndroidRuntime(5905): ... 14 more

Guian

unread,
Nov 23, 2010, 3:48:37 AM11/23/10
to android-ndk

Can it be relative to my Android.mk file ?
I wrote it quite approximatively, I'm note very confidente with it...

android.mk :

CURRENT_PATH := $(call my-dir)
LOCAL_PATH := $(call my-dir)

include $(CURRENT_PATH)/../external/myDynamicLib/Android.mk





include $(CLEAR_VARS)


LOCAL_MODULE := myLibrary
LOCAL_STATIC_LIBRARIES := myDynamicLib


LOCAL_CFLAGS :=-Wl,--no-undefined

LOCAL_SRC_FILES := someOtherSrc.cpp newSrc.cpp
andAgainOtherSrcFile.cpp
LOCAL_SRC_FILES += myLibrary.cpp
LOCAL_C_INCLUDES := $(CURRENT_PATH)/includes/LibsHeaders/


LOCAL_LDLIBS := $(CURRENT_PATH)/../obj/local/armeabi/myStaticLib.a $
(CURRENT_PATH)/../obj/local/armeabi/myDynamicLib.so

LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -ldl -llog


include $(BUILD_SHARED_LIBRARY)

Guian

unread,
Nov 23, 2010, 4:11:55 AM11/23/10
to android-ndk
I 've got another lib compiled using codesourcery (gcc cross compiler
for arm) included in android.mk as a LOCAL_LDLIBS.
Could it cause any problem ?



On 23 nov, 09:34, Guian <guiandou...@gmail.com> wrote:

Guian

unread,
Nov 23, 2010, 4:55:42 AM11/23/10
to android-ndk
update :


if I comment the other src file in android.mk : ( those cpp files are
those using imported libs )
and of course I comment also the code using them in myLibrary.cpp

#LOCAL_SRC_FILES := someOtherSrc.cpp newSrc.cpp...
LOCAL_SRC_FILES += myLibrary.cpp

the error doesn't occur anymore ...
can someone explain this to me ?

Igor R

unread,
Nov 23, 2010, 5:21:13 AM11/23/10
to andro...@googlegroups.com
> if I comment the other src file in android.mk :  ( those cpp files are
> those using imported libs )
> and of course I comment also the code using them in myLibrary.cpp
>
> #LOCAL_SRC_FILES := someOtherSrc.cpp newSrc.cpp...
> LOCAL_SRC_FILES += myLibrary.cpp
>
> the error doesn't occur anymore ...
> can someone explain this to me ?

If your shared library depends on another shared library, you should
load that library first.

Guian

unread,
Nov 23, 2010, 5:35:45 AM11/23/10
to android-ndk
yes, I do that ...

and it depend also on a static lib.

> if I comment the other src file in android.mk : ( those cpp files are
> those using imported libs )
> and of course I comment also the code using them in myLibrary.cpp

> #LOCAL_SRC_FILES := someOtherSrc.cpp newSrc.cpp...
> LOCAL_SRC_FILES += myLibrary.cpp

> the error doesn't occur anymore ...
> can someone explain this to me ?

I've got this answer : if I remove .cpp files that use my static
library, that last one isn't included in my final shared library and
no error occurs.
whereas if I compile those cpp file => the static libs are included in
my shared lib and the unsatisfied link error occur :'(

do I need to add my .a file in a particular place in order to use
them ?

Igor R

unread,
Nov 23, 2010, 5:50:12 AM11/23/10
to andro...@googlegroups.com
> and it depend also on a static lib.

It cannot "depend" on static libs - static libs are just linked into
the shared lib. If the link process succeeded, the static lib was
successfully linked in.

Guian

unread,
Nov 23, 2010, 8:36:54 AM11/23/10
to android-ndk

allright, the fact is the link process succeeded at compile time so
that's good.
I don't have to load static lib

but why my shared library is still not foud ... ?

is ther a limit size for native lib loaded in our application
package for java code ?

Guian

unread,
Nov 23, 2010, 9:52:03 AM11/23/10
to android-ndk

by the way, I'm using the Dmitry Moskalchuk's 'crystax' rebuilt of
android ndk since I needed stl support...

http://groups.google.com/group/android-ndk/browse_thread/thread/d78d1304eea42825/469021ffb66c3101?lnk=gst&q=crystax+stl#469021ffb66c3101
See http://www.crystax.net/androidndk.php for details.

duno if that can helps ....

Guian

unread,
Nov 23, 2010, 11:18:49 AM11/23/10
to android-ndk

new data :
do you remember I'm loading libmyLibrary.so and
libanOtherNeededLib.so
using :

System.loadlib("anOtherNeededLib");
System.loadlib("myLibrary");

the first works fine and the second makes the app crash.

When I use this command line in adb shell :
ls -l data/data/com.aquafadas.AFAdobeReader/lib

I can see the libmyLibrary.so but NOT the other one.

is that normal ?
and if it's normal ... can you explain it ?

thanks for any help.

On 23 nov, 15:52, Guian <guiandou...@gmail.com> wrote:
> by the way, I'm using the Dmitry Moskalchuk's  'crystax' rebuilt of
> android ndk since I needed stl support...
>
> http://groups.google.com/group/android-ndk/browse_thread/thread/d78d1...
> Seehttp://www.crystax.net/androidndk.phpfor details.

David Turner

unread,
Nov 23, 2010, 11:24:32 AM11/23/10
to andro...@googlegroups.com
Do you happen to use the same name than a system library? i.e. those under /system/lib/

In that case, your call would load the system library (instead of the missing anOtherNeededLib), then your myLibrary would fail to link because it doesn't find the right symbols it needs in the system library.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


fadden

unread,
Nov 23, 2010, 1:28:12 PM11/23/10
to android-ndk
On Nov 23, 12:34 am, Guian <guiandou...@gmail.com> wrote:
> here is my logcat output, does it say something I didn't see ?
>
> 11-23 09:29:13.643: ERROR/AndroidRuntime(5905): FATAL EXCEPTION: main
> 11-23 09:29:13.643: ERROR/AndroidRuntime(5905):
> java.lang.ExceptionInInitializerError

Any diagnostics from dlopen() will be printed when they are first
encountered, which will happen before the exception is thrown. Such
diagnostics, if present, will be above this point.

Guian

unread,
Nov 24, 2010, 3:56:36 AM11/24/10
to android-ndk

You are both right !

here is the logcat output right before the exception :
( I should have seen it before X( sorry )

11-24 09:47:39.995: DEBUG/dalvikvm(27508): No JNI_OnLoad found in /
system/lib/libssl.so 0x476c5138, skipping init
11-24 09:47:39.995: DEBUG/dalvikvm(27508): No JNI_OnLoad found in /
system/lib/libcrypto.so 0x476c5138, skipping init
11-24 09:47:40.005: DEBUG/dalvikvm(27508): Trying to load lib /data/
data/com.myCompanyName.myActivity/lib/libmyLibrary.so 0x476c5138
11-24 09:47:40.085: INFO/dalvikvm(27508): Unable to dlopen(/data/data/
com.myCompanyName.myActivity/lib/libmyLibrary.so): Cannot load
library: link_image[1995]: failed to link libmyLibrary.so

and that says it's looking for needed library in /system/lib/
(libssl and libcrypto alredy exists in system libs, can we use it as
it is from /system/lib ? )

Now I understand my mistake, I really thank you guys !

Guian

unread,
Nov 24, 2010, 4:18:30 AM11/24/10
to android-ndk
regarding libssl.so and libcrypto.so

I've read about libexpat.so from /system/lib

"It is not officially exposed, so you will have to include your own
copy in your application. " - David Turner -


is it still true and also true for libssl and libcrypot ?
in that case I'll need t find out how to include them without been in
conflict with the system's ones...

thank you again ! :)

Guian

unread,
Nov 24, 2010, 4:54:49 AM11/24/10
to android-ndk
it works fine now,

I've compiled my libssl and libcrypto as static libraries and include
them in myLibrary.so

this last .so seem successfully loaded by System.loadLibrary()
without any problem.

:)

David Turner

unread,
Nov 24, 2010, 10:44:03 AM11/24/10
to andro...@googlegroups.com
On Wed, Nov 24, 2010 at 10:18 AM, Guian <guian...@gmail.com> wrote:
regarding libssl.so and libcrypto.so

I've read about libexpat.so from /system/lib

"It is not officially exposed, so you will have to include your own
copy in your application. "     -  David Turner -


is it still true and also true for libssl and libcrypot ?

Yes, absolutely, if it is not in the NDK, it is not exposed (keep in mind that OEMs can add any kind of weird shared libraries to the system).
 
in that case I'll need t find out how to include them without been in
conflict with the system's ones...

Just use a different name (e.g. libexpat-custom.so / libssl-myown.so / etc)
 

Roy Samuel

unread,
Mar 18, 2011, 7:12:45 AM3/18/11
to andro...@googlegroups.com

Hi guys,

Going thru this thread, gives me the impression that I may find a clue to my plaguing problem! :)

I was able to build the mupdf library for android (libmupdf.so) and I got it working on the emulator. I have used the ndk: android-ndk-r5b & android-ndk-r4b, both work fine.

I have an app. that calls the mupdf library to read a PDF & save it as jpg files to the sdcard.

This works fine on the emulator (both 2.1 and 2.2) as well as on an Android 2.2 device API level 8 (LG Optimus).

However, on the Samsung Galaxy S (Android 2.1-update1 API level 7), the app installs fine, but on running, I'm getting the error :

ERROR/AndroidRuntime: Caused by: java.lang.UnsatisfiedLinkError: Library mupdf not found

I have tried building the library with ndk-r5b as well as prev. versions - ndk-r4, ndk-3 and ndk-r4b. There seems to be no change :(

Any ideas on what might be causing the error?!?! Any suggestions / help is appreciated.

alan

unread,
Mar 18, 2011, 7:36:18 AM3/18/11
to andro...@googlegroups.com
we might need to see your android.mk file
Reply all
Reply to author
Forward
0 new messages