[Interest] Qt on Android and loading native libs

Preet prismatic.project at gmail.com
Tue Oct 27 16:49:02 CET 2015


I recently came across an issue with native code on Android (not in a Qt
application though). When an Activity loads shared libraries, those
libraries aren't unloaded by Android until the corresponding process is
killed. However, Android can keep the same process around while creating
multiple instances of an Activity.

So it seems like the main QtActivity may be created and destroyed multiple
times with the same process (unless something I did't catch is being done
to prevent this). If shared libraries aren't loaded/unloaded accordingly,
you would be starting up your native application with any global state in
the shared libraries left intact.

I think that to compensate for this, Qt unloads the shared library that
contains the 'main' function. You can see this in androidjnimain.cpp, in
the startMainMethod function where dlclose is called on whichever native
lib contains the 'main' symbol. I'm not entirely sure that dlclose is being
called explicitly for this purpose though. After that, finish() is called
on the Activity.

This should work in general but there's this edge case where another
instance of an Activity can be created *before* the previous one is
destroyed.

So imagine:
00:01: [QtActivity1 onCreate]
00:02: [QtActivity1 onPause]
00:03: [QtActivity2 onCreate]
00:04: [QtActivity1 onStop,Destroy,whatever]

Does qt do anything to prevent or deal with that case?


Preet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151027/5f9e64bc/attachment.html>


More information about the Interest mailing list