What is the proper way to deploy C ++ QML plugins on a mobile device?

I played a lot with the Box2D QML plugin and everything looks very good. However, I wanted to deploy my sample application on Android (SGS2), but I cannot get it to work. I try to run it on an AVD or on a device, this will not work. androiddeployqt succeeds, but then I get “Unable to launch MyApp” and no other information about why it couldn’t start. I can successfully run qml applications on AVD and device, but this has something to do with the plugin, and I can not find any links to solve it.

I tried to configure DEPLOYMENTFOLDERS differently, but if I am wrong, then all this fails. Even when I do not receive the error message, in this case I assume that everything is correct, it still does not start.

I have been struggling with this a bit for some time and cannot find any useful information to solve it. If you know of a project that uses the C ++ plugin and can be successfully deployed on an Android device, this is also good.

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

+7
qt qml qtquick2
source share
1 answer

We were getting “module not found” errors while we tried to get our QML module to work in the Android Qt application. With Qt 5.3, we were able to get a QML plugin that is recognized only by deploying the plugin in the QT_INSTALL_QML directory, where the official Qt Qt modules are located. In our case, this is the directory / opt / Qt / 5.3 / android_armv7 / qml.

Plugin side

Our .pro file for the plugin looks like this:

 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 } 

Our qmldir (in the root root of the plugin source):

 module com.mycompany.qmlcomponents plugin prova 

Application side

The .pro file looks like this:

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

Important Note. Any library that your qml plugin uses must also be specified in ANDROID_EXTRA_LIBS in order to be embedded in apk. This includes the Qt components, and listing them in QT + = is not enough unless you use them in your application.

We really do not know if the inclusion of additional libprova.so is necessary. Most likely no.

main.cpp looks like this:

 #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 includes only the plugin:

 import QtQuick 2.2 import QtQuick.Controls 1.1 import QtMultimedia 5.0 import com.mycompany.qmlcomponents 1.0 ... 

Build and Deploy

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

How we create and deploy a project that uses the plugin is qmake (again, from the android-armv7 Qt toolchain), then make install INSTALL_ROOT=. (set to build the directory), then run androiddeployqt . The last command creates the structure of the Android project using qmldirs in assets and libraries in libs / and binds all this in apk via ant . See http://qt-project.org/wiki/Android for more on this procedure.

In short, we were able to get our QML plugin as part of the Android project by placing it in a private Qt qml directory. Hope this helps in some way.

+6
source share

All Articles