I'm trying to get image format plugins working on Android.
My plan is to build this APNG image format plugin, which closely follows the style of the official Qt extra image format plugins. The answer to my problem will be the same for these too.
On desktop (windows) it works. So long as you put the plugin DLL into a imageformats
subdirectory like this:
myapp/<all my binaries>
imageformats/qapng.dll
But on Android, it's another story;
First idea was to put libqapng.so
into libs
so that qtcreator
bundles it up with all the others as part of an APK build. It goes in, but is not loaded by Qt at runtime.
So i look into how the existing qt image formats work;
turns out, rather than being in a subdirectory, they are named according to this pattern;
libplugins_imageformats_libqapng.so
So i rename libqapng.so
to the above and put that into libs
. Nice try, but it didn't work.
After a lot of head scratching, i discover there's a secret resource array that connects the logical location of plugins to the physical file names;
This lives in;
res/values/libs.xml
and looks like this:
<array name="bundled_in_lib">
...
<item>libplugins_imageformats_libqgif.so:plugins/imageformats/libqgif.so</item>
<item>libplugins_imageformats_libqicns.so:plugins/imageformats/libqicns.so</item>
<item>libplugins_imageformats_libqico.so:plugins/imageformats/libqico.so</item>
<item>libplugins_imageformats_libqjpeg.so:plugins/imageformats/libqjpeg.so</item>
<item>libplugins_imageformats_libqsvg.so:plugins/imageformats/libqsvg.so</item>
<item>libplugins_imageformats_libqtga.so:plugins/imageformats/libqtga.so</item>
<item>libplugins_imageformats_libqtiff.so:plugins/imageformats/libqtiff.so</item>
<item>libplugins_imageformats_libqwbmp.so:plugins/imageformats/libqwbmp.so</item>
<item>libplugins_imageformats_libqwebp.so:plugins/imageformats/libqwebp.so</item>
....
So, i just need to get my new plugin into that list.
Sure enough, if i HACK it in, it works! but how to add my plugin to this list properly as part of the build?
this page on Qt Android deployment mentions a thing called bundled_in_lib
, which is indeed what i need. But it unfortunately does not explain how to change this or to add to it.
I'm thinking there might be a secret magic spell i can add to my qmake
.pro
file to affect this bundled_in_lib
resource.
How to do it? or is there a better way that I've not yet seen. There doesn't seem to be much about explaining these details for Android.
On a final note, an alternative might be to manually load the plugin in main.cpp
. I've tried this and it doesn't work. Perhaps, they need to be loaded by the Qt image format plugin loader rather than just loaded at all. Maybe there's a way to do this. not sure?
using Qt5.9.1
Thanks for any help.