Description: Install android files to DATADIR
 .
 Install src/android/templates into INSTALL_DATADIR
 Install src/3rdparty/gradle into INSTALL_DATADIR
 Install src/android/java files into INSTALL_DATADIR
 Install all jars into INSTALL_DATADIR
 .
 Add new items to android-*-deployment-settings.json:
   - qtDataDirectory
   - qtLibsDirectory
   - qtLibExecsDirectory
   - qtPluginsDirectory
   - qtQmlDirectory
 .
 .
 When configuring with cmake, also set the qml-importscanner-binary
 attribute in android-*-deployment-settings.json
 .
 Update androiddeployqt to be able to get files from their install location
 .
 See https://bugreports.qt.io/browse/QTBUG-106533
Author: Fab Stz <fabstz-it@yahoo.fr>
Forwarded: yes
Last-Update: 2022-09-29

--- a/qtbase/src/3rdparty/gradle/CMakeLists.txt
+++ b/qtbase/src/3rdparty/gradle/CMakeLists.txt
@@ -1,4 +1,4 @@
-qt_path_join(destination ${QT_INSTALL_DIR} "src/3rdparty/gradle")
+qt_path_join(destination ${QT_INSTALL_DIR} ${INSTALL_DATADIR} "src/3rdparty/gradle")
 qt_copy_or_install(
     PROGRAMS
         gradlew
--- a/qtbase/src/android/jar/CMakeLists.txt
+++ b/qtbase/src/android/jar/CMakeLists.txt
@@ -25,8 +25,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtBase_VERSION_MAJOR}Android # special case
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtbase/src/android/java/CMakeLists.txt
+++ b/qtbase/src/android/java/CMakeLists.txt
@@ -6,7 +6,7 @@
     res
     src)
 
-qt_path_join(destination ${QT_INSTALL_DIR} "src/android/java")
+qt_path_join(destination ${QT_INSTALL_DIR} ${INSTALL_DATADIR} "src/android/java")
 qt_copy_or_install(DIRECTORY ${resource_directories}
                    DESTINATION "${destination}"
 )
--- a/qtbase/src/android/templates/CMakeLists.txt
+++ b/qtbase/src/android/templates/CMakeLists.txt
@@ -9,7 +9,7 @@
 set(template_directories
     res)
 
-qt_path_join(destination ${QT_INSTALL_DIR} "src/android/templates")
+qt_path_join(destination ${QT_INSTALL_DIR} ${INSTALL_DATADIR} "src/android/templates")
 qt_copy_or_install(FILES ${template_files}
                    DESTINATION "${destination}")
 
--- a/qtbase/src/tools/androiddeployqt/main.cpp
+++ b/qtbase/src/tools/androiddeployqt/main.cpp
@@ -70,10 +70,30 @@
 
 struct QtInstallDirectoryWithTriple
 {
-    QtInstallDirectoryWithTriple(const QString &dir = QString(), const QString &t = QString()) :
-        qtInstallDirectory(dir), triple(t), enabled(false) {}
+    QtInstallDirectoryWithTriple(const QString &dir = QString(),
+                                 const QString &t = QString(),
+                                 const QString &dataDir = QString(),
+                                 const QString &libsDir = QString(),
+                                 const QString &libExecsdir = QString(),
+                                 const QString &pluginsDir = QString(),
+                                 const QString &qmlDir = QString()
+                                ) :
+        qtInstallDirectory(dir),
+        qtDataDirectory(dataDir),
+        qtLibsDirectory(libsDir),
+        qtLibExecsDirectory(libExecsdir),
+        qtPluginsDirectory(pluginsDir),
+        qtQmlDirectory(qmlDir),
+        triple(t),
+        enabled(false)
+        {}
 
     QString qtInstallDirectory;
+    QString qtDataDirectory;
+    QString qtLibsDirectory;
+    QString qtLibExecsDirectory;
+    QString qtPluginsDirectory;
+    QString qtQmlDirectory;
     QString triple;
     bool enabled;
 };
@@ -129,6 +149,11 @@
 
     // Build paths
     QString qtInstallDirectory;
+    QString qtDataDirectory;
+    QString qtLibsDirectory;
+    QString qtLibExecsDirectory;
+    QString qtPluginsDirectory;
+    QString qtQmlDirectory;
     QString qtHostDirectory;
     std::vector<QString> extraPrefixDirs;
     // Unlike 'extraPrefixDirs', the 'extraLibraryDirs' key doesn't expect the 'lib' subfolder
@@ -200,10 +225,22 @@
     QString installLocation;
 
     // Per architecture collected information
