Issues while loading native .so files from JNI

423 views
Skip to first unread message

MMF

unread,
Apr 22, 2009, 7:38:54 AM4/22/09
to android-...@googlegroups.com, android-d...@googlegroups.com, android-...@googlegroups.com
Hi All,

I am facing a problem while loading .so libs from my App.

Here is the story:

I have two native libs say abc.so and xyz.so.
I have written a JNI component (say jni.so) which is calling APIs from abc.so and xyz.so.

Now from the application (Java) when I do system.loadlibrary("jni.so") I get an error as "cannot find library".

But when I remove the dependencies of abc.so and xyz.so from jni.so (say I just have some dummy functions in my jni.so) and try to load jni.so from App, it works fine.

Can someone please let me know what could be problem?

Thanks
APT

Kevin Mahaffey

unread,
Apr 22, 2009, 2:17:44 PM4/22/09
to android-platform
If you have any unresolved symbols, the Java LoadLibrary call will
give you that error. You can use strace or, alternatively, try to
load jni.so from a native application being executed from the adb
shell to get more information. If you go the native application
route, you should see some linker output on the commandline.

There is a linker bug in cupcake (not sure if it is in other branches)
that will output "(null)" being unresolved instead of the symbol name
when you have unresolved global variables. We'll be submitting a
patch for that soon.

-Kevin

On Apr 22, 4:38 am, MMF <android...@gmail.com> wrote:
> Hi All,
>
> I am facing a problem while loading .so libs from my App.
>
> Here is the story:
>
> I have two native libs say *abc.so* and *xyz.so*.
> I have written a JNI component (say *jni.so*) which is calling APIs from

MMF

unread,
Apr 22, 2009, 2:37:42 PM4/22/09
to android-...@googlegroups.com
Hi Kevin,

I have written a small test application (C code) which can be run from adb shell.
And with this app there is no problem at all.
But when I do the same from Java app, my Java app is not able to load the .so and gives an error.
I am not sure if this problem is because of my jni lib in defendant on another 2 libs.

Thanks
APT
 

Kevin Mahaffey

unread,
Apr 22, 2009, 3:06:27 PM4/22/09
to android-...@googlegroups.com

Possibly try using System.Load with an absolute path to make sure it isn’t a problem with the load path of System.LoadLibrary. 

Also, try using Strace on your java app to see what’s happening inside of the linker.

 

We’ve been able to load shared objects which depend on other libraries with System.Load; however, those other libraries were in the default library path.

 

-Kevin

Dianne Hackborn

unread,
Apr 22, 2009, 3:30:29 PM4/22/09
to android-d...@googlegroups.com, android-...@googlegroups.com, android-...@googlegroups.com
Hi, you've cross-posted this to three groups, all for which the discussion is not really relevant.  I would recommend posting to just android-ndk, for people wanting to use native code in applications when it is supported at some point in the future.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

fadden

unread,
Apr 22, 2009, 3:36:28 PM4/22/09
to android-platform
On Apr 22, 12:06 pm, "Kevin Mahaffey" <kevin.mahaf...@flexilis.com>
wrote:
> Possibly try using System.Load with an absolute path to make sure it
> isn't a problem with the load path of System.LoadLibrary.  

This is a good approach when things don't seem to be working.

Also, System.loadLibrary prepends "lib" and appends ".so" to the
filename it receives. So if your library is "libjni.so", you would
call System.loadLibrary("jni").
Reply all
Reply to author
Forward
0 new messages