Skip to content

Commit

Permalink
chore: warn users of bug when patching android releases (#2595)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Oct 30, 2024
1 parent 7eb01e5 commit 9aa9ccf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/shorebird_cli/lib/src/commands/patch/android_patcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -72,6 +83,14 @@ class AndroidPatcher extends Patcher {
Future<File> 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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -266,6 +267,7 @@ void main() {
});

group('buildPatchArtifact', () {
final flutterVersion = Version(3, 10, 6);
const flutterVersionAndRevision = '3.10.6 (83305b5088)';
late File aabFile;

Expand All @@ -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'),
Expand All @@ -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');

Expand Down

0 comments on commit 9aa9ccf

Please sign in to comment.