From ba6a108d6056834f7824c7807bfec834a619b82e Mon Sep 17 00:00:00 2001
From: Christoph Keller <keller@conntac.net>
Date: Fri, 24 Jun 2022 14:36:30 +0200
Subject: [PATCH] Fix androiddeployqt not handling
 ANDROID_DEPLOYMENT_DEPENDENCIES correctly.

Change-Id: I012a1687c7dc18eab884ee27d748bca14343b92e
---
 src/tools/androiddeployqt/main.cpp | 65 ++++++++++++++++++------------
 1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp
index dabc5af271..a9ec89245e 100644
--- a/src/tools/androiddeployqt/main.cpp
+++ b/src/tools/androiddeployqt/main.cpp
@@ -1011,12 +1011,26 @@ bool readInputFile(Options *options)
                         }
                     }
                 } else {
-                    auto arch = fileArchitecture(*options, path);
-                    if (!arch.isEmpty()) {
-                        options->qtDependencies[arch].append(QtDependency(dependency.toString(), path));
-                    } else if (options->verbose) {
-                        fprintf(stderr, "Skipping \"%s\", unknown architecture\n", qPrintable(path));
-                        fflush(stderr);
+                    if (dependency.endsWith(QLatin1String(".so"))) {
+                        auto arch = fileArchitecture(*options, path);
+                        if (!arch.isEmpty()) {
+                            options->qtDependencies[arch].append(QtDependency(dependency.toString(), path));
+                        } else if (options->verbose) {
+                            fprintf(stderr, "Skipping \"%s\", unknown architecture\n", qPrintable(path));
+                            fflush(stderr);
+                        }
+                    } else if (dependency.endsWith(QLatin1String(".jar"))) {
+                        options->localJars.append(dependency.toString());
+
+                        for (auto arch : options->architectures.keys()) {
+                            options->qtDependencies[arch].append(QtDependency(dependency.toString(), path));
+                        }
+                    } else {
+                        // Assume all other files are architecture-independent
+                        // qmldir, .qml etc. ends up here, they will be put to android_rcc_bundle
+                        for (auto arch : options->architectures.keys()) {
+                            options->qtDependencies[arch].append(QtDependency(dependency.toString(), path));
+                        }
                     }
                 }
             }
@@ -1317,8 +1331,8 @@ bool updateLibsXml(Options *options)
         if (localLibs.isEmpty()) {
             QString plugin;
             for (const QtDependency &qtDependency : options->qtDependencies[it.key()]) {
-                if (qtDependency.relativePath.endsWith(QLatin1String("libqtforandroid.so"))
-                        || qtDependency.relativePath.endsWith(QLatin1String("libqtforandroidGL.so"))) {
+                if (qtDependency.relativePath.contains(QLatin1String("platforms_qtforandroid_"))
+                        || qtDependency.relativePath.contains(QLatin1String("platforms_qtforandroidGL_"))) {
                     if (!plugin.isEmpty() && plugin != qtDependency.relativePath) {
                         fprintf(stderr, "Both platform plugins libqtforandroid.so and libqtforandroidGL.so included in package. Please include only one.\n");
                         return false;
@@ -1329,13 +1343,12 @@ bool updateLibsXml(Options *options)
                 if (qtDependency.relativePath.contains(QLatin1String("libQt5OpenGL"))
                         || qtDependency.relativePath.contains(QLatin1String("libQt5Quick"))) {
                     options->usesOpenGL |= true;
-                    break;
                 }
             }
 
             if (plugin.isEmpty()) {
                 fflush(stdout);
-                fprintf(stderr, "No platform plugin, neither libqtforandroid.so or libqtforandroidGL.so, included in package. Please include one.\n");
+                fprintf(stderr, "No platform plugin, neither qtforandroid.so or qtforandroidGL.so, included in package. Please include one.\n");
                 fflush(stderr);
                 return false;
             } 
\ No newline at end of file
-- 
2.31.0

