How to deploy Qt imageformats plugins on Android

六眼飞鱼酱① 提交于 2019-12-11 03:43:02

问题


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.


回答1:


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.




回答2:


The answer is on the same site, a little lower on the page: Android-specific qmake Variables

The one you are looking for is most likely ANDROID_EXTRA_PLUGINS. There is no usage example, so you will have to try out in wich format to add the plugin here.

My suggestions would be:

ANDROID_EXTRA_PLUGINS += imageformats/qapng

or

ANDROID_EXTRA_PLUGINS += plugins/imageformats/libqapng.so

... something like that. This should take care of all the renaming stuff etc. as well.

EDIT:
Its also very possible you need to enter the absolute path, i.e.

ANDROID_EXTRA_PLUGINS += $$[QT_INSTALL_PLUGINS]/imageformats/libqapng.so

or in whichever path you keep the plugin



来源:https://stackoverflow.com/questions/47061829/how-to-deploy-qt-imageformats-plugins-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!