strange behaviour in shared library loading

1,037 views
Skip to first unread message

jeyries

unread,
Aug 29, 2009, 9:44:15 AM8/29/09
to android-ndk
Hello,

I have observed that on Android, shared library are not reloaded
each time the activity is started.

The problem with that is that the static data from this library
stay in the same state and are initialized properly only on the first
time they are loaded.

For example the first time the activity is started, the shared
library is loaded and the static data are initialised to the good
value.

But on the second time the activity is started, the shared library
is not loaded and the system uses the library already loaded in
memory, therefore the static data are not initialized !

I have observed this behaviour on the 1.5 emulator, and on the
Samsung Galaxy phone, but on the HTC G2 there is no problem, the
library is reloaded each time.

What do you think of this behaviour ? is it a bug ? Are they some
workaround to force correct reloading of library ?

Regards,

Julien

=====================================
some logcat to show the problem :

**** first time ****
D/dalvikvm( 715): Trying to load lib /data/data/com.example.quake2/
lib/libquake2.so 0x499401b0
I/ActivityManager( 582): Displayed activity
com.example.quake2/.Quake2: 1905 ms
D/dalvikvm( 715): Added shared lib /data/data/com.example.quake2/lib/
libquake2.so 0x499401b0
D/dalvikvm( 715): No JNI_OnLoad found in /data/data/
com.example.quake2/lib/libquake2.so 0x499401b0
D/dalvikvm( 715): +++ not scanning '/system/lib/libwebcore.so' for
'getVersion' (wrong CL)
I/Quake2 ( 715): version : 1.0
D/dalvikvm( 715): +++ not scanning '/system/lib/libwebcore.so' for
'Quake2Test' (wrong CL)
D/quake2-jni.c( 715): init_done= 0
I/ARMAssembler( 715): generated
scanline__00000077:03010144_00000000_00000000 [ 11 ipp] (45 ins) at
[0x198c48:0x198cfc] in 2648382 ns
D/quake2-jni.c( 715): init_done= 1

**** second time ****
D/dalvikvm( 956): Trying to load lib /data/data/com.example.quake2/
lib/libquake2.so 0x49b36f60
D/dalvikvm( 956): Shared lib '/data/data/com.example.quake2/lib/
libquake2.so' already loaded in same CL 0x49b36f60
I/Quake2 ( 956): version : 1.0
D/quake2-jni.c( 956): init_done= 1
I/ActivityManager( 587): Displayed activity
com.example.quake2/.Quake2: 1253 ms
D/quake2-jni.c( 956): init_done= 1


David Turner

unread,
Aug 31, 2009, 1:19:45 PM8/31/09
to andro...@googlegroups.com
On Sat, Aug 29, 2009 at 6:44 AM, jeyries <jey...@googlemail.com> wrote:

Hello,

   I have observed that on Android, shared library are not reloaded
each time the activity is started.

   The problem with that is that the static data from this library
stay in the same state and are initialized properly only on the first
time they are loaded.

   For example the first time the activity is started, the shared
library is loaded and the static data are initialised to the good
value.

  But on the second time  the activity is started, the shared library
is not loaded and the system uses the library already loaded in
memory, therefore the static data are not initialized !

  I have observed this behaviour on the 1.5 emulator, and on the
Samsung Galaxy phone, but on the HTC G2 there is no problem, the
library is reloaded each time.

 What do you think of this behaviour ? is it a bug ? Are they some
workaround to force correct reloading of library ?


This behaviour is perfectly normal. Activity lifecycle and process/VM lifecycles are very different things
in Android. If you need to initialize something each time your Activity starts, you will have to do that
explicitely by calling a native function.

jeyries

unread,
Sep 6, 2009, 3:34:58 AM9/6/09
to android-ndk
OK I understand. As the library is linked to the process/VM I need to
kill the process to be sure that the library is reloaded.

Thanks !

Dianne Hackborn

unread,
Sep 6, 2009, 2:55:24 PM9/6/09
to andro...@googlegroups.com
Please do not kill the process.  Just do whatever init you want to get into the desired state when the activity starts.
--
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.

Eric Yuen

unread,
Dec 18, 2013, 12:29:20 AM12/18/13
to andro...@googlegroups.com
Hi, I have the exact same problem (with the same library in fact). How did you resolve this?

On Monday, August 13, 2012 2:05:51 PM UTC-4, Dark Smile wrote:
Hey i know this thread is old but i get the same error. Log cat says:
 
 
08-13 19:58:16.215: D/dalvikvm(28975): Trying to load lib /data/data/*my.app.space*//lib/libzbarjni.so 0x419ff688
08-13 19:58:16.215: D/dalvikvm(28975): Shared lib '/data/data/*my.app.space*/lib/libzbarjni.so' already loaded in same CL 0x419ff688
08-13 19:58:16.255: A/libc(28975): Fatal signal 11 (SIGSEGV) at 0x41a73000 (code=2)
abow the onCreate event in the section, where i declare my variables, i use
 
static { System.LoadLibrary("iconv"); }
Reply all
Reply to author
Forward
0 new messages