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.
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.
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.
I am using Qt 5.2.0 compiled for android and the qt5 branch of box2d
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.
Plugin Side
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
}
Our qmldir
(in the plugin source tree root) file is:
module com.mycompany.qmlcomponents
plugin prova
Application Side
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
}
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.
We don't actually know if the inclusion of the extra libprova.so is necessary. It's most probably not.
The main.cpp
looks like:
#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();
}
The main.qml
just includes the plugin like:
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtMultimedia 5.0
import com.mycompany.qmlcomponents 1.0
...
Building and Deployment
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With