Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Qt imageformats plugins on Android

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.

like image 462
jkj yuio Avatar asked Feb 01 '26 08:02

jkj yuio


1 Answers

Following @Felix answer, ANDROID_EXTRA_PLUGINS is correct, but how it works is a bit strange.

Following a discussion on the lack of doc for this feature here, and some trial and error, i found that;

ANDROID_EXTRA_PLUGINS must specify a directory, not a file. So you point to a plugins directory of your own. Things below this directory (including subdirectories) get mangled as in my original question and explained below.

So, for my plugin libqapng.so, i have:

ANDROID_EXTRA_PLUGINS += <some path>/plugins

and my android plugin building .pro puts the output in;

<some path again>/plugins/imageformats/libqapng.so

The .so lib, then winds up mangled in (eg. for arm);

android-build/libs/armeabi-v7a/libplugins_imageformats_libqapng.so

and the resources get the entry;

android-build/res/values/libs.xml

    <array name="bundled_in_lib">
    ...
<item>libplugins_imageformats_libqapng.so:plugins/imageformats/libqapng.so</item>
</array>

as required.

Thanks to @Felix for almost the answer, but i thought I'd write up the extra details here for the benefit of others.

like image 67
jkj yuio Avatar answered Feb 04 '26 00:02

jkj yuio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!