Handle missing Android SDKs in getEmulators() (#67295)
diff --git a/packages/flutter_tools/lib/src/android/android_emulator.dart b/packages/flutter_tools/lib/src/android/android_emulator.dart
index 43a0edd..a33dfa7 100644
--- a/packages/flutter_tools/lib/src/android/android_emulator.dart
+++ b/packages/flutter_tools/lib/src/android/android_emulator.dart
@@ -56,7 +56,7 @@
/// Return the list of available emulator AVDs.
Future<List<AndroidEmulator>> _getEmulatorAvds() async {
- final String emulatorPath = _androidSdk.emulatorPath;
+ final String emulatorPath = _androidSdk?.emulatorPath;
if (emulatorPath == null) {
return <AndroidEmulator>[];
}
diff --git a/packages/flutter_tools/test/general.shard/emulator_test.dart b/packages/flutter_tools/test/general.shard/emulator_test.dart
index b75d27d..89d6208 100644
--- a/packages/flutter_tools/test/general.shard/emulator_test.dart
+++ b/packages/flutter_tools/test/general.shard/emulator_test.dart
@@ -84,6 +84,28 @@
returnsNormally);
});
+ testUsingContext('getEmulators with no Android SDK', () async {
+ // Test that EmulatorManager.getEmulators() doesn't throw when there's no Android SDK.
+ final EmulatorManager emulatorManager = EmulatorManager(
+ fileSystem: MemoryFileSystem.test(),
+ logger: BufferLogger.test(),
+ processManager: FakeProcessManager.list(<FakeCommand>[
+ const FakeCommand(
+ command: <String>['emulator', '-list-avds'],
+ stdout: 'existing-avd-1',
+ ),
+ ]),
+ androidSdk: null,
+ androidWorkflow: AndroidWorkflow(
+ androidSdk: null,
+ featureFlags: TestFeatureFlags(),
+ ),
+ );
+
+ await expectLater(() async => await emulatorManager.getAllAvailableEmulators(),
+ returnsNormally);
+ });
+
testWithoutContext('getEmulatorsById', () async {
final TestEmulatorManager testEmulatorManager = TestEmulatorManager(emulators);