Improves SDK Search Error Messages (#23884)
* Improves error message and adds test.
This commit is contained in:
@@ -317,14 +317,36 @@ class AndroidSdk {
|
||||
|
||||
String get avdManagerPath => getAvdManagerPath();
|
||||
|
||||
Directory get _platformsDir => fs.directory(fs.path.join(directory, 'platforms'));
|
||||
|
||||
Iterable<Directory> get _platforms {
|
||||
Iterable<Directory> platforms = <Directory>[];
|
||||
if (_platformsDir.existsSync()) {
|
||||
platforms = _platformsDir
|
||||
.listSync()
|
||||
.whereType<Directory>();
|
||||
}
|
||||
return platforms;
|
||||
}
|
||||
|
||||
/// Validate the Android SDK. This returns an empty list if there are no
|
||||
/// issues; otherwise, it returns a list of issues found.
|
||||
List<String> validateSdkWellFormed() {
|
||||
if (!processManager.canRun(adbPath))
|
||||
return <String>['Android SDK file not found: $adbPath.'];
|
||||
|
||||
if (sdkVersions.isEmpty || latestVersion == null)
|
||||
return <String>['Android SDK is missing command line tools; download from https://goo.gl/XxQghQ'];
|
||||
if (sdkVersions.isEmpty || latestVersion == null) {
|
||||
final StringBuffer msg = StringBuffer('No valid Android SDK platforms found in ${_platformsDir.path}.');
|
||||
if (_platforms.isEmpty) {
|
||||
msg.write(' Directory was empty.');
|
||||
} else {
|
||||
msg.write(' Candidates were:\n');
|
||||
msg.write(_platforms
|
||||
.map((Directory dir) => ' - ${dir.basename}')
|
||||
.join('\n'));
|
||||
}
|
||||
return <String>[msg.toString()];
|
||||
}
|
||||
|
||||
return latestVersion.validateSdkWellFormed();
|
||||
}
|
||||
@@ -355,15 +377,6 @@ class AndroidSdk {
|
||||
}
|
||||
|
||||
void _init() {
|
||||
Iterable<Directory> platforms = <Directory>[]; // android-22, ...
|
||||
|
||||
final Directory platformsDir = fs.directory(fs.path.join(directory, 'platforms'));
|
||||
if (platformsDir.existsSync()) {
|
||||
platforms = platformsDir
|
||||
.listSync()
|
||||
.whereType<Directory>();
|
||||
}
|
||||
|
||||
List<Version> buildTools = <Version>[]; // 19.1.0, 22.0.1, ...
|
||||
|
||||
final Directory buildToolsDir = fs.directory(fs.path.join(directory, 'build-tools'));
|
||||
@@ -382,7 +395,7 @@ class AndroidSdk {
|
||||
}
|
||||
|
||||
// Match up platforms with the best corresponding build-tools.
|
||||
_sdkVersions = platforms.map<AndroidSdkVersion>((Directory platformDir) {
|
||||
_sdkVersions = _platforms.map<AndroidSdkVersion>((Directory platformDir) {
|
||||
final String platformName = platformDir.basename;
|
||||
int platformVersion;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user