-    void setCurrentQtArchitecture(const QString &arch, const QString &directory)
+    void setCurrentQtArchitecture(const QString &arch,
+                                  const QString &directory,
+                                  const QString &dataDirectory,
+                                  const QString &libsDirectory,
+                                  const QString &libExecsDirectory,
+                                  const QString &pluginsDirectory,
+                                  const QString &qmlDirectory
+    )
     {
         currentArchitecture = arch;
         qtInstallDirectory = directory;
+        qtDataDirectory = dataDirectory;
+        qtLibsDirectory = libsDirectory;
+        qtLibExecsDirectory = libExecsDirectory;
+        qtPluginsDirectory = pluginsDirectory;
+        qtQmlDirectory = qmlDirectory;
     }
     typedef QPair<QString, QString> BundledFile;
     QHash<QString, QList<BundledFile>> bundledFiles;
@@ -252,15 +289,6 @@
     return path;
 }
 
-QString defaultLibexecDir()
-{
-#ifdef Q_OS_WIN32
-    return "bin"_L1;
-#else
-    return "libexec"_L1;
-#endif
-}
-
 static QString llvmReadobjPath(const Options &options)
 {
     return execSuffixAppended("%1/toolchains/%2/prebuilt/%3/bin/llvm-readobj"_L1
@@ -896,6 +924,202 @@
             return false;
         }
     }
