E/AndroidRuntime( 6053): Caused by: java.lang.UnsatisfiedLinkError: Library gpac not found

1,650 views
Skip to first unread message

Ngo Van Luyen

unread,
Aug 20, 2010, 10:07:48 AM8/20/10
to andro...@googlegroups.com
Hi all,


I'm testing my libs, so I take the example hello-gl2 to test.

I copie all my libs to libs/armeabi, then I checked in hello-gl2.apk, and they are there.

But when I start hello-gl2 using eclipse, hello-gl2 was crashed. I checked log and found:

E/AndroidRuntime( 6053): Caused by: java.lang.UnsatisfiedLinkError: Library gpac not found
E/AndroidRuntime( 6053): at java.lang.Runtime.loadLibrary(Runtime.java:489)
E/AndroidRuntime( 6053): at java.lang.System.loadLibrary(System.java:557)
E/AndroidRuntime( 6053): at com.android.gl2jni.GL2JNILib.<clinit>(GL2JNILib.java:25)


Why it cannot load my libs?

Thanks,


--
Hello Android!
http://androidcore.com/

RichardC

unread,
Aug 20, 2010, 12:08:39 PM8/20/10
to android-ndk
your library is called libgpac.so ?

fadden

unread,
Aug 20, 2010, 1:08:09 PM8/20/10
to android-ndk
On Aug 20, 7:07 am, Ngo Van Luyen <nvluye...@gmail.com> wrote:
> But when I start hello-gl2 using eclipse, hello-gl2 was crashed. I checked
> log and found:
>
> E/AndroidRuntime( 6053): Caused by: java.lang.UnsatisfiedLinkError: Library
> gpac not found
> E/AndroidRuntime( 6053): at java.lang.Runtime.loadLibrary(Runtime.java:489)
> E/AndroidRuntime( 6053): at java.lang.System.loadLibrary(System.java:557)
> E/AndroidRuntime( 6053): at
> com.android.gl2jni.GL2JNILib.<clinit>(GL2JNILib.java:25)


Right above that in the log you should see some diagnostics from the
VM, e.g. the dlopen() failure message.

Ngo Van Luyen

unread,
Aug 20, 2010, 4:53:37 PM8/20/10
to andro...@googlegroups.com
Yes gl2jni.so will call libgpac.so, but I'm using System.loadLibrary to load both of them.


2010/8/20 fadden <fad...@android.com>

--
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.

Christian Linne

unread,
Aug 21, 2010, 9:25:58 AM8/21/10
to andro...@googlegroups.com
Did you link the libraries? (LOCAL_LD_LIBS += -lgpac - as far as I remember - in your Android.mk)

2010/8/20 Ngo Van Luyen <nvlu...@gmail.com>



--
_________
Mit freundlichen Grüßen
Yours sincerely

Christian Linne

Mail (private): linn...@aol.com
Mail (official): Christi...@googlemail.com,
ICQ: 293253013

nguyen hoang tran

unread,
Aug 22, 2010, 9:05:20 AM8/22/10
to andro...@googlegroups.com
Hi Luyen,

As far as I know,  NDK does not support shared-library-to-shared-library linking. It just supports static-library-to-shared-library linking. This is the limitation of NDK. Although you will have no error in building, you will not use System.loadLibrary to call it. The program will be crashed unexpectedly, even if you have already loaded this library in your process. Please refer NDK/doc/SYSTEM-ISSUES.TXT for more detail.

However, I'm successful in using static-library-to-shared-library linking. Please try this!

Ngo Van Luyen

unread,
Aug 24, 2010, 4:26:14 AM8/24/10
to andro...@googlegroups.com
hi,

Thanks, but I have some confusion: I checked some demo in NDK, ex hello-gl2. In this example, we are building hello-gl2.so, and in hello-gl2 we are calling some functions from OpenGL ES. So we are calling .so to .so.

Back to my problem, I'm using static link to link my libs, and now I have some errors message:

