在移动设备上部署 C++ QML 插件的正确方法是什么? [英] What is the proper way of deploying C++ QML plugins on mobile device?

查看:39
本文介绍了在移动设备上部署 C++ QML 插件的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩 Box2D QML 插件,而且看起来非常好.但是,我想在 Android (SGS2) 上部署我的示例应用程序,但我似乎无法让它工作.无论我尝试在 AVD 上还是在设备上运行它,它都不起作用.androiddeployqt 成功完成,但随后我收到无法启动‘MyApp’"并且没有其他信息说明它无法启动的原因.我可以在 AVD 和设备上成功运行 qml 应用程序,但这与插件有关,我找不到任何参考来解决它.

I've been playing a lot with the Box2D QML plugin and the things are looking really good. However, I wanted to deploy my sample app on Android (SGS2), but I can't seem to get it work. Whether I try to run it on AVD or on the device, it doesn't work. androiddeployqt finishes successfully, but then I get "Unable to start 'MyApp'" and no other info as to why it failed to start. I can successfully run qml apps on the AVD and the device, but this has something to do with the plugin and I can't find any reference in order to solve it.

我尝试以不同的方式设置 DEPLOYMENTFOLDERS,但如果我弄错了,那么整个事情都会失败.即使我没有收到错误消息,在这种情况下,我认为我做对了,它仍然无法启动.

I tried setting up DEPLOYMENTFOLDERS in different ways, but if i get them wrong, then the whole thing fails. Even when I don't get an error, in which case I assume I got it right, it still doesn't start.

我已经为此苦苦挣扎了一段时间,但找不到任何有用的信息来解决它.如果您知道任何使用 c++ 插件并且可以成功部署在 android 设备上的项目,那也不错.

I've been struggling with this for quiet some time, and can't find any bit of useful information in order to resolve it. If you know of any project that uses a c++ plugin and can be successfully deployed on android device, that would be good as well.

我使用的是为 android 编译的 Qt 5.2.0 和 box2d 的 qt5 分支

I am using Qt 5.2.0 compiled for android and the qt5 branch of box2d

推荐答案

当我们试图让 QML 模块在 Android Qt 应用程序中工作时,我们遇到了找不到模块"错误.在 Qt 5.3 中,我们仅通过将插件部署到官方 Qt QML 模块所在的 QT_INSTALL_QML 目录,才设法让我们的 QML 插件被识别.在我们的例子中,这个目录是/opt/Qt/5.3/android_armv7/qml.

We were getting "module not found" errors while we were trying to get our QML module working inside an Android Qt application. With Qt 5.3, we managed to get our QML plugin recognized only by deploying the plugin to the QT_INSTALL_QML directory where official Qt QML modules reside. This directory is /opt/Qt/5.3/android_armv7/qml in our case.

插件端

我们的插件.pro 文件如下所示:

Our .pro file for the plugin looks like:

TEMPLATE = lib
TARGET = prova
QT += qml quick multimedia
CONFIG += qt plugin c++11 console
CONFIG -= android_install
TARGET = $$qtLibraryTarget($$TARGET)
uri = com.mycompany.qmlcomponents

# Input
SOURCES += \
    src1.cpp \
    src2.cpp

HEADERS += \
    src1.h \
    src2.h

##The below is generated automatically by Qt Creator when you create a new "Qt Quick 2 Extension Plugin" project for Android

#Copies the qmldir file to the build directory
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
    copy_qmldir.target = $$OUT_PWD/qmldir
    copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
    copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\"
    QMAKE_EXTRA_TARGETS += copy_qmldir
    PRE_TARGETDEPS += $$copy_qmldir.target
}

#Copies the qmldir file and the built plugin .so to the QT_INSTALL_QML directory
qmldir.files = qmldir
unix {
    installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
    qmldir.path = $$installPath
    target.path = $$installPath
    INSTALLS += target qmldir
}

我们的qmldir(在插件源码树根中)文件是:

Our qmldir (in the plugin source tree root) file is:

module com.mycompany.qmlcomponents
plugin prova

应用端

.pro 文件如下所示:

The .pro file looks like:

TEMPLATE = app

QT += qml quick widgets multimedia

CONFIG+= console
SOURCES += main.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)

contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
    ANDROID_EXTRA_LIBS = \
        /opt/Qt/5.3/android_armv7/qml/com/mycompany/qmlcomponents/libprova.so
}

重要说明:您的 qml 插件使用的任何库也必须列在 ANDROID_EXTRA_LIBS 中,以便捆绑到 apk 中.这也包括 Qt 组件,如果您不在应用程序中使用它们,将它们列在 QT+= 中是不够的.

Important Note: Any library that your qml plugin uses must also be listed in ANDROID_EXTRA_LIBS in order to be bundled into the apk. This includes Qt components as well, listing them in QT+= is not enough if you don't use them in your application.

我们实际上并不知道是否需要包含额外的 libprova.so.很可能不是.

We don't actually know if the inclusion of the extra libprova.so is necessary. It's most probably not.

main.cpp 看起来像:

#include <QApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[]){
    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    return app.exec();
}

main.qml 只包含如下插件:

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtMultimedia 5.0

import com.mycompany.qmlcomponents 1.0

...

构建和部署

我们构建和部署插件的方式是qmake(来自Qt的android-armv7工具链),然后make install.它将 qmldir 文件和插件 .so 安装到 QT_INSTALL_QML 目录.

The way we build and deploy the plugin is to qmake (from the android-armv7 toolchain of Qt), then make install. It installs the qmldir file and the plugin .so to the QT_INSTALL_QML directory.

我们构建和部署使用插件的项目的方式是qmake(同样来自Qt的android-armv7工具链),然后make install INSTALL_ROOT=.(安装到构建目录),然后运行 ​​androiddeployqt.最后一个命令使用 assets/中的 qmldirs 和 libs/中的库创建 Android 项目结构,并通过 ant 将整个内容捆绑在 apk 中.有关此过程的详细信息,请参阅http://qt-project.org/wiki/Android.

The way we build and deploy the project that uses the plugin is to qmake (again, from the android-armv7 toolchain of Qt), then make install INSTALL_ROOT=. (installs to build directory), then run androiddeployqt. The last command creates the Android project structure with the qmldirs in assets/ and libraries in libs/ and bundles the whole thing in an apk via ant. For the details of this procedure, refer to http://qt-project.org/wiki/Android.

简而言之,我们只能通过将 QML 插件放在私有 Qt qml 目录中,才能在 Android 项目中识别它.我希望这在某种程度上有所帮助.

In short, we were only able to get our QML plugin recognized inside an Android project by putting it inside the private Qt qml directory. I hope this helps in some way.

这篇关于在移动设备上部署 C++ QML 插件的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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