Skip to content

Commit e82170f

Browse files
committed
Improved XAPK Support (#682)
1 parent 8922b1c commit e82170f

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

lib/app_sources/apkpure.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ class APKPure extends AppSource {
105105
.map((e) => e.text.trim())
106106
.map((t) => t == 'APKs' ? 'APK' : t) ??
107107
[];
108-
String type = types.isEmpty
109-
? 'APK'
110-
: types.length == 1
111-
? types.first
112-
: types.last;
108+
String type = types.isEmpty ? 'APK' : types.first;
113109
String? dateString = apkInfo
114110
?.querySelector('div.info-bottom span.time')
115111
?.text

lib/providers/apps_provider.dart

+30-16
Original file line numberDiff line numberDiff line change
@@ -644,28 +644,38 @@ class AppsProvider with ChangeNotifier {
644644
var somethingInstalled = false;
645645
try {
646646
MultiAppMultiError errors = MultiAppMultiError();
647+
List<File> APKFiles = [];
647648
for (var file in dir.extracted
648649
.listSync(recursive: true, followLinks: false)
649650
.whereType<File>()) {
650651
if (file.path.toLowerCase().endsWith('.apk')) {
651-
try {
652-
somethingInstalled = somethingInstalled ||
653-
await installApk(
654-
DownloadedApk(dir.appId, file), firstTimeWithContext,
655-
needsBGWorkaround: needsBGWorkaround,
656-
shizukuPretendToBeGooglePlay: shizukuPretendToBeGooglePlay);
657-
} catch (e) {
658-
logs.add(
659-
'Could not install APK from XAPK \'${file.path}\': ${e.toString()}');
660-
errors.add(dir.appId, e, appName: apps[dir.appId]?.name);
661-
}
652+
APKFiles.add(file);
662653
} else if (file.path.toLowerCase().endsWith('.obb')) {
663654
await moveObbFile(file, dir.appId);
664655
}
665656
}
666-
if (somethingInstalled) {
657+
APKFiles.sort((a, b) {
658+
if (a.uri.pathSegments.last.startsWith(dir.appId)) {
659+
return -1;
660+
} else {
661+
return 0;
662+
}
663+
});
664+
try {
665+
await installApk(
666+
DownloadedApk(dir.appId, APKFiles[0]), firstTimeWithContext,
667+
needsBGWorkaround: needsBGWorkaround,
668+
shizukuPretendToBeGooglePlay: shizukuPretendToBeGooglePlay,
669+
additionalAPKs: APKFiles.sublist(1)
670+
.map((a) => DownloadedApk(dir.appId, a))
671+
.toList());
672+
somethingInstalled = true;
667673
dir.file.delete(recursive: true);
668-
} else if (errors.idsByErrorString.isNotEmpty) {
674+
} catch (e) {
675+
logs.add('Could not install APKs from XAPK: ${e.toString()}');
676+
errors.add(dir.appId, e, appName: apps[dir.appId]?.name);
677+
}
678+
if (errors.idsByErrorString.isNotEmpty) {
669679
throw errors;
670680
}
671681
} finally {
@@ -677,7 +687,8 @@ class AppsProvider with ChangeNotifier {
677687
Future<bool> installApk(
678688
DownloadedApk file, BuildContext? firstTimeWithContext,
679689
{bool needsBGWorkaround = false,
680-
bool shizukuPretendToBeGooglePlay = false}) async {
690+
bool shizukuPretendToBeGooglePlay = false,
691+
List<DownloadedApk> additionalAPKs = const []}) async {
681692
if (firstTimeWithContext != null &&
682693
settingsProvider.beforeNewInstallsShareToAppVerifier &&
683694
(await getInstalledInfo('dev.soupslurpr.appverifier')) != null) {
@@ -693,6 +704,7 @@ class AppsProvider with ChangeNotifier {
693704
if (newInfo == null) {
694705
try {
695706
file.file.deleteSync(recursive: true);
707+
additionalAPKs.forEach((a) => a.file.deleteSync(recursive: true));
696708
} catch (e) {
697709
//
698710
} finally {
@@ -720,8 +732,10 @@ class AppsProvider with ChangeNotifier {
720732
}
721733
int? code;
722734
if (!settingsProvider.useShizuku) {
723-
code =
724-
await AndroidPackageInstaller.installApk(apkFilePath: file.file.path);
735+
var allAPKs = [file.file.path];
736+
allAPKs.addAll(additionalAPKs.map((a) => a.file.path));
737+
code = await AndroidPackageInstaller.installApk(
738+
apkFilePath: allAPKs.join(','));
725739
} else {
726740
code = await ShizukuApkInstaller.installAPK(file.file.uri.toString(),
727741
shizukuPretendToBeGooglePlay ? "com.android.vending" : "");

pubspec.lock

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ packages:
1414
description:
1515
path: "."
1616
ref: main
17-
resolved-ref: ba2aa7a11edc2649d1d80c25ed9291521262f714
17+
resolved-ref: bcad19e964d377da8816718032e5dbf6dd16ba3a
1818
url: "https://github.com/ImranR98/android_package_installer"
1919
source: git
2020
version: "0.0.1"
@@ -449,10 +449,10 @@ packages:
449449
dependency: "direct main"
450450
description:
451451
name: flutter_markdown
452-
sha256: f0e599ba89c9946c8e051780f0ec99aba4ba15895e0380a7ab68f420046fc44e
452+
sha256: "999a4e3cb3e1532a971c86d6c73a480264f6a687959d4887cb4e2990821827e4"
453453
url: "https://pub.dev"
454454
source: hosted
455-
version: "0.7.4+1"
455+
version: "0.7.4+2"
456456
flutter_plugin_android_lifecycle:
457457
dependency: transitive
458458
description:
@@ -731,10 +731,10 @@ packages:
731731
dependency: transitive
732732
description:
733733
name: permission_handler_html
734-
sha256: af26edbbb1f2674af65a8f4b56e1a6f526156bc273d0e65dd8075fab51c78851
734+
sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24"
735735
url: "https://pub.dev"
736736
source: hosted
737-
version: "0.1.3+2"
737+
version: "0.1.3+5"
738738
permission_handler_platform_interface:
739739
dependency: transitive
740740
description:
@@ -945,10 +945,10 @@ packages:
945945
dependency: transitive
946946
description:
947947
name: sqflite_common
948-
sha256: "4468b24876d673418a7b7147e5a08a715b4998a7ae69227acafaab762e0e5490"
948+
sha256: "761b9740ecbd4d3e66b8916d784e581861fd3c3553eda85e167bc49fdb68f709"
949949
url: "https://pub.dev"
950950
source: hosted
951-
version: "2.5.4+5"
951+
version: "2.5.4+6"
952952
sqflite_darwin:
953953
dependency: transitive
954954
description:
@@ -1145,10 +1145,10 @@ packages:
11451145
dependency: transitive
11461146
description:
11471147
name: webview_flutter_android
1148-
sha256: "86c2d01c37c4578ee46560109cf2e18fb271f0d080a796f09188d0952352e057"
1148+
sha256: "285cedfd9441267f6cca8843458620b5fda1af75b04f5818d0441acda5d7df19"
11491149
url: "https://pub.dev"
11501150
source: hosted
1151-
version: "4.0.2"
1151+
version: "4.1.0"
11521152
webview_flutter_platform_interface:
11531153
dependency: transitive
11541154
description:
@@ -1161,10 +1161,10 @@ packages:
11611161
dependency: transitive
11621162
description:
11631163
name: webview_flutter_wkwebview
1164-
sha256: "3be297aa4ca78205abdd284cf55f168c35246c75b3079990ad8ba9d257681a30"
1164+
sha256: b7e92f129482460951d96ef9a46b49db34bd2e1621685de26e9eaafd9674e7eb
11651165
url: "https://pub.dev"
11661166
source: hosted
1167-
version: "3.16.2"
1167+
version: "3.16.3"
11681168
win32:
11691169
dependency: transitive
11701170
description:

0 commit comments

Comments
 (0)