------------------------------------------------------------------------------------------
/home/gacon/workspace/gpac/jni/src/utils/os_module.c:112: undefined reference to `dlopen'
/home/gacon/workspace/gpac/jni/src/utils/os_module.c:117: undefined reference to `dlsym'
/home/gacon/workspace/gpac/jni/src/utils/os_module.c:118: undefined reference to `dlsym'
/home/gacon/workspace/gpac/jni/src/utils/os_module.c:119: undefined reference to `dlsym'
/home/gacon/workspace/gpac/jni/src/utils/os_module.c:114: undefined reference to `dlerror'
......................

and 

/home/gacon/workspace/gpac/jni/src/compositor/compositor_2d.c:177: undefined reference to `glMatrixMode'
/home/gacon/workspace/gpac/jni/src/compositor/compositor_2d.c:179: undefined reference to `glLoadMatrixx'
/home/gacon/workspace/gpac/jni/src/compositor/compositor_2d.c:184: undefined reference to `glMatrixMode'
/home/gacon/workspace/gpac/jni/src/compositor/compositor_2d.c:189: undefined reference to `glLoadMatrixx'

...........................
------------------------------------------------------------------------------------------

But I cannot find libGLESv2.a and libdl.a in android-ndk-r4b/build/platforms/android-8/arch-arm/usr/lib

Thanks,



2010/8/22 nguyen hoang tran <nguyenho...@gmail.com>

Christian Linne

unread,
Aug 24, 2010, 6:12:09 AM8/24/10
to andro...@googlegroups.com
They are only there as shared objects, so link those to it with LOCAL_LDLIBS .
Additionally, I have already worked with multiple self-built libraries and linking them together, and it definitely works, as long as the build order is fine. It wouldn't be possible to link any shared library (even from the NDK!) otherwise.
 
2010/8/24 Ngo Van Luyen <nvlu...@gmail.com>

Ngo Van Luyen

unread,
Aug 24, 2010, 7:35:32 AM8/24/10
to andro...@googlegroups.com
Thanks for your help. It's ok now. All libs are loaded :)



2010/8/24 Christian Linne <christi...@googlemail.com>

nguyen hoang tran

unread,
Aug 24, 2010, 10:45:25 AM8/24/10
to andro...@googlegroups.com
Hi,

Yes, of course. It can work if you use LOCAL_LDLIBS. When using LOCAL_LDLIBS, it will load library in /system/lib/libname.so

What happens if you use the lib that doesn't exist in /system/lib/ ???

Please try to use LOCAL_LDLIBS with other shared libraries that don't exist in /system/lib and call them in your app.

I think it will not work.

If you can load it successfully, please share to everyone how to use shared library.

Thank you very much for your sharing!

Ngo Van Luyen

unread,
Aug 24, 2010, 10:57:23 AM8/24/10
to andro...@googlegroups.com
hi, this is the log file:

------------------------------------------------------------------------------------
D/dalvikvm( 4682): Trying to load lib /data/data/com.android.gl2jni/lib/libeditline.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /data/data/com.android.gl2jni/lib/libeditline.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /data/data/com.android.gl2jni/lib/libeditline.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /data/data/com.android.gl2jni/lib/libfreetype2.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /data/data/com.android.gl2jni/lib/libfreetype2.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /data/data/com.android.gl2jni/lib/libfreetype2.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /data/data/com.android.gl2jni/lib/libft2.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /data/data/com.android.gl2jni/lib/libft2.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /data/data/com.android.gl2jni/lib/libft2.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /system/lib/libjs.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /system/lib/libjs.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /system/lib/libjs.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /system/lib/libopenjpeg.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /system/lib/libopenjpeg.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /system/lib/libopenjpeg.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /data/data/com.android.gl2jni/lib/libjpeg.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /data/data/com.android.gl2jni/lib/libjpeg.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /data/data/com.android.gl2jni/lib/libjpeg.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /data/data/com.android.gl2jni/lib/libpng.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /data/data/com.android.gl2jni/lib/libpng.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /data/data/com.android.gl2jni/lib/libpng.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /system/lib/libz.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /system/lib/libz.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /system/lib/libz.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /data/data/com.android.gl2jni/lib/libgpac.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /data/data/com.android.gl2jni/lib/libgpac.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /data/data/com.android.gl2jni/lib/libgpac.so 0x4409b120
D/dalvikvm( 4682): Trying to load lib /system/lib/libgl2jni.so 0x4409b120
D/dalvikvm( 4682): Added shared lib /system/lib/libgl2jni.so 0x4409b120
D/dalvikvm( 4682): No JNI_OnLoad found in /system/lib/libgl2jni.so 0x4409b120
D/dalvikvm( 4682): +++ not scanning '/system/lib/libwebcore.so' for 'initgpac' (wrong CL)
D/dalvikvm( 4682): +++ not scanning '/system/lib/libmedia_jni.so' for 'initgpac' (wrong CL)
D/dalvikvm( 4682): +++ not scanning '/system/lib/libexif.so' for 'initgpac' (wrong CL)
D/dalvikvm( 4682): +++ not scanning '/system/lib/libsrec_jni.so' for 'initgpac' (wrong CL)

------------------------------------------------------------------------------------

When install my apk file, I found that some libs are copied into /system/lib, the others one are copied to /data/....

I don't know when they are copied to /sys/lib , and when for /data/....

Thanks,



2010/8/24 nguyen hoang tran <nguyenho...@gmail.com>

Christian Linne

unread,
Aug 24, 2010, 1:18:45 PM8/24/10
to andro...@googlegroups.com
Hi,

Yes, of course. It can work if you use LOCAL_LDLIBS. When using LOCAL_LDLIBS, it will load library in /system/lib/libname.so

What happens if you use the lib that doesn't exist in /system/lib/ ???

Please try to use LOCAL_LDLIBS with other shared libraries that don't exist in /system/lib and call them in your app.

I think it will not work.

If you can load it successfully, please share to everyone how to use shared library.

Thank you very much for your sharing!

I've just used that with building multiple shared libraries using the same Android.mk, to avoid any problems of build-orders.
Consider you want to build libalpha.so and libbeta.so, and beta depends on some parts of alpha, you build alpha first and beta afterwards, with LOCAL_LDLIBS += -lalpha . The issue seems to be that both libs have to be in the same directory, but that's not really a problem.
So something like
include $(CLEAR_VARS)
LOCAL_MODULE := alpha
# whatever else for your lib
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := beta
LOCAL_LDLIBS += -lalpha
# whatever else for your lib
include $(BUILD_SHARED_LIBRARY)
 
always worked for me. That's some kind of parsing issue, I think - alpha only has to exist at the point you link it to beta, and it DOES, because it has been built just some lines before.
That worked fine for me in 1.6 and 2.0 upwards. As far as I know, LOCAL_LDLIBS does not need the given libraries to be rebuilt, so that's the point that is used here. The same thing is used if you link libraries provided by the NDK, so I do not see any problems on that, please correct me if anything is wrong on that.

 

Christian Linne

unread,
Aug 25, 2010, 5:20:58 AM8/25/10
to andro...@googlegroups.com
Hm, I forgot to mention something - if LOCAL_LDLIBS does not work for you, you may also try to use LOCAL_SHARED_LIBRARIES.
Generally, if you refer to the SYSTEM-ISSUES.TXT from the docs, you should do that correctly ...
The Android dynamic linker in 1.5 has many important limitations:
That's the information on top of the part that lists the dynamic linker limitations.
 
2010/8/24 Christian Linne <christi...@googlemail.com>

nguyen hoang tran

unread,
Aug 25, 2010, 7:57:36 AM8/25/10
to andro...@googlegroups.com
Hi,

I agree with you that the usage of "LOCAL_SHARED_LIBRARIES" and "LOCAL_LDLIBS" are OK if you specify the right directory. You can choose any kind you like. You can create your shared library, but you can not link shared library on your java application. It means that you can not use shared library in your java code by System.loadLibrary("libname").  The java application will be crashed, even if you have loaded all your shared library (except you load the library in /system/lib in your shared library).

Please try this and tell me if I make mistake!

nguyen hoang tran

unread,
Aug 25, 2010, 8:34:05 AM8/25/10
to andro...@googlegroups.com
Hi Luyen,

Actually, no library will be copied into /system/lib/. This is read-only file system. Even, you cannot replace or delete it (except you use some tools or tricks). Some libraries you see have already existed in your /system/lib/. Normally, all shared libraries will be copied to /data/data/<package-name>/lib/ . Please check that!

As your log file, i think that you have already linked final shared library to another shared libraries. Please build all shared libraries to static libraries, for example: libeditline.a, libfreetype2.a, ...; then link all these static libraries to final shared library.

Please try this!

If you have any question, feel free to talk to me!

Christian Linne

unread,
Aug 25, 2010, 9:35:23 AM8/25/10
to andro...@googlegroups.com
 
[...]It means that you can not use shared library in your java code by System.loadLibrary("libname").  The java application will be crashed, even if you have loaded all your shared library [...]
No, this should work, either - the lookup caused by the "native" declaration in Java normally causes a lookup in every library that is added through System.loadLibrary(...). I don't know the correct circumstances for this in Android, and I haven't used that up to now, because it has never been neccessary - and would be really easy to avoid, either.
[...]then link all these static libraries to final shared library[...] 
I think of this only being a waste of time ;) As I have mentioned before, the linker limitations you listed only appeared in 1.5, as far as I know, they have been fixed in 1.6 .
 
And the log mentioned before is nothing to fear about - it just lists your libraries (which are loaded from your application's directory) and the system-libraries you have declared to be loaded in your Android.mk .On the point you have copied out, both kind of libraries already exist on the system, so they only have to be loaded.
2010/8/25 nguyen hoang tran <nguyenho...@gmail.com>

Ngo Van Luyen

unread,
Aug 26, 2010, 9:11:06 AM8/26/10
to andro...@googlegroups.com
Hi Tran,

If you are testing hello-gl2 from the example, and check the logcat, you can see:

----------------------------------------------------------------------------------------------------

D/libEGL  ( 3091): loaded /system/lib/egl/libEGL_fimg.so
D/libEGL  ( 3091): loaded /system/lib/egl/libGLESv1_CM_fimg.so
D/libEGL  ( 3091): loaded /system/lib/egl/libGLESv2_fimg.so
W/GL2JNIView( 3091): creating OpenGL ES 2.0 context
I/        ( 3091): libGLESv2_fimg.so was loaded and GLES 2.0 API was successfully mapped
D/dalvikvm( 3091): Trying to load lib /system/lib/libgl2jni.so 0x43f0e120
D/dalvikvm( 3091): Added shared lib /system/lib/libgl2jni.so 0x43f0e120
D/dalvikvm( 3091): No JNI_OnLoad found in /system/lib/libgl2jni.so 0x43f0e120
D/dalvikvm( 3091): +++ not scanning '/system/lib/libwebcore.so' for 'test' (wrong CL)
D/dalvikvm( 3091): +++ not scanning '/system/lib/libmedia_jni.so' for 'test' (wrong CL)
D/dalvikvm( 3091): +++ not scanning '/system/lib/libexif.so' for 'test' (wrong CL)
D/dalvikvm( 3091): +++ not scanning '/system/lib/libsrec_jni.so' for 'test' (wrong CL)
----------------------------------------------------------------------------------------------------

the system is trying to load libgl2jni.so from /system/lib/

Best,
Luyen,



2010/8/25 Christian Linne <christi...@googlemail.com>

Ngo Van Luyen

unread,
Aug 26, 2010, 9:12:39 AM8/26/10
to andro...@googlegroups.com
And if I use adb shell ls /system/lib/, I can see all my lib.so there, in /system/lib/



2010/8/26 Ngo Van Luyen <nvlu...@gmail.com>

Ngo Van Luyen

unread,
Aug 26, 2010, 10:03:35 AM8/26/10
to andro...@googlegroups.com
anyway, it's working for me, thank you all, the guru!
Reply all
Reply to author
Forward
0 new messages