Unverified Commit 40a7a9cf authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Fixes a common crash in getAdbDevices when adb executable isn't found. (#22676)

Apparently, this accounts for 13% of our crashes in Beta.
parent cfc73590
......@@ -533,7 +533,13 @@ List<AndroidDevice> getAdbDevices() {
final String adbPath = getAdbPath(androidSdk);
if (adbPath == null)
return <AndroidDevice>[];
final String text = runSync(<String>[adbPath, 'devices', '-l']);
String text;
try {
text = runSync(<String>[adbPath, 'devices', '-l']);
} on ArgumentError catch (exception) {
throwToolExit('Unable to run "adb", check your Android SDK installation and '
'ANDROID_HOME environment variable: ${exception.message}');
}
final List<AndroidDevice> devices = <AndroidDevice>[];
parseADBDeviceOutput(text, devices: devices);
return devices;
......
......@@ -4,13 +4,18 @@
import 'dart:async';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_device.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart';
void main() {
group('android_device', () {
......@@ -22,6 +27,18 @@ void main() {
});
group('getAdbDevices', () {
testUsingContext('throws on missing adb path', () {
final Directory sdkDir = MockAndroidSdk.createSdkDirectory();
Config.instance.setValue('android-sdk', sdkDir.path);
final File adbExe = fs.file(getAdbPath(androidSdk));
adbExe.deleteSync();
expect(() => getAdbDevices(), throwsToolExit(message: RegExp('Unable to run "adb".*${adbExe.path}')));
}, overrides: <Type, Generator>{
AndroidSdk: () => MockAndroidSdk(),
FileSystem: () => MemoryFileSystem(),
});
testUsingContext('physical devices', () {
final List<AndroidDevice> devices = <AndroidDevice>[];
parseADBDeviceOutput('''
......
......@@ -84,7 +84,7 @@ void updateFileModificationTime(String path,
}
/// Matcher for functions that throw [ToolExit].
Matcher throwsToolExit({int exitCode, String message}) {
Matcher throwsToolExit({int exitCode, Pattern message}) {
Matcher matcher = isToolExit;
if (exitCode != null)
matcher = allOf(matcher, (ToolExit e) => e.exitCode == exitCode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment