Improve error message when Android SDK not found
Also, look for the Android SDK in the default locations.
This commit is contained in:
@@ -49,12 +49,24 @@ class AndroidSdk {
|
||||
static AndroidSdk locateAndroidSdk() {
|
||||
// TODO: Use explicit configuration information from a metadata file?
|
||||
|
||||
String androidHomeDir;
|
||||
if (Platform.environment.containsKey('ANDROID_HOME')) {
|
||||
String homeDir = Platform.environment['ANDROID_HOME'];
|
||||
if (validSdkDirectory(homeDir))
|
||||
return new AndroidSdk(homeDir);
|
||||
if (validSdkDirectory(path.join(homeDir, 'sdk')))
|
||||
return new AndroidSdk(path.join(homeDir, 'sdk'));
|
||||
androidHomeDir = Platform.environment['ANDROID_HOME'];
|
||||
} else if (Platform.isLinux) {
|
||||
String homeDir = Platform.environment['HOME'];
|
||||
if (homeDir != null)
|
||||
androidHomeDir = '$homeDir/Android/Sdk';
|
||||
} else if (Platform.isMacOS) {
|
||||
String homeDir = Platform.environment['HOME'];
|
||||
if (homeDir != null)
|
||||
androidHomeDir = '$homeDir/Library/Android/sdk';
|
||||
}
|
||||
|
||||
if (androidHomeDir != null) {
|
||||
if (validSdkDirectory(androidHomeDir))
|
||||
return new AndroidSdk(androidHomeDir);
|
||||
if (validSdkDirectory(path.join(androidHomeDir, 'sdk')))
|
||||
return new AndroidSdk(path.join(androidHomeDir, 'sdk'));
|
||||
}
|
||||
|
||||
File aaptBin = os.which('aapt'); // in build-tools/$version/aapt
|
||||
|
||||
@@ -177,7 +177,7 @@ class ApkCommand extends FlutterCommand {
|
||||
Future<int> runInProject() async {
|
||||
// Validate that we can find an android sdk.
|
||||
if (androidSdk == null) {
|
||||
printError('No Android SDK found.');
|
||||
printError('No Android SDK found. Try setting the ANDROID_HOME environment variable.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ Future<int> buildAndroid({
|
||||
}) async {
|
||||
// Validate that we can find an android sdk.
|
||||
if (androidSdk == null) {
|
||||
printError('No Android SDK found.');
|
||||
printError('No Android SDK found. Try setting the ANDROID_HOME environment variable.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user