diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake index c5f04c49bc..3640624aa3 100644 --- a/src/corelib/Qt6AndroidMacros.cmake +++ b/src/corelib/Qt6AndroidMacros.cmake @@ -187,13 +187,21 @@ function(qt6_android_generate_deployment_settings target) " \"qml-import-paths\": \"${_import_paths}\",\n") endif() - get_target_property(qml_root_path ${target} QT_QML_ROOT_PATH) - if(NOT qml_root_path) - set(qml_root_path "${target_source_dir}") + get_target_property(qml_root_paths ${target} QT_QML_ROOT_PATH) + if(NOT qml_root_paths) + set(qml_root_paths "${target_source_dir}") endif() - file(TO_CMAKE_PATH "${qml_root_path}" qml_root_path_native) + + set(qml_native_root_paths "") + foreach(root_path IN LISTS qml_root_paths) + file(TO_CMAKE_PATH "${root_path}" qml_root_path_native) + list(APPEND qml_native_root_paths "\"${qml_root_path_native}\"") + endforeach() + + list(JOIN qml_native_root_paths "," qml_native_root_paths) + string(APPEND file_contents - " \"qml-root-path\": \"${qml_root_path_native}\",\n") + " \"qml-root-path\": [${qml_native_root_paths}],\n") # App binary string(APPEND file_contents diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index 2fa944a95b..bc280dc107 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -171,7 +171,7 @@ struct Options QString inputFileName; QString applicationBinary; QString applicationArguments; - QString rootPath; + std::vector rootPaths; QString rccBinaryPath; QString depFilePath; QString buildDirectory; @@ -1030,8 +1030,17 @@ bool readInputFile(Options *options) { const QJsonValue qmlRootPath = jsonObject.value(QLatin1String("qml-root-path")); - if (!qmlRootPath.isUndefined()) - options->rootPath = qmlRootPath.toString(); + if (qmlRootPath.isString()) { + options->rootPaths.push_back(qmlRootPath.toString()); + } else if (qmlRootPath.isArray()) { + auto qmlRootPaths = qmlRootPath.toArray(); + for (auto path : qmlRootPaths) { + if (path.isString()) + options->rootPaths.push_back(path.toString()); + } + } else { + options->rootPaths.push_back(options->inputFileName); + } } { @@ -1671,7 +1680,8 @@ bool readAndroidDependencyXml(Options *options, QString file = reader.attributes().value(QLatin1String("file")).toString(); // Special case, since this is handled by qmlimportscanner instead - if (!options->rootPath.isEmpty() && (file == QLatin1String("qml") || file == QLatin1String("qml/"))) + if (!options->rootPaths.empty() + && (file == QLatin1String("qml") || file == QLatin1String("qml/"))) continue; const QList fileNames = findFilesRecursively(*options, file); @@ -1849,6 +1859,7 @@ QString defaultLibexecDir() } bool goodToCopy(const Options *options, const QString &file, QStringList *unmetDependencies); +bool checkQmlFileInRootPaths(const Options *options, const QString &absolutePath); bool scanImports(Options *options, QSet *usedDependencies) { @@ -1864,16 +1875,6 @@ bool scanImports(Options *options, QSet *usedDependencies) qmlImportScanner += QLatin1String(".exe"); #endif - QString rootPath = options->rootPath; - - if (rootPath.isEmpty()) - rootPath = QFileInfo(options->inputFileName).absolutePath(); - else - rootPath = QFileInfo(rootPath).absoluteFilePath(); - - if (!rootPath.endsWith(QLatin1Char('/'))) - rootPath += QLatin1Char('/'); - QStringList importPaths; importPaths += shellQuote(options->qtInstallDirectory + QLatin1String("/qml")); @@ -1914,11 +1915,18 @@ bool scanImports(Options *options, QSet *usedDependencies) return true; } - // After checking for qml folder imports we can add rootPath - if (!rootPath.isEmpty()) - importPaths += shellQuote(rootPath); + for (auto rootPath : options->rootPaths) { + rootPath = QFileInfo(rootPath).absoluteFilePath(); - qmlImportScanner += QLatin1String(" -rootPath %1").arg(shellQuote(rootPath)); + if (!rootPath.endsWith(QLatin1Char('/'))) + rootPath += QLatin1Char('/'); + + // After checking for qml folder imports we can add rootPath + if (!rootPath.isEmpty()) + importPaths += shellQuote(rootPath); + + qmlImportScanner += QLatin1String(" -rootPath %1").arg(shellQuote(rootPath)); + } if (!options->qrcFiles.isEmpty()) { qmlImportScanner += QLatin1String(" -qrcFiles"); @@ -1980,7 +1988,7 @@ bool scanImports(Options *options, QSet *usedDependencies) if (!absolutePath.endsWith(QLatin1Char('/'))) absolutePath += QLatin1Char('/'); - if (absolutePath.startsWith(rootPath)) { + if (checkQmlFileInRootPaths(options, absolutePath)) { if (options->verbose) fprintf(stdout, " -- Skipping because path is in QML root path.\n"); continue; @@ -2035,6 +2043,15 @@ bool scanImports(Options *options, QSet *usedDependencies) return true; } +bool checkQmlFileInRootPaths(const Options *options, const QString &absolutePath) +{ + for (auto rootPath : options->rootPaths) { + if (absolutePath.startsWith(rootPath)) + return true; + } + return false; +} + bool runCommand(const Options &options, const QString &command) { if (options.verbose) @@ -2161,7 +2178,7 @@ bool readDependencies(Options *options) } } - if ((!options->rootPath.isEmpty() || options->qrcFiles.isEmpty()) && + if ((!options->rootPaths.empty() || options->qrcFiles.isEmpty()) && !scanImports(options, &usedDependencies)) return false;