Skip to content

Commit c98c802

Browse files
committed
only start listener if device meets criteria
1 parent 31a1f2a commit c98c802

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

packages/flutter_tools/lib/src/ios/devices.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import 'xcodeproj.dart';
4242
const String kJITCrashFailureMessage =
4343
'Crash occurred when compiling unknown function in unoptimized JIT mode in unknown pass';
4444

45-
const String kJITCrashFailureMessageInstructions = '''
45+
const String kJITCrashFailureInstructions = '''
4646
════════════════════════════════════════════════════════════════════════════════
4747
An upcoming change to iOS has caused a temporary break in Flutter's
4848
debug mode on physical devices running iOS 18.4 (currently in beta).
@@ -762,7 +762,7 @@ class IOSDevice extends Device {
762762
});
763763
}
764764

765-
final StreamSubscription<String> errorListener = _interceptErrorsFromLogs(
765+
final StreamSubscription<String>? errorListener = _interceptErrorsFromLogs(
766766
package,
767767
debuggingOptions: debuggingOptions,
768768
);
@@ -795,16 +795,22 @@ class IOSDevice extends Device {
795795
}
796796
}
797797
maxWaitForCI?.cancel();
798-
await errorListener.cancel();
798+
await errorListener?.cancel();
799799
return localUri;
800800
}
801801

802-
/// Listen for specific errors and perform actions, such as printing guided
803-
/// messages or exiting the tool.
804-
StreamSubscription<String> _interceptErrorsFromLogs(
802+
/// Listen to device logs for crash on iOS 18.4+ due to JIT restriction. If
803+
/// found, give guided error and throw tool exit. Returns null and does not
804+
/// listen if device is less than iOS 18.4.
805+
StreamSubscription<String>? _interceptErrorsFromLogs(
805806
IOSApp? package, {
806807
required DebuggingOptions debuggingOptions,
807808
}) {
809+
// Currently only checking for kJITCrashFailureMessage, which only should
810+
// be checked on iOS 18.4+.
811+
if (sdkVersion == null || sdkVersion! < Version(18, 4, null)) {
812+
return null;
813+
}
808814
final DeviceLogReader deviceLogReader = getLogReader(
809815
app: package,
810816
usingCISystem: debuggingOptions.usingCISystem,
@@ -813,10 +819,8 @@ class IOSDevice extends Device {
813819
final Stream<String> logStream = deviceLogReader.logLines;
814820

815821
final StreamSubscription<String> errorListener = logStream.listen((String line) {
816-
if (sdkVersion != null && sdkVersion! >= Version(18, 4, null)) {
817-
if (line.contains(kJITCrashFailureMessage)) {
818-
throwToolExit(kJITCrashFailureMessageInstructions);
819-
}
822+
if (line.contains(kJITCrashFailureMessage)) {
823+
throwToolExit(kJITCrashFailureInstructions);
820824
}
821825
});
822826

packages/flutter_tools/test/general.shard/ios/ios_device_start_prebuilt_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ void main() {
11621162
return null;
11631163
},
11641164
onError: (Object error, StackTrace stack) {
1165-
expect(error.toString(), contains(kJITCrashFailureMessageInstructions));
1165+
expect(error.toString(), contains(kJITCrashFailureInstructions));
11661166
completer.complete();
11671167
},
11681168
),

0 commit comments

Comments
 (0)