如何在Android上部署Qt imageformats插件 [英] How to deploy Qt imageformats plugins on Android

查看:252
本文介绍了如何在Android上部署Qt imageformats插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android上使用图片格式插件.

I'm trying to get image format plugins working on Android.

我的计划是构建此 APNG 图片格式插件,该插件应严格遵循官方风格Qt Extra 图像格式插件.对于我的问题,答案也将与此相同.

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.

在桌面(Windows)上它可以工作.只要将插件DLL放入这样的imageformats子目录中即可:

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

但是在Android上,这是另一回事了;

But on Android, it's another story;

第一个想法是将libqapng.so放入libs中,以便qtcreator将其与所有其他捆绑在一起,作为APK构建的一部分.它可以进入,但Qt在运行时不会加载.

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.

因此,我研究了现有的qt图像格式是如何工作的;

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

所以我将libqapng.so重命名为上述名称,并将其放入libs中.很好的尝试,但是没用.

So i rename libqapng.so to the above and put that into libs. Nice try, but it didn't work.

经过一番摸索,我发现有一个秘密的 resource 数组,该数组将插件的逻辑位置连接到物理文件名;

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;

此居住地;

res/values/libs.xml

看起来像这样:

<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.

果然,如果我 HACK 进入,它就能正常工作!但是如何在构建过程中将我的插件正确添加到此列表中?

Sure enough, if i HACK it in, it works! but how to add my plugin to this list properly as part of the build?

页面在Qt Android部署中提到了称为bundled_in_lib,这确实是我需要的.不幸的是,它没有说明如何更改或添加.

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.

我认为我可能会添加到我的qmake .pro文件中以影响此bundled_in_lib资源的秘密魔术咒语.

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.

该怎么做?还是有一个我还没有看到的更好的方法.似乎并没有太多关于为Android解释这些细节的说明.

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.

最后一点,另一种选择是在main.cpp中手动加载插件.我已经尝试过了,但是没有用.也许,它们需要由Qt图像格式插件加载器加载,而不是完全由加载加载.也许有一种方法可以做到这一点.不确定吗?

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?

使用Qt5.9.1

感谢您的帮助.

推荐答案

在@Felix回答之后,ANDROID_EXTRA_PLUGINS是正确的,但是它的工作原理有点奇怪.

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必须指定一个目录,而不是文件.因此,您指向自己的插件目录.该目录下的内容(包括子目录)与我原来的问题一样混乱,并在下面进行了解释.

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.

因此,对于我的插件libqapng.so,我有:

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

ANDROID_EXTRA_PLUGINS += <some path>/plugins

和我构建的Android插件.pro将输出放入;

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

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

.so库,然后卷入其中(例如,对于手臂);

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

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

和资源获得条目;

android-build/res/values/libs.xml

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

根据需要.

感谢@Felix给出了几乎所有的答案,但我想我会在这里写下其他详细信息,以使他人受益.

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

这篇关于如何在Android上部署Qt imageformats插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