Add AndroidSdk.sdkManagerPath, sdkManagerVersion (#14247)
Convenience getters for the the path to the Android SDK manager and the
currently installed version of the tool.
Pre-factoring to support better checks around the --android-licenses
command, which uses a feature of the SDK manager that is unsupported in
older versions of the tool.
diff --git a/packages/flutter_tools/lib/src/android/android_sdk.dart b/packages/flutter_tools/lib/src/android/android_sdk.dart
index a3946d5..5b178b7 100644
--- a/packages/flutter_tools/lib/src/android/android_sdk.dart
+++ b/packages/flutter_tools/lib/src/android/android_sdk.dart
@@ -9,6 +9,7 @@
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
+import '../base/io.dart' show ProcessResult;
import '../base/os.dart';
import '../base/platform.dart';
import '../base/process_manager.dart';
@@ -285,6 +286,22 @@
_latestVersion = _sdkVersions.isEmpty ? null : _sdkVersions.last;
}
+ /// Returns the filesystem path of the Android SDK manager tool or null if not found.
+ String get sdkManagerPath {
+ return fs.path.join(directory, 'tools', 'bin', 'sdkmanager');
+ }
+
+ /// Returns the version of the Android SDK manager tool or null if not found.
+ String get sdkManagerVersion {
+ if (!processManager.canRun(sdkManagerPath))
+ throwToolExit('Android sdkmanager not found. Update to the latest Android SDK to resolve this.');
+ final ProcessResult result = processManager.runSync(<String>[sdkManagerPath, '--version']);
+ if (result.exitCode != 0) {
+ throwToolExit('sdkmanager --version failed: ${result.exitCode}', exitCode: result.exitCode);
+ }
+ return result.stdout.trim();
+ }
+
@override
String toString() => 'AndroidSdk: $directory';
}