+
+    {
+        const QJsonValue qtDataDirectory = jsonObject.value("qtDataDirectory"_L1);
+        if (qtDataDirectory.isUndefined()) {
+            fprintf(stderr, "No Qt Data directory in json file %s\n", qPrintable(options->inputFileName));
+            return false;
+        }
+
+        if (qtDataDirectory.isObject()) {
+            const QJsonObject object = qtDataDirectory.toObject();
+            for (auto it = object.constBegin(); it != object.constEnd(); ++it) {
+                if (it.value().isUndefined()) {
+                    fprintf(stderr, "Invalid architecture: %s\n",
+                            qPrintable(it.value().toString()));
+                    return false;
+                }
+                if (it.value().isNull())
+                    continue;
+                if (!options->architectures.contains(it.key())) {
+                    fprintf(stderr, "Architecture %s unknown (%s).", qPrintable(it.key()),
+                        qPrintable(options->architectures.keys().join(u',')));
+                    return false;
+                }
+                options->architectures[it.key()].qtDataDirectory = it.value().toString();
+            }
+        } else if (qtDataDirectory.isString()) {
+            // Format for Qt < 6 or when using the tool with Qt >= 6 but in single arch.
+            // We assume Qt > 5.14 where all architectures are in the same directory.
+            const QString directory = qtDataDirectory.toString();
+            options->architectures["arm64-v8a"_L1].qtDataDirectory = directory;
+            options->architectures["armeabi-v7a"_L1].qtDataDirectory = directory;
+            options->architectures["x86"_L1].qtDataDirectory = directory;
+            options->architectures["x86_64"_L1].qtDataDirectory = directory;
+        } else {
+            fprintf(stderr, "Invalid format for Qt Data install prefixes in json file %s.\n",
+                    qPrintable(options->inputFileName));
+            return false;
+        }
+    }
+
+    {
+        const QJsonValue qtLibsDirectory = jsonObject.value("qtLibsDirectory"_L1);
+        if (qtLibsDirectory.isUndefined()) {
+            fprintf(stderr, "No Qt Libs directory in json file %s\n", qPrintable(options->inputFileName));
+            return false;
+        }
+
+        if (qtLibsDirectory.isObject()) {
+            const QJsonObject object = qtLibsDirectory.toObject();
+            for (auto it = object.constBegin(); it != object.constEnd(); ++it) {
+                if (it.value().isUndefined()) {
+                    fprintf(stderr, "Invalid architecture: %s\n",
+                            qPrintable(it.value().toString()));
+                    return false;
+                }
+                if (it.value().isNull())
+                    continue;
+                if (!options->architectures.contains(it.key())) {
+                    fprintf(stderr, "Architecture %s unknown (%s).", qPrintable(it.key()),
+                        qPrintable(options->architectures.keys().join(u',')));
+                    return false;
+                }
+                options->architectures[it.key()].qtLibsDirectory = it.value().toString();
+            }
+        } else if (qtLibsDirectory.isString()) {
+            // Format for Qt < 6 or when using the tool with Qt >= 6 but in single arch.
+            // We assume Qt > 5.14 where all architectures are in the same directory.
+            const QString directory = qtLibsDirectory.toString();
+            options->architectures["arm64-v8a"_L1].qtLibsDirectory = directory;
+            options->architectures["armeabi-v7a"_L1].qtLibsDirectory = directory;
+            options->architectures["x86"_L1].qtLibsDirectory = directory;
+            options->architectures["x86_64"_L1].qtLibsDirectory = directory;
+        } else {
+            fprintf(stderr, "Invalid format for Qt Libs install prefixes in json file %s.\n",
+                    qPrintable(options->inputFileName));
+            return false;
+        }
+    }
+
+    {
+        const QJsonValue qtLibExecsDirectory = jsonObject.value("qtLibExecsDirectory"_L1);
+        if (qtLibExecsDirectory.isUndefined()) {
+            fprintf(stderr, "No Qt LibExecs directory in json file %s\n", qPrintable(options->inputFileName));
+            return false;
+        }
+
+        if (qtLibExecsDirectory.isObject()) {
+            const QJsonObject object = qtLibExecsDirectory.toObject();
+            for (auto it = object.constBegin(); it != object.constEnd(); ++it) {
+                if (it.value().isUndefined()) {
+                    fprintf(stderr, "Invalid architecture: %s\n",
+                            qPrintable(it.value().toString()));
+                    return false;
+                }
+                if (it.value().isNull())
+                    continue;
+                if (!options->architectures.contains(it.key())) {
+                    fprintf(stderr, "Architecture %s unknown (%s).", qPrintable(it.key()),
+                        qPrintable(options->architectures.keys().join(u',')));
+                    return false;
+                }
+                options->architectures[it.key()].qtLibExecsDirectory = it.value().toString();
+            }
+        } else if (qtLibExecsDirectory.isString()) {
+            // Format for Qt < 6 or when using the tool with Qt >= 6 but in single arch.
+            // We assume Qt > 5.14 where all architectures are in the same directory.
+            const QString directory = qtLibExecsDirectory.toString();
+            options->architectures["arm64-v8a"_L1].qtLibExecsDirectory = directory;
+            options->architectures["armeabi-v7a"_L1].qtLibExecsDirectory = directory;
+            options->architectures["x86"_L1].qtLibExecsDirectory = directory;
+            options->architectures["x86_64"_L1].qtLibExecsDirectory = directory;
+        } else {
+            fprintf(stderr, "Invalid format for Qt LibExecs install prefixes in json file %s.\n",
+                    qPrintable(options->inputFileName));
+            return false;
+        }
+    }
+
+    {
+        const QJsonValue qtPluginsDirectory = jsonObject.value("qtPluginsDirectory"_L1);
+        if (qtPluginsDirectory.isUndefined()) {
+            fprintf(stderr, "No Qt Plugins directory in json file %s\n", qPrintable(options->inputFileName));
+            return false;
+        }
+
+        if (qtPluginsDirectory.isObject()) {
+            const QJsonObject object = qtPluginsDirectory.toObject();
+            for (auto it = object.constBegin(); it != object.constEnd(); ++it) {
+                if (it.value().isUndefined()) {
+                    fprintf(stderr, "Invalid architecture: %s\n",
+                            qPrintable(it.value().toString()));
+                    return false;
+                }
+                if (it.value().isNull())
+                    continue;
+                if (!options->architectures.contains(it.key())) {
+                    fprintf(stderr, "Architecture %s unknown (%s).", qPrintable(it.key()),
+                        qPrintable(options->architectures.keys().join(u',')));
+                    return false;
+                }
+                options->architectures[it.key()].qtPluginsDirectory = it.value().toString();
+            }
+        } else if (qtPluginsDirectory.isString()) {
+            // Format for Qt < 6 or when using the tool with Qt >= 6 but in single arch.
+            // We assume Qt > 5.14 where all architectures are in the same directory.
+            const QString directory = qtPluginsDirectory.toString();
+            options->architectures["arm64-v8a"_L1].qtPluginsDirectory = directory;
+            options->architectures["armeabi-v7a"_L1].qtPluginsDirectory = directory;
+            options->architectures["x86"_L1].qtPluginsDirectory = directory;
+            options->architectures["x86_64"_L1].qtPluginsDirectory = directory;
+        } else {
+            fprintf(stderr, "Invalid format for Qt Plugins install prefixes in json file %s.\n",
+                    qPrintable(options->inputFileName));
+            return false;
+        }
+    }
+
+    {
+        const QJsonValue qtQmlDirectory = jsonObject.value("qtQmlDirectory"_L1);
+        if (qtQmlDirectory.isUndefined()) {
+            fprintf(stderr, "No Qt Qml directory in json file %s\n", qPrintable(options->inputFileName));
+            return false;
+        }
+
+        if (qtQmlDirectory.isObject()) {
+            const QJsonObject object = qtQmlDirectory.toObject();
+            for (auto it = object.constBegin(); it != object.constEnd(); ++it) {
+                if (it.value().isUndefined()) {
+                    fprintf(stderr, "Invalid architecture: %s\n",
+                            qPrintable(it.value().toString()));
+                    return false;
+                }
+                if (it.value().isNull())
+                    continue;
+                if (!options->architectures.contains(it.key())) {
+                    fprintf(stderr, "Architecture %s unknown (%s).", qPrintable(it.key()),
+                        qPrintable(options->architectures.keys().join(u',')));
+                    return false;
+                }
+                options->architectures[it.key()].qtQmlDirectory = it.value().toString();
+            }
+        } else if (qtQmlDirectory.isString()) {
+            // Format for Qt < 6 or when using the tool with Qt >= 6 but in single arch.
+            // We assume Qt > 5.14 where all architectures are in the same directory.
+            const QString directory = qtQmlDirectory.toString();
+            options->architectures["arm64-v8a"_L1].qtQmlDirectory = directory;
+            options->architectures["armeabi-v7a"_L1].qtQmlDirectory = directory;
+            options->architectures["x86"_L1].qtQmlDirectory = directory;
+            options->architectures["x86_64"_L1].qtQmlDirectory = directory;
+        } else {
+            fprintf(stderr, "Invalid format for Qt Qml install prefixes in json file %s.\n",
+                    qPrintable(options->inputFileName));
+            return false;
+        }
+    }
+
     {
         const QJsonValue qtHostDirectory = jsonObject.value("qtHostDir"_L1);
         if (!qtHostDirectory.isUndefined()) {
@@ -1211,13 +1435,13 @@
     if (!options.androidSourceDirectory.isEmpty())
         cleanTopFolders(options, QDir(options.androidSourceDirectory), options.outputDirectory);
 
-    cleanTopFolders(options, QDir(options.qtInstallDirectory + "/src/android/templates"_L1),
+    cleanTopFolders(options, QDir(options.qtDataDirectory + "/src/android/templates"_L1),
                     options.outputDirectory);
 }
 
 bool copyAndroidTemplate(const Options &options, const QString &androidTemplate, const QString &outDirPrefix = QString())
 {
-    QDir sourceDirectory(options.qtInstallDirectory + androidTemplate);
+    QDir sourceDirectory(options.qtDataDirectory + androidTemplate);
     if (!sourceDirectory.exists()) {
         fprintf(stderr, "Cannot find template directory %s\n", qPrintable(sourceDirectory.absolutePath()));
         return false;
@@ -1235,7 +1459,7 @@
 
 bool copyGradleTemplate(const Options &options)
 {
-    QDir sourceDirectory(options.qtInstallDirectory + "/src/3rdparty/gradle"_L1);
+    QDir sourceDirectory(options.qtDataDirectory + "/src/3rdparty/gradle"_L1);
     if (!sourceDirectory.exists()) {
         fprintf(stderr, "Cannot find template directory %s\n", qPrintable(sourceDirectory.absolutePath()));
         return false;
@@ -1693,6 +1917,22 @@
         }
     }
 
+    if (relativeFileName.startsWith("lib/"_L1)) {
+        return options->qtLibsDirectory + u'/' + relativeFileName.mid(sizeof("lib/") - 1);
+    }
+
+    if (relativeFileName.startsWith("plugins/"_L1)) {
+        return options->qtPluginsDirectory + u'/' + relativeFileName.mid(sizeof("plugins/") - 1);
+    }
+
+    if (relativeFileName.endsWith("-android-dependencies.xml"_L1)) {
+        return options->qtLibsDirectory + u'/' + relativeFileName;
+    }
+
+    if (relativeFileName.startsWith("jar/"_L1)) {
+        return options->qtDataDirectory + u'/' + relativeFileName;
+    }
+
     for (const auto &prefix : options->extraPrefixDirs) {
         const QString path = prefix + u'/' + relativeFileName;
         if (QFile::exists(path))
@@ -1731,8 +1971,9 @@
         if (info.exists())
             return findFilesRecursively(options, info, prefix + u'/');
     }
-    QFileInfo info(options.qtInstallDirectory + u'/' + fileName);
-    return findFilesRecursively(options, info, options.qtInstallDirectory + u'/');
+    QFileInfo info(options.qtPluginsDirectory + "/../"_L1 + fileName);
+    QFileInfo rootPath(options.qtPluginsDirectory + "/../"_L1);
+    return findFilesRecursively(options, info, rootPath.absolutePath() + u'/');
 }
 
 bool readAndroidDependencyXml(Options *options,
@@ -1740,7 +1981,7 @@
                               QSet<QString> *usedDependencies,
                               QSet<QString> *remainingDependencies)
 {
-    QString androidDependencyName = absoluteFilePath(options, "/lib/%1-android-dependencies.xml"_L1.arg(moduleName));
+    QString androidDependencyName = absoluteFilePath(options, "%1-android-dependencies.xml"_L1.arg(moduleName));
 
     QFile androidDependencyFile(androidDependencyName);
     if (androidDependencyFile.exists()) {
@@ -1942,8 +2183,7 @@
     if (!options->qmlImportScannerBinaryPath.isEmpty()) {
         qmlImportScanner = options->qmlImportScannerBinaryPath;
     } else {
-        qmlImportScanner = execSuffixAppended(options->qtInstallDirectory + u'/'
-                                              + defaultLibexecDir() + "/qmlimportscanner"_L1);
+        qmlImportScanner = execSuffixAppended(options->qtLibExecsDirectory + "/qmlimportscanner"_L1);
     }
 
     QStringList importPaths;
@@ -1952,7 +2192,7 @@
     // lacks a qml directory. We don't want to pass it as an import path if it doesn't exist
     // because it will cause qmlimportscanner to fail.
     // This also covers the case when only qtbase is installed in a regular Qt build.
-    const QString mainImportPath = options->qtInstallDirectory + "/qml"_L1;
+    const QString mainImportPath = options->qtQmlDirectory;
     if (QFile::exists(mainImportPath))
         importPaths += shellQuote(mainImportPath);
 
@@ -2211,8 +2451,7 @@
     if (!options.rccBinaryPath.isEmpty()) {
         rcc = options.rccBinaryPath;
     } else {
-        rcc = execSuffixAppended(options.qtInstallDirectory + u'/' + defaultLibexecDir() +
-                                 "/rcc"_L1);
+        rcc = execSuffixAppended(options.qtLibExecsDirectory + "/rcc"_L1);
     }
 
     if (!QFile::exists(rcc)) {
@@ -2591,11 +2830,11 @@
     GradleProperties gradleProperties = readGradleProperties(gradlePropertiesPath);
     gradleProperties["android.bundle.enableUncompressedNativeLibs"] = "false";
     gradleProperties["buildDir"] = "build";
-    gradleProperties["qtAndroidDir"] = (options.qtInstallDirectory + "/src/android/java"_L1).toUtf8();
+    gradleProperties["qtAndroidDir"] = (options.qtDataDirectory + "/src/android/java"_L1).toUtf8();
     // The following property "qt5AndroidDir" is only for compatibility.
     // Projects using a custom build.gradle file may use this variable.
     // ### Qt7: Remove the following line
-    gradleProperties["qt5AndroidDir"] = (options.qtInstallDirectory + "/src/android/java"_L1).toUtf8();
+    gradleProperties["qt5AndroidDir"] = (options.qtDataDirectory + "/src/android/java"_L1).toUtf8();
     gradleProperties["androidCompileSdkVersion"] = options.androidPlatform.split(u'-').last().toLocal8Bit();
     gradleProperties["qtMinSdkVersion"] = options.minSdkVersion;
     gradleProperties["qtTargetSdkVersion"] = options.targetSdkVersion;
@@ -3138,7 +3377,14 @@
     for (auto it = options.architectures.constBegin(); it != options.architectures.constEnd(); ++it) {
         if (!it->enabled)
             continue;
-        options.setCurrentQtArchitecture(it.key(), it.value().qtInstallDirectory);
+        options.setCurrentQtArchitecture(it.key(),
+                                         it.value().qtInstallDirectory,
+                                         it.value().qtDataDirectory,
+                                         it.value().qtLibsDirectory,
+                                         it.value().qtLibExecsDirectory,
+                                         it.value().qtPluginsDirectory,
+                                         it.value().qtQmlDirectory
+        );
 
         // All architectures have a copy of the gradle files but only one set needs to be copied.
         if (!androidTemplatetCopied && options.build && !options.auxMode && !options.copyDependenciesOnly) {
--- a/qtbase/mkspecs/features/android/android_deployment_settings.prf
+++ b/qtbase/mkspecs/features/android/android_deployment_settings.prf
@@ -8,6 +8,11 @@
     FILE_CONTENT += "   \"description\": \"This file is generated by qmake to be read by androiddeployqt and should not be modified by hand.\","
 
     FILE_CONTENT += "   \"qt\": $$emitString($$[QT_INSTALL_PREFIX]),"
+    FILE_CONTENT += "   \"qtDataDirectory\": $$emitString($$[QT_INSTALL_DATA]),"
+    FILE_CONTENT += "   \"qtLibExecsDirectory\": $$emitString($$[QT_INSTALL_LIBEXECS]),"
+    FILE_CONTENT += "   \"qtLibsDirectory\": $$emitString($$[QT_INSTALL_LIBS]),"
+    FILE_CONTENT += "   \"qtPluginsDirectory\": $$emitString($$[QT_INSTALL_PLUGINS]),"
+    FILE_CONTENT += "   \"qtQmlDirectory\": $$emitString($$[QT_INSTALL_QML]),"
 
     # Settings from mkspecs/environment
     FILE_CONTENT += "   \"sdk\": $$emitString($$ANDROID_SDK_ROOT),"
--- a/qtbase/src/corelib/Qt6AndroidMacros.cmake
+++ b/qtbase/src/corelib/Qt6AndroidMacros.cmake
@@ -126,24 +126,79 @@
     endif()
     foreach(abi IN LISTS qt_android_abis)
         _qt_internal_get_android_abi_path(qt_abi_path ${abi})
+        _qt_internal_get_android_abi_subdir_path(qt_abi_data_path QT6_INSTALL_DATA ${abi})
+        _qt_internal_get_android_abi_subdir_path(qt_abi_libexec_path QT6_INSTALL_LIBEXECS ${abi})
+        _qt_internal_get_android_abi_subdir_path(qt_abi_libs_path QT6_INSTALL_LIBS ${abi})
+        _qt_internal_get_android_abi_subdir_path(qt_abi_plugins_path QT6_INSTALL_PLUGINS ${abi})
+        _qt_internal_get_android_abi_subdir_path(qt_abi_qml_path QT6_INSTALL_QML ${abi})
         file(TO_CMAKE_PATH "${qt_abi_path}" qt_android_install_dir_native)
+        file(TO_CMAKE_PATH "${qt_abi_data_path}" qt_android_data_dir_native)
+        file(TO_CMAKE_PATH "${qt_abi_libexec_path}" qt_android_libexecs_dir_native)
+        file(TO_CMAKE_PATH "${qt_abi_libs_path}" qt_android_libs_dir_native)
+        file(TO_CMAKE_PATH "${qt_abi_plugins_path}" qt_android_plugins_dir_native)
+        file(TO_CMAKE_PATH "${qt_abi_qml_path}" qt_android_qml_dir_native)
         list(APPEND abi_records "\"${abi}\": \"${qt_android_install_dir_native}\"")
+        list(APPEND abi_records_data "\"${abi}\": \"${qt_android_install_dir_native}/${qt_android_data_dir_native}\"")
+        list(APPEND abi_records_libexecs "\"${abi}\": \"${qt_android_install_dir_native}/${qt_android_libexecs_dir_native}\"")
+        list(APPEND abi_records_libs "\"${abi}\": \"${qt_android_install_dir_native}/${qt_android_libs_dir_native}\"")
+        list(APPEND abi_records_plugins "\"${abi}\": \"${qt_android_install_dir_native}/${qt_android_plugins_dir_native}\"")
+        list(APPEND abi_records_qml "\"${abi}\": \"${qt_android_install_dir_native}/${qt_android_qml_dir_native}\"")
     endforeach()
 
     # Required to build unit tests in developer build
     if(QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX)
         set(qt_android_install_dir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}")
+        set(qt_android_data_dir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${QT6_INSTALL_DATA}")
+        set(qt_android_libexecs_dir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${QT6_INSTALL_LIBEXECS}")
+        set(qt_android_libs_dir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${QT6_INSTALL_LIBS}")
+        set(qt_android_plugins_dir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}")
+        set(qt_android_qml_dir "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${QT6_INSTALL_QML}")
     else()
         set(qt_android_install_dir "${QT6_INSTALL_PREFIX}")
+        set(qt_android_data_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_DATA}")
+        set(qt_android_libexecs_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_LIBEXECS}")
+        set(qt_android_libs_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_LIBS}")
+        set(qt_android_plugins_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_PLUGINS}")
+        set(qt_android_qml_dir "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_QML}")
     endif()
     file(TO_CMAKE_PATH "${qt_android_install_dir}" qt_android_install_dir_native)
+    file(TO_CMAKE_PATH "${qt_android_data_dir}" qt_android_data_dir_native)
+    file(TO_CMAKE_PATH "${qt_android_libexecs_dir}" qt_android_libexecs_dir_native)
+    file(TO_CMAKE_PATH "${qt_android_libs_dir}" qt_android_libs_dir_native)
+    file(TO_CMAKE_PATH "${qt_android_plugins_dir}" qt_android_plugins_dir_native)
+    file(TO_CMAKE_PATH "${qt_android_qml_dir}" qt_android_qml_dir_native)
     list(APPEND abi_records "\"${CMAKE_ANDROID_ARCH_ABI}\": \"${qt_android_install_dir_native}\"")
+    list(APPEND abi_records_data "\"${CMAKE_ANDROID_ARCH_ABI}\": \"${qt_android_data_dir_native}\"")
+    list(APPEND abi_records_libexecs "\"${CMAKE_ANDROID_ARCH_ABI}\": \"${qt_android_libexecs_dir_native}\"")
+    list(APPEND abi_records_libs "\"${CMAKE_ANDROID_ARCH_ABI}\": \"${qt_android_libs_dir_native}\"")
+    list(APPEND abi_records_plugins "\"${CMAKE_ANDROID_ARCH_ABI}\": \"${qt_android_plugins_dir_native}\"")
+    list(APPEND abi_records_qml "\"${CMAKE_ANDROID_ARCH_ABI}\": \"${qt_android_qml_dir_native}\"")
 
     list(JOIN abi_records "," qt_android_install_dir_records)
+    list(JOIN abi_records_data "," qt_android_data_dir_records)
+    list(JOIN abi_records_libexecs "," qt_android_libexecs_dir_records)
+    list(JOIN abi_records_libs "," qt_android_libs_dir_records)
+    list(JOIN abi_records_plugins "," qt_android_plugins_dir_records)
+    list(JOIN abi_records_qml "," qt_android_qml_dir_records)
     set(qt_android_install_dir_records "{${qt_android_install_dir_records}}")
+    set(qt_android_data_dir_records "{${qt_android_data_dir_records}}")
+    set(qt_android_libexecs_dir_records "{${qt_android_libexecs_dir_records}}")
+    set(qt_android_libs_dir_records "{${qt_android_libs_dir_records}}")
+    set(qt_android_plugins_dir_records "{${qt_android_plugins_dir_records}}")
+    set(qt_android_qml_dir_records "{${qt_android_qml_dir_records}}")
 
     string(APPEND file_contents
         "   \"qt\": ${qt_android_install_dir_records},\n")
+    string(APPEND file_contents
+        "   \"qtDataDirectory\": ${qt_android_data_dir_records},\n")
+    string(APPEND file_contents
+        "   \"qtLibExecsDirectory\": ${qt_android_libexecs_dir_records},\n")
+    string(APPEND file_contents
+        "   \"qtLibsDirectory\": ${qt_android_libs_dir_records},\n")
+    string(APPEND file_contents
+        "   \"qtPluginsDirectory\": ${qt_android_plugins_dir_records},\n")
+    string(APPEND file_contents
+        "   \"qtQmlDirectory\": ${qt_android_qml_dir_records},\n")
 
     # Android SDK path
     file(TO_CMAKE_PATH "${ANDROID_SDK_ROOT}" android_sdk_root_native)
@@ -259,6 +314,10 @@
     # Override rcc binary path
     _qt_internal_add_tool_to_android_deployment_settings(file_contents rcc "rcc-binary" "${target}")
 
+    # Override qmlimportscanner binary path
+    find_package(Qt6Qml)
+    _qt_internal_add_tool_to_android_deployment_settings(file_contents qmlimportscanner "qml-importscanner-binary" "${target}")
+
     # Extra prefix paths
     foreach(prefix IN LISTS CMAKE_FIND_ROOT_PATH)
         if (NOT "${prefix}" STREQUAL "${qt_android_install_dir_native}"
@@ -866,6 +925,27 @@
     set(${out_path} "${${out_path}}" PARENT_SCOPE)
 endfunction()
 
+function(_qt_internal_get_android_abi_toolchain_path out_path abi)
+    if(DEFINED QT_PATH_CMAKE_DIR_ANDROID_ABI_${abi})
+        get_filename_component(TOOLCHAIN_PATH "${QT_PATH_CMAKE_DIR_ANDROID_ABI_${abi}}/${QT_CMAKE_EXPORT_NAMESPACE}/qt.toolchain.cmake" ABSOLUTE)
+    else()
+        _qt_internal_get_android_abi_path(path ${abi})
+        get_filename_component(TOOLCHAIN_PATH "${path}/lib/cmake/${QT_CMAKE_EXPORT_NAMESPACE}/qt.toolchain.cmake" ABSOLUTE)
+    endif()
+    set(${out_path} "${TOOLCHAIN_PATH}" PARENT_SCOPE)
+endfunction()
+
+function(_qt_internal_get_android_abi_subdir_path out_path subdir abi)
+    if(DEFINED QT_PATH_CMAKE_DIR_ANDROID_ABI_${abi})
+        get_filename_component(abi_config "${QT_PATH_CMAKE_DIR_ANDROID_ABI_${abi}}/${QT_CMAKE_EXPORT_NAMESPACE}Core/${QT_CMAKE_EXPORT_NAMESPACE}CoreConfigExtras.cmake" ABSOLUTE)
+    else()
+        _qt_internal_get_android_abi_path(path ${abi})
+        get_filename_component(abi_config "${path}/lib/cmake/${QT_CMAKE_EXPORT_NAMESPACE}Core/${QT_CMAKE_EXPORT_NAMESPACE}CoreConfigExtras.cmake" ABSOLUTE)
+    endif()
+    include(${abi_config})
+    set(${out_path} "${${subdir}}" PARENT_SCOPE)
+endfunction()
+
 # The function collects list of existing Qt for Android using _qt_internal_get_android_abi_path
 # and pre-defined set of known Android ABIs. The result is written to QT_DEFAULT_ANDROID_ABIS
 # cache variable.
@@ -876,9 +956,9 @@
 
     set(default_abis)
     foreach(abi IN LISTS known_android_abis)
-        _qt_internal_get_android_abi_path(qt_abi_path ${abi})
+        _qt_internal_get_android_abi_toolchain_path(qt_abi_toolchain_path ${abi})
         # It's expected that Qt for Android contains ABI specific toolchain file.
-        if(EXISTS "${qt_abi_path}/lib/cmake/${QT_CMAKE_EXPORT_NAMESPACE}/qt.toolchain.cmake"
+        if(EXISTS "${qt_abi_toolchain_path}"
             OR CMAKE_ANDROID_ARCH_ABI STREQUAL abi)
             list(APPEND default_abis ${abi})
         endif()
@@ -1011,8 +1091,7 @@
         if(NOT abi_external_projects
             OR NOT "qt_internal_android_${abi}" IN_LIST abi_external_projects)
             _qt_internal_get_android_abi_path(qt_abi_path ${abi})
-            set(qt_abi_toolchain_path
-                "${qt_abi_path}/lib/cmake/${QT_CMAKE_EXPORT_NAMESPACE}/qt.toolchain.cmake")
+            _qt_internal_get_android_abi_toolchain_path(qt_abi_toolchain_path ${abi})
             ExternalProject_Add("qt_internal_android_${abi}"
                 SOURCE_DIR "${CMAKE_SOURCE_DIR}"
                 BINARY_DIR "${android_abi_build_dir}"
@@ -1078,7 +1157,9 @@
         message(FATAL_ERROR "Cannot find toolchain files for the manually specified Android"
             " ABIs: ${missing_qt_abi_toolchains_string}"
             "\nNote that you also may manually specify the path to the required Qt for"
-            " Android ABI using QT_PATH_ANDROID_ABI_<abi> CMake variable.\n")
+            " Android ABI using QT_PATH_ANDROID_ABI_<abi> CMake variable with the value"
+            " of the installation prefix, and QT_PATH_CMAKE_DIR_ANDROID_ABI_<abi> with"
+            " the location of the cmake directory for that ABI.\n")
     endif()
 
     list(JOIN android_abis ", " android_abis_string)
--- a/qtbase/src/network/android/jar/CMakeLists.txt
+++ b/qtbase/src/network/android/jar/CMakeLists.txt
@@ -10,8 +10,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtBase_VERSION_MAJOR}AndroidNetwork # special case
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtbase/src/plugins/networkinformation/android/CMakeLists.txt
+++ b/qtbase/src/plugins/networkinformation/android/CMakeLists.txt
@@ -9,8 +9,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtBase_VERSION_MAJOR}AndroidNetworkInformationBackend
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtconnectivity/src/android/bluetooth/CMakeLists.txt
+++ b/qtconnectivity/src/android/bluetooth/CMakeLists.txt
@@ -15,8 +15,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtConnectivity_VERSION_MAJOR}AndroidBluetooth
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtconnectivity/src/android/nfc/CMakeLists.txt
+++ b/qtconnectivity/src/android/nfc/CMakeLists.txt
@@ -11,8 +11,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtConnectivity_VERSION_MAJOR}AndroidNfc
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtmultimedia/src/android/jar/CMakeLists.txt
+++ b/qtmultimedia/src/android/jar/CMakeLists.txt
@@ -17,8 +17,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtMultimedia_VERSION_MAJOR}AndroidMultimedia
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtpositioning/src/plugins/position/android/jar/CMakeLists.txt
+++ b/qtpositioning/src/plugins/position/android/jar/CMakeLists.txt
@@ -10,8 +10,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(Qt${QtLocation_VERSION_MAJOR}AndroidPositioning # special case
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtwebview/src/jar/CMakeLists.txt
+++ b/qtwebview/src/jar/CMakeLists.txt
@@ -5,8 +5,10 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(QtAndroidWebView
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
 
--- a/qtspeech/src/plugins/tts/android/jar/CMakeLists.txt
+++ b/qtspeech/src/plugins/tts/android/jar/CMakeLists.txt
@@ -10,7 +10,9 @@
     OUTPUT_DIR "${QT_BUILD_DIR}/jar"
 )
 
+qt_path_join(destination ${INSTALL_DATADIR} "jar")
+
 install_jar(QtAndroidTextToSpeech
-    DESTINATION jar
+    DESTINATION ${destination}
     COMPONENT Devel
 )
