From 75367d1cfe564953d980b0c6917257f8ec0faa93 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Thu, 27 Feb 2025 12:25:34 +0200 Subject: [PATCH] Android: fix uncompressed libs loading from split APKs When split APKs, when an AAB is used for example, the native libraries are kept in a separate APK and not under the main app APK, thus, we need to use that instead to get the path of the native libs otherwise the app would crash failing to load Qt libraries. Amends 0db5b424cdaede8724886e8a1eda1380382d9aaf. Pick-to: 6.9 6.9.0 Fixes: QTBUG-134101 Change-Id: I930ba005aaefc15e4500b7290167892dc2428066 Reviewed-by: Alexey Edelev --- .../qtproject/qt/android/QtApkFileEngine.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtApkFileEngine.java b/src/android/jar/src/org/qtproject/qt/android/QtApkFileEngine.java index 4203b6a946a..78eb4d5c492 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtApkFileEngine.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtApkFileEngine.java @@ -6,6 +6,8 @@ package org.qtproject.qt.android; import android.content.Context; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; +import android.os.Build; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import java.io.FileInputStream; @@ -16,6 +18,7 @@ import java.util.zip.ZipFile; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Comparator; @@ -138,7 +141,20 @@ class QtApkFileEngine { try { Context context = QtNative.getContext(); PackageManager pm = context.getPackageManager(); - m_appApkPath = pm.getApplicationInfo(context.getPackageName(), 0).sourceDir; + ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(), 0); + if (applicationInfo.splitSourceDirs != null) { + m_appApkPath = Arrays.stream(applicationInfo.splitSourceDirs) + .filter(file -> Arrays.stream(Build.SUPPORTED_ABIS) + .anyMatch(abi -> file.endsWith(abi.replace('-', '_') + ".apk"))) + .findFirst() + .orElse(null); + + if (m_appApkPath == null) + Log.d(QtTAG, "No ABI specific split APK found, defaulting to the main APK."); + } + + if (m_appApkPath == null) + m_appApkPath = applicationInfo.sourceDir; } catch (PackageManager.NameNotFoundException e) { Log.e(QtTAG, "Failed to get the app APK path with " + e); return null;