Error with custom QML module on Android: module "QtQuick.Window" is not installed
-
Hi,
I'm developing a custom QML module that contains some custom QML items. One of them is a "MainWindow" type that inherits from the Window QML type (via import QtQuick.Window 2.2). The QML module is installed right into the qml directories of my Qt installation (..\5.5\mingw492_32\qml and ..\5.5\android_armv7\qml respectively).
When I write an application that imports my module, it works fine on Windows. When I try to deploy and execute it on Android I get the following Error:
D libandroidmoduletest.so: (null):0 ((null)): [Plugin] initializing engine for "MyQmlModule" W libandroidmoduletest.so: (null):0 ((null)): QQmlApplicationEngine failed to load component W libandroidmoduletest.so: (null):0 ((null)): qrc:/main.qml:4 Type MainWindow unavailable W libandroidmoduletest.so: qrc:/MyQmlModule/MainWindow.qml:2 module "QtQuick.Window" is not installed
It seems that qmlimportscanner doesn't detect the dependency of MyQmlModule to the QtQuick.Window module.
Any ideas what to do about it?
-
I did some digging and found that adding a QML-file to the application project containing all imports used in the QML Module (library) will add all necessary dependencies to the Android APK.
QmlDependencies.qml:
import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import QtQuick.Layouts 1.1 import QtQuick.Window 2.2 import Qt.labs.folderlistmodel 2.1 import QtGraphicalEffects 1.0 QtObject {}
But I can't help but wonder if there is another way of doing this directly in my custom module? Is there any Qt-conformant way to provide a list of dependencies to the android build that doesn't involve adding a file to all projects that import the module?
-
Turns out that adding the
depends
keyword to the qmldir file of MyModule did the trick.
(see also: https://doc.qt.io/qt-5/qtqml-modules-qmldir.html#contents-of-a-module-definition-qmldir-file)