Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Download the right APK for each Android device

Barnabas555126206943
diff --git a/.github/workflows/all-release.yml b/.github/workflows/all-release.yml
index c2e6784b..e111c19c 100644
--- a/.github/workflows/all-release.yml
+++ b/.github/workflows/all-release.yml
@@ -155,7 +155,12 @@ jobs:
storeFile=$RUNNER_TEMP/absorb-upload-key.jks
EOF
+ - name: Build universal and split GitHub APKs
+ if: matrix.flavor == 'github'
+ run: bash scripts/build-github-apks
+
- name: Build ${{ matrix.flavor }}
+ if: matrix.flavor != 'github'
run: flutter build ${{ matrix.build_type }} --release --flavor ${{ matrix.flavor }} --dart-define=${{ matrix.define }}
- name: Rename artifact
@@ -163,19 +168,40 @@ jobs:
FNAME: ${{ needs.prepare.outputs.fname }}
OUT_DIR: ${{ matrix.out_dir }}
EXT: ${{ matrix.ext }}
+ PRE: ${{ needs.prepare.outputs.pre }}
run: |
- SRC=$(ls "$OUT_DIR"/*.$EXT | head -1)
- DST="$OUT_DIR/${FNAME}.${EXT}"
- # gradle already names the APK absorb-<version>-<code>.apk, so the
- # source can equal the destination; only mv when they differ.
- [ "$SRC" = "$DST" ] || mv "$SRC" "$DST"
- echo "ARTIFACT=$DST" >> "$GITHUB_ENV"
+ if [ "${{ matrix.flavor }}" = "github" ]; then
+ if [ "$PRE" = "true" ]; then
+ for apk in "$OUT_DIR"/*.apk; do
+ mv "$apk" "${apk%.apk}-pre.apk"
+ done
+ fi
+ else
+ SRC=$(ls "$OUT_DIR"/*.$EXT | head -1)
+ DST="$OUT_DIR/${FNAME}.${EXT}"
+ [ "$SRC" = "$DST" ] || mv "$SRC" "$DST"
+ echo "ARTIFACT=$DST" >> "$GITHUB_ENV"
+ fi
- name: Upload to GitHub draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION_TAG: ${{ needs.prepare.outputs.tag }}
- run: gh release upload "$VERSION_TAG" "$ARTIFACT" --clobber
+ OUT_DIR: ${{ matrix.out_dir }}
+ run: |
+ if [ "${{ matrix.flavor }}" = "github" ]; then
+ shopt -s nullglob
+ UNIVERSAL=("$OUT_DIR"/*-universal*.apk)
+ ALL_APKS=("$OUT_DIR"/*.apk)
+ [ "${#UNIVERSAL[@]}" -eq 1 ] || { echo "Universal APK missing"; exit 1; }
+ gh release upload "$VERSION_TAG" "${UNIVERSAL[0]}" --clobber
+ for apk in "${ALL_APKS[@]}"; do
+ [ "$apk" = "${UNIVERSAL[0]}" ] && continue
+ gh release upload "$VERSION_TAG" "$apk" --clobber
+ done
+ else
+ gh release upload "$VERSION_TAG" "$ARTIFACT" --clobber
+ fi
# Park the AAB in Play Console as an internal-track DRAFT (nothing
# submitted or rolled out). Skips silently if the secret isn't set.
diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml
index 34ddc155..c4bb3b31 100644
--- a/.github/workflows/android-release.yml
+++ b/.github/workflows/android-release.yml
@@ -92,21 +92,22 @@ jobs:
storeFile=$RUNNER_TEMP/absorb-upload-key.jks
EOF
- - name: Build GitHub APK
- run: flutter build apk --release --flavor github --dart-define=GITHUB_BUILD=true
+ - name: Build universal and split GitHub APKs
+ run: bash scripts/build-github-apks
- name: Build Play Store AAB
run: flutter build appbundle --release --flavor playstore --dart-define=PLAYSTORE_BUILD=true
- - name: Rename APK and AAB
+ - name: Rename release artifacts
env:
FNAME: ${{ steps.version.outputs.fname }}
+ PRE: ${{ steps.version.outputs.pre }}
run: |
- # gradle already names the APK absorb-<version>-<code>.apk, so skip
- # the mv when source and destination are the same file.
- APK_SRC=$(ls build/app/outputs/apk/github/release/*.apk | head -1)
- APK_DST="build/app/outputs/apk/github/release/${FNAME}.apk"
- [ "$APK_SRC" = "$APK_DST" ] || mv "$APK_SRC" "$APK_DST"
+ if [ "$PRE" = "true" ]; then
+ for apk in build/app/outputs/apk/github/release/*.apk; do
+ mv "$apk" "${apk%.apk}-pre.apk"
+ done
+ fi
AAB_SRC=$(ls build/app/outputs/bundle/playstoreRelease/*.aab | head -1)
mv "$AAB_SRC" "build/app/outputs/bundle/playstoreRelease/${FNAME}.aab"
@@ -116,19 +117,25 @@ jobs:
VERSION_TAG: ${{ steps.version.outputs.tag }}
PRE: ${{ steps.version.outputs.pre }}
run: |
+ shopt -s nullglob
+ UNIVERSAL=(build/app/outputs/apk/github/release/*-universal*.apk)
+ ALL_APKS=(build/app/outputs/apk/github/release/*.apk)
+ AAB=(build/app/outputs/bundle/playstoreRelease/*.aab)
+ [ "${#UNIVERSAL[@]}" -eq 1 ] || { echo "Universal APK missing"; exit 1; }
if gh release view "$VERSION_TAG" &>/dev/null; then
- gh release upload "$VERSION_TAG" \
- build/app/outputs/apk/github/release/*.apk \
- build/app/outputs/bundle/playstoreRelease/*.aab \
- --clobber
+ gh release upload "$VERSION_TAG" "${UNIVERSAL[0]}" --clobber
else
CREATE_ARGS=(--draft --title "$VERSION_TAG")
[ "$PRE" = "true" ] && CREATE_ARGS+=(--prerelease)
- gh release create "$VERSION_TAG" \
- build/app/outputs/apk/github/release/*.apk \
- build/app/outputs/bundle/playstoreRelease/*.aab \
- "${CREATE_ARGS[@]}"
+ gh release create "$VERSION_TAG" "${UNIVERSAL[0]}" "${CREATE_ARGS[@]}"
fi
+ for apk in "${ALL_APKS[@]}"; do
+ [ "$apk" = "${UNIVERSAL[0]}" ] && continue
+ gh release upload "$VERSION_TAG" "$apk" --clobber
+ done
+ for aab in "${AAB[@]}"; do
+ gh release upload "$VERSION_TAG" "$aab" --clobber
+ done
- name: Notify Discord (build finished)
if: always() && env.DISCORD_WEBHOOK_URL != ''
diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml
index 248aa66c..c130ee65 100644
--- a/.github/workflows/github-release.yml
+++ b/.github/workflows/github-release.yml
@@ -91,18 +91,18 @@ jobs:
storeFile=$RUNNER_TEMP/absorb-upload-key.jks
EOF
- - name: Build GitHub APK
- run: flutter build apk --release --flavor github --dart-define=GITHUB_BUILD=true
+ - name: Build universal and split GitHub APKs
+ run: bash scripts/build-github-apks
- - name: Rename APK with version
+ - name: Mark prerelease APK names
env:
- FNAME: ${{ steps.version.outputs.fname }}
+ PRE: ${{ steps.version.outputs.pre }}
run: |
- # gradle already names the APK absorb-<version>-<code>.apk, so skip
- # the mv when source and destination are the same file.
- APK_SRC=$(ls build/app/outputs/apk/github/release/*.apk | head -1)
- APK_DST="build/app/outputs/apk/github/release/${FNAME}.apk"
- [ "$APK_SRC" = "$APK_DST" ] || mv "$APK_SRC" "$APK_DST"
+ if [ "$PRE" = "true" ]; then
+ for apk in build/app/outputs/apk/github/release/*.apk; do
+ mv "$apk" "${apk%.apk}-pre.apk"
+ done
+ fi
- name: Upload APK to GitHub draft release
env:
@@ -110,17 +110,21 @@ jobs:
VERSION_TAG: ${{ steps.version.outputs.tag }}
PRE: ${{ steps.version.outputs.pre }}
run: |
+ shopt -s nullglob
+ UNIVERSAL=(build/app/outputs/apk/github/release/*-universal*.apk)
+ ALL_APKS=(build/app/outputs/apk/github/release/*.apk)
+ [ "${#UNIVERSAL[@]}" -eq 1 ] || { echo "Universal APK missing"; exit 1; }
if gh release view "$VERSION_TAG" &>/dev/null; then
- gh release upload "$VERSION_TAG" \
- build/app/outputs/apk/github/release/*.apk \
- --clobber
+ gh release upload "$VERSION_TAG" "${UNIVERSAL[0]}" --clobber
else
CREATE_ARGS=(--draft --title "$VERSION_TAG")
[ "$PRE" = "true" ] && CREATE_ARGS+=(--prerelease)
- gh release create "$VERSION_TAG" \
- build/app/outputs/apk/github/release/*.apk \
- "${CREATE_ARGS[@]}"
+ gh release create "$VERSION_TAG" "${UNIVERSAL[0]}" "${CREATE_ARGS[@]}"
fi
+ for apk in "${ALL_APKS[@]}"; do
+ [ "$apk" = "${UNIVERSAL[0]}" ] && continue
+ gh release upload "$VERSION_TAG" "$apk" --clobber
+ done
- name: Notify Discord (build finished)
if: always() && env.DISCORD_WEBHOOK_URL != ''
diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts
index 5c9dcedc..3d92a759 100644
--- a/android/app/build.gradle.kts
+++ b/android/app/build.gradle.kts
@@ -18,6 +18,10 @@ android {
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
+ buildFeatures {
+ buildConfig = true
+ }
+
compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_17
@@ -43,6 +47,11 @@ android {
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
+ buildConfigField(
+ "int",
+ "ABSORB_BASE_VERSION_CODE",
+ flutter.versionCode.toString()
+ )
}
flavorDimensions += "distribution"
@@ -99,11 +108,14 @@ android {
val variant = this
outputs.all {
val output = this as com.android.build.gradle.internal.api.ApkVariantOutputImpl
- val abiCode = abiCodes[output.filters.find { it.filterType == "ABI" }?.identifier]
+ val abi = output.filters.find { it.filterType == "ABI" }?.identifier
+ val abiCode = abiCodes[abi]
if (abiCode != null) {
output.versionCodeOverride = variant.versionCode * 10 + abiCode
}
- output.outputFileName = "absorb-${variant.versionName}-${output.versionCode}.apk"
+ val packageKind = abi ?: "universal"
+ output.outputFileName =
+ "absorb-${variant.versionName}-${variant.versionCode}-$packageKind.apk"
}
}
}
diff --git a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
index 88ea2cc9..2f43df22 100644
--- a/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
+++ b/android/app/src/main/kotlin/com/barnabas/absorb/MainActivity.kt
@@ -129,6 +129,15 @@ class MainActivity : AudioServiceActivity() {
}
}
+ MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.absorb.update")
+ .setMethodCallHandler { call, result ->
+ when (call.method) {
+ "getBaseBuildNumber" ->
+ result.success(BuildConfig.ABSORB_BASE_VERSION_CODE)
+ else -> result.notImplemented()
+ }
+ }
+
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "com.absorb.storage")
.setMethodCallHandler { call, result ->
when (call.method) {
diff --git a/codemagic.yaml b/codemagic.yaml
index 1fb3a953..2e2c35cc 100644
--- a/codemagic.yaml
+++ b/codemagic.yaml
@@ -50,28 +50,21 @@ workflows:
keyAlias=$CM_KEY_ALIAS
storeFile=$CM_KEYSTORE_PATH
EOF
- - name: Build GitHub APK
- script: flutter build apk --release --flavor github --dart-define=GITHUB_BUILD=true
- - name: Rename APK with version
- script: |
- RAW=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //')
- APK_SRC=$(ls build/app/outputs/apk/github/release/*.apk | head -1)
- mv "$APK_SRC" "build/app/outputs/apk/github/release/absorb-${RAW//+/-}.apk"
+ - name: Build universal and split GitHub APKs
+ script: bash scripts/build-github-apks
- name: Publish to GitHub Draft Release
script: |
VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
+ UNIVERSAL=$(ls build/app/outputs/apk/github/release/*-universal*.apk)
if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
- gh release upload "$VERSION" \
- build/app/outputs/apk/github/release/*.apk \
- --clobber \
- --repo "$CM_REPO_SLUG"
+ gh release upload "$VERSION" "$UNIVERSAL" --clobber --repo "$CM_REPO_SLUG"
else
- gh release create "$VERSION" \
- build/app/outputs/apk/github/release/*.apk \
- --draft \
- --title "$VERSION" \
- --repo "$CM_REPO_SLUG"
+ gh release create "$VERSION" "$UNIVERSAL" --draft --title "$VERSION" --repo "$CM_REPO_SLUG"
fi
+ for apk in build/app/outputs/apk/github/release/*.apk; do
+ [ "$apk" = "$UNIVERSAL" ] && continue
+ gh release upload "$VERSION" "$apk" --clobber --repo "$CM_REPO_SLUG"
+ done
artifacts:
- build/app/outputs/apk/github/release/*.apk
publishing:
@@ -100,34 +93,31 @@ workflows:
keyAlias=$CM_KEY_ALIAS
storeFile=$CM_KEYSTORE_PATH
EOF
- - name: Build GitHub APK
- script: flutter build apk --release --flavor github --dart-define=GITHUB_BUILD=true
+ - name: Build universal and split GitHub APKs
+ script: bash scripts/build-github-apks
- name: Build Play Store AAB
script: flutter build appbundle --release --flavor playstore --dart-define=PLAYSTORE_BUILD=true
- - name: Rename APK and AAB with version
+ - name: Rename AAB with version
script: |
RAW=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //')
- APK_SRC=$(ls build/app/outputs/apk/github/release/*.apk | head -1)
- mv "$APK_SRC" "build/app/outputs/apk/github/release/absorb-${RAW//+/-}.apk"
AAB_SRC=$(ls build/app/outputs/bundle/playstoreRelease/*.aab | head -1)
mv "$AAB_SRC" "build/app/outputs/bundle/playstoreRelease/absorb-${RAW}.aab"
- name: Publish to GitHub Draft Release
script: |
VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
+ UNIVERSAL=$(ls build/app/outputs/apk/github/release/*-universal*.apk)
if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
- gh release upload "$VERSION" \
- build/app/outputs/apk/github/release/*.apk \
- build/app/outputs/bundle/playstoreRelease/*.aab \
- --clobber \
- --repo "$CM_REPO_SLUG"
+ gh release upload "$VERSION" "$UNIVERSAL" --clobber --repo "$CM_REPO_SLUG"
else
- gh release create "$VERSION" \
- build/app/outputs/apk/github/release/*.apk \
- build/app/outputs/bundle/playstoreRelease/*.aab \
- --draft \
- --title "$VERSION" \
- --repo "$CM_REPO_SLUG"
+ gh release create "$VERSION" "$UNIVERSAL" --draft --title "$VERSION" --repo "$CM_REPO_SLUG"
fi
+ for apk in build/app/outputs/apk/github/release/*.apk; do
+ [ "$apk" = "$UNIVERSAL" ] && continue
+ gh release upload "$VERSION" "$apk" --clobber --repo "$CM_REPO_SLUG"
+ done
+ for aab in build/app/outputs/bundle/playstoreRelease/*.aab; do
+ gh release upload "$VERSION" "$aab" --clobber --repo "$CM_REPO_SLUG"
+ done
artifacts:
- build/app/outputs/apk/github/release/*.apk
- build/app/outputs/bundle/playstoreRelease/*.aab
@@ -256,17 +246,15 @@ workflows:
EOF
- name: Set up iOS code signing
script: xcode-project use-profiles
- - name: Build GitHub APK
- script: flutter build apk --release --flavor github --dart-define=GITHUB_BUILD=true
+ - name: Build universal and split GitHub APKs
+ script: bash scripts/build-github-apks
- name: Build Play Store AAB
script: flutter build appbundle --release --flavor playstore --dart-define=PLAYSTORE_BUILD=true
- name: Build iOS IPA
script: flutter build ipa --release --export-options-plist=/Users/builder/export_options.plist
- - name: Rename APK, AAB and IPA with version
+ - name: Rename AAB and IPA with version
script: |
RAW=$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //')
- APK_SRC=$(ls build/app/outputs/apk/github/release/*.apk | head -1)
- mv "$APK_SRC" "build/app/outputs/apk/github/release/absorb-${RAW//+/-}.apk"
AAB_SRC=$(ls build/app/outputs/bundle/playstoreRelease/*.aab | head -1)
mv "$AAB_SRC" "build/app/outputs/bundle/playstoreRelease/absorb-${RAW}.aab"
IPA_SRC=$(ls build/ios/ipa/*.ipa | head -1)
@@ -274,22 +262,19 @@ workflows:
- name: Publish all to GitHub Draft Release
script: |
VERSION="v$(grep 'version:' pubspec.yaml | head -1 | sed 's/version: //' | cut -d'+' -f1)"
+ UNIVERSAL=$(ls build/app/outputs/apk/github/release/*-universal*.apk)
if gh release view "$VERSION" --repo "$CM_REPO_SLUG" &>/dev/null; then
- gh release upload "$VERSION" \
- build/app/outputs/apk/github/release/*.apk \
- build/app/outputs/bundle/playstoreRelease/*.aab \
- build/ios/ipa/*.ipa \
- --clobber \
- --repo "$CM_REPO_SLUG"
+ gh release upload "$VERSION" "$UNIVERSAL" --clobber --repo "$CM_REPO_SLUG"
else
- gh release create "$VERSION" \
- build/app/outputs/apk/github/release/*.apk \
- build/app/outputs/bundle/playstoreRelease/*.aab \
- build/ios/ipa/*.ipa \
- --draft \
- --title "$VERSION" \
- --repo "$CM_REPO_SLUG"
+ gh release create "$VERSION" "$UNIVERSAL" --draft --title "$VERSION" --repo "$CM_REPO_SLUG"
fi
+ for apk in build/app/outputs/apk/github/release/*.apk; do
+ [ "$apk" = "$UNIVERSAL" ] && continue
+ gh release upload "$VERSION" "$apk" --clobber --repo "$CM_REPO_SLUG"
+ done
+ for artifact in build/app/outputs/bundle/playstoreRelease/*.aab build/ios/ipa/*.ipa; do
+ gh release upload "$VERSION" "$artifact" --clobber --repo "$CM_REPO_SLUG"
+ done
- name: Publish to TestFlight
script: |
# Mirrors the ios-release workflow's explicit publish so this
diff --git a/lib/services/update_checker_service.dart b/lib/services/update_checker_service.dart
index 2c3804b9..60834275 100644
--- a/lib/services/update_checker_service.dart
+++ b/lib/services/update_checker_service.dart
@@ -1,13 +1,16 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
+import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:open_filex/open_filex.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
+import 'update_policy.dart';
class UpdateInfo {
final String latestVersion;
@@ -15,6 +18,8 @@ class UpdateInfo {
final String downloadUrl;
final String releaseNotes;
final bool isPreRelease;
+ final bool isDirectApk;
+ final String? packageLabel;
UpdateInfo({
required this.latestVersion,
@@ -22,30 +27,12 @@ class UpdateInfo {
required this.downloadUrl,
this.releaseNotes = '',
this.isPreRelease = false,
+ this.isDirectApk = true,
+ this.packageLabel,
});
- bool get hasUpdate => _compareVersions(latestVersion, currentVersion) > 0;
-}
-
-/// Compare versions like v1.9.1, v1.9.1-176, or 1.9.1+176: semver first, then
-/// the trailing build number. Returns positive if a > b, negative if a < b,
-/// 0 if equal. Builds only compare when both sides have one, so a clean final
-/// tag never out-ranks the beta build it was promoted from.
-int _compareVersions(String a, String b) {
- final (aSem, aBuild) = _parseVersion(a);
- final (bSem, bBuild) = _parseVersion(b);
- for (int i = 0; i < 3; i++) {
- if (aSem[i] != bSem[i]) return aSem[i] - bSem[i];
- }
- if (aBuild != null && bBuild != null) return aBuild - bBuild;
- return 0;
-}
-
-(List<int>, int?) _parseVersion(String v) {
- final sem = RegExp(r'(\d+)\.(\d+)\.(\d+)').firstMatch(v);
- final parts = [for (var i = 1; i <= 3; i++) int.parse(sem?.group(i) ?? '0')];
- final build = RegExp(r'[-+](\d+)$').firstMatch(v);
- return (parts, build == null ? null : int.parse(build.group(1)!));
+ bool get hasUpdate =>
+ compareUpdateVersions(latestVersion, currentVersion) > 0;
}
class UpdateCheckerService {
@@ -53,6 +40,7 @@ class UpdateCheckerService {
static const _checkInterval = Duration(hours: 12);
static const _dismissedKey = 'update_dismissed_version';
static const _lastCheckKey = 'update_last_check';
+ static const _updateChannel = MethodChannel('com.absorb.update');
/// Check for updates. Returns UpdateInfo if a newer version exists, null otherwise.
/// Respects a 12-hour cooldown between checks and skips dismissed versions.
@@ -96,18 +84,51 @@ class UpdateCheckerService {
final assets = data['assets'] as List<dynamic>? ?? [];
final isPreRelease = data['prerelease'] as bool? ?? false;
- // Find APK asset
- String downloadUrl = data['html_url'] as String? ?? '';
- for (final asset in assets) {
- final name = (asset['name'] as String? ?? '').toLowerCase();
- if (name.endsWith('.apk')) {
- downloadUrl = asset['browser_download_url'] as String? ?? downloadUrl;
- break;
+ final releaseAssets = <UpdateReleaseAsset>[];
+ for (final rawAsset in assets) {
+ if (rawAsset is! Map<String, dynamic>) continue;
+ final name = rawAsset['name'] as String? ?? '';
+ final url = rawAsset['browser_download_url'] as String? ?? '';
+ if (name.isNotEmpty && url.isNotEmpty) {
+ releaseAssets.add(UpdateReleaseAsset(name: name, downloadUrl: url));
}
}
final packageInfo = await PackageInfo.fromPlatform();
- final currentVersion = '${packageInfo.version}+${packageInfo.buildNumber}';
+ List<String> supportedAbis = const [];
+ int? baseBuildNumber;
+ if (!kIsWeb && Platform.isAndroid) {
+ try {
+ supportedAbis =
+ (await DeviceInfoPlugin().androidInfo).supportedAbis;
+ } catch (error) {
+ debugPrint('[UpdateChecker] ABI detection failed: $error');
+ }
+ try {
+ baseBuildNumber =
+ await _updateChannel.invokeMethod<int>('getBaseBuildNumber');
+ } catch (error) {
+ debugPrint('[UpdateChecker] Base build lookup failed: $error');
+ }
+ }
+ final selectedAsset = selectAndroidUpdateAsset(
+ assets: releaseAssets,
+ supportedAbis: supportedAbis,
+ );
+ final currentVersion = currentUpdateVersion(
+ versionName: packageInfo.version,
+ packageBuildNumber: packageInfo.buildNumber,
+ baseBuildNumber: baseBuildNumber,
+ );
+ final downloadUrl = selectedAsset?.downloadUrl ??
+ data['html_url'] as String? ??
+ '';
+ if (selectedAsset != null) {
+ debugPrint(
+ '[UpdateChecker] Selected ${selectedAsset.name} for '
+ '${supportedAbis.join(', ')}',
+ );
+ }
final info = UpdateInfo(
latestVersion: tagName,
@@ -115,6 +136,10 @@ class UpdateCheckerService {
downloadUrl: downloadUrl,
releaseNotes: body,
isPreRelease: isPreRelease,
+ isDirectApk: selectedAsset != null,
+ packageLabel: selectedAsset == null
+ ? null
+ : androidUpdatePackageLabel(selectedAsset),
);
if (!info.hasUpdate) return null;
diff --git a/lib/services/update_policy.dart b/lib/services/update_policy.dart
new file mode 100644
index 00000000..dc5156a6
--- /dev/null
+++ b/lib/services/update_policy.dart
@@ -0,0 +1,99 @@
+class UpdateReleaseAsset {
+ final String name;
+ final String downloadUrl;
+
+ const UpdateReleaseAsset({
+ required this.name,
+ required this.downloadUrl,
+ });
+}
+
+const supportedAndroidUpdateAbis = <String>{
+ 'armeabi-v7a',
+ 'arm64-v8a',
+ 'x86_64',
+};
+
+UpdateReleaseAsset? selectAndroidUpdateAsset({
+ required List<UpdateReleaseAsset> assets,
+ required List<String> supportedAbis,
+}) {
+ final apks = assets
+ .where((asset) => asset.name.toLowerCase().endsWith('.apk'))
+ .toList();
+
+ for (final abi in supportedAbis.map((value) => value.toLowerCase())) {
+ if (!supportedAndroidUpdateAbis.contains(abi)) continue;
+ for (final asset in apks) {
+ if (_hasFilenameToken(asset.name, abi)) return asset;
+ }
+ }
+
+ for (final asset in apks) {
+ if (_hasFilenameToken(asset.name, 'universal')) return asset;
+ }
+
+ if (apks.length == 1 &&
+ !supportedAndroidUpdateAbis.any(
+ (abi) => _hasFilenameToken(apks.single.name, abi),
+ )) {
+ return apks.single;
+ }
+ return null;
+}
+
+String currentUpdateVersion({
+ required String versionName,
+ required String packageBuildNumber,
+ int? baseBuildNumber,
+}) {
+ final build = baseBuildNumber != null && baseBuildNumber > 0
+ ? baseBuildNumber.toString()
+ : packageBuildNumber;
+ return '$versionName+$build';
+}
+
+int compareUpdateVersions(String a, String b) {
+ final (aSem, aBuild) = _parseVersion(a);
+ final (bSem, bBuild) = _parseVersion(b);
+ for (int i = 0; i < 3; i++) {
+ if (aSem[i] != bSem[i]) return aSem[i] - bSem[i];
+ }
+ if (aBuild != null && bBuild != null) return aBuild - bBuild;
+ return 0;
+}
+
+String androidUpdatePackageLabel(UpdateReleaseAsset asset) {
+ var packageKind = 'Universal';
+ for (final abi in supportedAndroidUpdateAbis) {
+ if (_hasFilenameToken(asset.name, abi)) {
+ packageKind = abi;
+ break;
+ }
+ }
+
+ final build = RegExp(
+ r'-(\d+)-(?:universal|armeabi-v7a|arm64-v8a|x86_64)(?:-pre)?\.apk$',
+ caseSensitive: false,
+ ).firstMatch(asset.name)?.group(1);
+ return build == null
+ ? '$packageKind APK'
+ : '$packageKind APK • build $build';
+}
+
+bool _hasFilenameToken(String filename, String token) {
+ final pattern = RegExp(
+ '(^|[-_.])${RegExp.escape(token)}(?=[-_.]|\$)',
+ caseSensitive: false,
+ );
+ return pattern.hasMatch(filename);
+}
+
+(List<int>, int?) _parseVersion(String version) {
+ final sem = RegExp(r'(\d+)\.(\d+)\.(\d+)').firstMatch(version);
+ final parts = [
+ for (var i = 1; i <= 3; i++) int.parse(sem?.group(i) ?? '0'),
+ ];
+ final build = RegExp(r'[-+](\d+)$').firstMatch(version);
+ return (parts, build == null ? null : int.parse(build.group(1)!));
+}
diff --git a/lib/widgets/update_dialog.dart b/lib/widgets/update_dialog.dart
index db0ec863..4f55ab64 100644
--- a/lib/widgets/update_dialog.dart
+++ b/lib/widgets/update_dialog.dart
@@ -18,11 +18,21 @@ class UpdateDialog {
context: context,
builder: (ctx) => AlertDialog(
title: Text(info.isPreRelease ? l.preReleaseAvailable : l.updateAvailable),
- content: Text(l.updateDialogContent(
- info.isPreRelease ? l.updateKindPreRelease : l.updateKindVersion,
- info.latestVersion,
- info.currentVersion,
- )),
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Text(l.updateDialogContent(
+ info.isPreRelease ? l.updateKindPreRelease : l.updateKindVersion,
+ info.latestVersion,
+ info.currentVersion,
+ )),
+ if (info.packageLabel != null) ...[
+ const SizedBox(height: 12),
+ _UpdatePackageLabel(info.packageLabel!),
+ ],
+ ],
+ ),
actions: [
TextButton(
onPressed: () {
@@ -44,6 +54,13 @@ class UpdateDialog {
static Future<void> _runInstall(BuildContext context, UpdateInfo info) async {
final l = AppLocalizations.of(context)!;
+ if (!info.isDirectApk) {
+ await launchUrl(
+ Uri.parse(info.downloadUrl),
+ mode: LaunchMode.externalApplication,
+ );
+ return;
+ }
final progress = ValueNotifier<double?>(null);
unawaited(showDialog<void>(
@@ -57,6 +74,10 @@ class UpdateDialog {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
+ if (info.packageLabel != null) ...[
+ _UpdatePackageLabel(info.packageLabel!),
+ const SizedBox(height: 12),
+ ],
WavyProgressIndicator(value: p),
const SizedBox(height: 12),
Text(
@@ -103,3 +124,18 @@ class UpdateDialog {
}
}
}
+
+class _UpdatePackageLabel extends StatelessWidget {
+ final String label;
+
+ const _UpdatePackageLabel(this.label);
+
+ @override
+ Widget build(BuildContext context) => Text(
+ label,
+ textAlign: TextAlign.center,
+ style: Theme.of(context).textTheme.bodySmall?.copyWith(
+ fontWeight: FontWeight.w600,
+ ),
+ );
+}
diff --git a/scripts/build-github-apks b/scripts/build-github-apks
new file mode 100644
index 00000000..ac44ea49
--- /dev/null
+++ b/scripts/build-github-apks
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+set -eo pipefail
+
+OUT_DIR="build/app/outputs/apk/github/release"
+STAGING_DIR=$(mktemp -d)
+trap 'rm -rf "$STAGING_DIR"' EXIT
+
+FLUTTER_ARGS=()
+for arg in "$@"; do
+ if [ "$arg" != "--split-per-abi" ]; then
+ FLUTTER_ARGS+=("$arg")
+ fi
+done
+
+flutter build apk \
+ --release \
+ --flavor github \
+ --dart-define=GITHUB_BUILD=true \
+ "${FLUTTER_ARGS[@]}"
+
+shopt -s nullglob
+UNIVERSAL=("$OUT_DIR"/*-universal.apk)
+if [ "${#UNIVERSAL[@]}" -ne 1 ]; then
+ echo "Expected one universal GitHub APK, found ${#UNIVERSAL[@]}"
+ exit 1
+fi
+cp "${UNIVERSAL[0]}" "$STAGING_DIR/"
+
+flutter build apk \
+ --release \
+ --flavor github \
+ --dart-define=GITHUB_BUILD=true \
+ --split-per-abi \
+ "${FLUTTER_ARGS[@]}"
+
+mkdir -p "$OUT_DIR"
+cp "$STAGING_DIR"/*.apk "$OUT_DIR/"
+
+for package_kind in universal armeabi-v7a arm64-v8a x86_64; do
+ MATCHES=("$OUT_DIR"/*-"$package_kind".apk)
+ if [ "${#MATCHES[@]}" -ne 1 ]; then
+ echo "Expected one $package_kind GitHub APK, found ${#MATCHES[@]}"
+ exit 1
+ fi
+ echo " ${MATCHES[0]}"
+done