diff --git a/packages/flutter_tools/lib/src/android/android_sdk.dart b/packages/flutter_tools/lib/src/android/android_sdk.dart index c3fec0de67..be3059d701 100644 --- a/packages/flutter_tools/lib/src/android/android_sdk.dart +++ b/packages/flutter_tools/lib/src/android/android_sdk.dart @@ -87,8 +87,9 @@ class AndroidSdk { return new AndroidSdk(fs.path.join(androidHomeDir, 'sdk')); } - File aaptBin = os.which('aapt'); // in build-tools/$version/aapt - if (aaptBin != null) { + // in build-tools/$version/aapt + final List aaptBins = os.whichAll('aapt'); + for (File aaptBin in aaptBins) { // Make sure we're using the aapt from the SDK. aaptBin = fs.file(aaptBin.resolveSymbolicLinksSync()); final String dir = aaptBin.parent.parent.parent.path; @@ -96,8 +97,9 @@ class AndroidSdk { return new AndroidSdk(dir); } - File adbBin = os.which('adb'); // in platform-tools/adb - if (adbBin != null) { + // in platform-tools/adb + final List adbBins = os.whichAll('adb'); + for (File adbBin in adbBins) { // Make sure we're using the adb from the SDK. adbBin = fs.file(adbBin.resolveSymbolicLinksSync()); final String dir = adbBin.parent.parent.path; diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index 06c7270248..74fbd8ca26 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -5,7 +5,6 @@ import 'dart:async'; import 'package:archive/archive.dart'; - import 'context.dart'; import 'file_system.dart'; import 'io.dart'; @@ -34,6 +33,28 @@ abstract class OperatingSystemUtils { /// if `which` was not able to locate the binary. File which(String execName); + /// Return a list of all paths to `execName` found on the system. Uses the + /// PATH environment variable. + List whichAll(String execName) { + final List result = []; + final String pathEnvironmentVariable = platform.environment['PATH']; + for (final String pathComponent in _splitPath(pathEnvironmentVariable)) { + final String pathToExecName = fs.path.join(pathComponent, execName); + if (processManager.canRun(pathToExecName)) { + result.add(fs.file(pathToExecName)); + } + } + return result; + } + + List _splitPath(String pathEnvironmentVariable) { + final String delimiter = platform.isWindows ? ';' : ':'; + if (pathEnvironmentVariable == null) { + return []; + } + return pathEnvironmentVariable.split(delimiter); + } + /// Return the File representing a new pipe. File makePipe(String path); diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 642adb95ba..1752264658 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -151,7 +151,10 @@ class MockSimControl extends Mock implements SimControl { } } -class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {} +class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { + @override + List whichAll(String execName) => []; +} class MockIOSSimulatorUtils extends Mock implements IOSSimulatorUtils {}