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 <alexey.edelev@qt.io>
This commit is contained in:
parent
c67659149f
commit
75367d1cfe
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user