Native libraries installation path

362 views
Skip to first unread message

Olivier Guilyardi

unread,
Dec 28, 2009, 6:53:02 PM12/28/09
to andro...@googlegroups.com
Hi,

I need to load a shared library built with the NDK using dlopen() instead of the
usual System.loadLibrary().

For this, I need a clean way to find the path to the location where the .so file
is installed.

From older posts on this thread and by reading logcat, I see that it's:
/data/data/<app_pkg>/lib

But how can I programmatically and reliably find this path with the SDK?

--
Olivier

Olivier Guilyardi

unread,
Dec 29, 2009, 7:52:30 AM12/29/09
to andro...@googlegroups.com

Hey guys, please help. This isn't a stupid/superfluous question, I need to
provide some sort of dynamic linking to comply with the LGPL for a library I'm
using. That's why I'm playing with dlopen().

On this very list, Dianne Hackborn states that "there are Java APIs to get
the path":
http://groups.google.com/group/android-ndk/browse_frm/thread/6b2ee1a90cbb0800/c375ed98edbc1036?lnk=gst&q=dlopen#c375ed98edbc1036

But what are these "APIs"?

The somewhat "clean" thing that I found on android 1.5 is:

dataDir = getPackageManager().getApplicationInfo(getPackageName(), 0).dataDir;
libFilename = System.mapLibraryName("libname")
fullPath = dataDir + "/lib/" + libFilename;

But is this reliable? Will it still work in the future?

Isn't there something more straightforward, similar to
ClassLoader.findLibrary("libname")?

I also looked at System.getProperty("java.library.path") but it only returns
/system/lib.

--
Olivier

Olivier Guilyardi

unread,
Dec 30, 2009, 9:11:35 AM12/30/09
to andro...@googlegroups.com

Could anyone please explain why I'm not getting any answer to this question?

Maybe that you think that my question is irrelevant because of this first
sentence "I need to load a shared library built with the NDK using dlopen()


instead of the usual System.loadLibrary()"

Don't get me wrong, I'm not trying to load a library with JNI methods with
dlopen(). I am loading a library with System.loadLibrary(), and this library is
loading another library using dlopen(). Both libraries are compiled with the NDK
into a single project, and thus installed in the same place on the device. What
I meant is that I need to use dlopen() and thus cannot, in this case, benefit of
the automatic path resolution provided by System.loadLibrary().

My current use of dlopen() works perfectly. But I need an elegant and reliable
way to find the path that I pass to dlopen(), to ensure that it will still work
in the future.

--
Olivier

Reply all
Reply to author
Forward
0 new messages