diff --git a/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart b/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart index d428c138c..fbdbf8f34 100644 --- a/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart +++ b/packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:mason_logger/mason_logger.dart'; import 'package:path/path.dart' as p; +import 'package:pub_semver/pub_semver.dart'; import 'package:shorebird_cli/src/archive_analysis/android_archive_differ.dart'; import 'package:shorebird_cli/src/artifact_builder.dart'; import 'package:shorebird_cli/src/artifact_manager.dart'; @@ -35,6 +36,16 @@ class AndroidPatcher extends Patcher { required super.target, }); + /// Android versions prior to 3.24.2 have a bug that can cause patches to + /// be erroneously uninstalled. + /// https://github.com/shorebirdtech/updater/issues/211 was fixed in 3.24.2 + static final updaterPatchErrorWarning = ''' +Your version of flutter contains a known issue that can cause patches to be erroneously uninstalled in apps that use package:flutter_foreground_task or other plugins that start their own Flutter engines. +This issue was fixed in Flutter 3.24.2. Please upgrade to a newer version of Flutter to avoid this issue. + +See more info about the issue ${link(uri: Uri.parse('https://github.com/shorebirdtech/updater/issues/211'), message: 'on Github')} +'''; + @override ReleaseType get releaseType => ReleaseType.android; @@ -72,6 +83,14 @@ class AndroidPatcher extends Patcher { Future buildPatchArtifact({String? releaseVersion}) async { final File aabFile; final flutterVersionString = await shorebirdFlutter.getVersionAndRevision(); + final flutterVersion = await shorebirdFlutter.getVersion(); + // Android versions prior to 3.24.2 have a bug that can cause patches to + // be erroneously uninstalled. + // https://github.com/shorebirdtech/updater/issues/211 was fixed in 3.24.2 + if (flutterVersion != null && flutterVersion < Version(3, 24, 2)) { + logger.warn(updaterPatchErrorWarning); + } + final buildProgress = logger .detailProgress('Building patch with Flutter $flutterVersionString'); diff --git a/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart b/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart index efc2dbfbb..91e501e69 100644 --- a/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart +++ b/packages/shorebird_cli/test/src/commands/patch/android_patcher_test.dart @@ -5,6 +5,7 @@ import 'package:crypto/crypto.dart'; import 'package:mason_logger/mason_logger.dart'; import 'package:mocktail/mocktail.dart'; import 'package:path/path.dart' as p; +import 'package:pub_semver/pub_semver.dart'; import 'package:scoped_deps/scoped_deps.dart'; import 'package:shorebird_cli/src/archive_analysis/android_archive_differ.dart'; import 'package:shorebird_cli/src/artifact_builder.dart'; @@ -266,6 +267,7 @@ void main() { }); group('buildPatchArtifact', () { + final flutterVersion = Version(3, 10, 6); const flutterVersionAndRevision = '3.10.6 (83305b5088)'; late File aabFile; @@ -274,6 +276,9 @@ void main() { when( () => shorebirdFlutter.getVersionAndRevision(), ).thenAnswer((_) async => flutterVersionAndRevision); + when( + () => shorebirdFlutter.getVersion(), + ).thenAnswer((_) async => flutterVersion); when( () => artifactBuilder.buildAppBundle( flavor: any(named: 'flavor'), @@ -286,6 +291,41 @@ void main() { ).thenAnswer((_) async => aabFile); }); + // See https://github.com/shorebirdtech/updater/issues/211 + group('when flutter version contains updater issue 211', () { + setUp(() { + setUpProjectRootArtifacts(); + when( + () => shorebirdFlutter.getVersion(), + ).thenAnswer((_) async => Version(3, 24, 1)); + }); + + test('warns user of potential patch issues', () async { + await runWithOverrides(patcher.buildPatchArtifact); + + verify( + () => logger.warn(AndroidPatcher.updaterPatchErrorWarning), + ).called(1); + }); + }); + + group('when flutter version does not contain updater issue 211', () { + setUp(() { + setUpProjectRootArtifacts(); + when( + () => shorebirdFlutter.getVersion(), + ).thenAnswer((_) async => Version(3, 24, 2)); + }); + + test('does not warn user of potential patch issues', () async { + await runWithOverrides(patcher.buildPatchArtifact); + + verifyNever( + () => logger.warn(AndroidPatcher.updaterPatchErrorWarning), + ); + }); + }); + group('when build fails', () { final exception = ArtifactBuildException('error');