Unverified Commit ae8586cf authored by liyuqian's avatar liyuqian Committed by GitHub

Show help info instead of crashing if Android SDK is not found (#17610)

Fixes #16832
parent c36ec760
......@@ -209,6 +209,9 @@ void updateLocalProperties({String projectPath, BuildInfo buildInfo}) {
settings = new SettingsFile.parseFromFile(localProperties);
} else {
settings = new SettingsFile();
if (androidSdk == null) {
throwToolExit('Unable to locate Android SDK. Please run `flutter doctor` for more details.');
}
settings.values['sdk.dir'] = escapePath(androidSdk.directory);
changed = true;
}
......
......@@ -7,8 +7,28 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:test/test.dart';
import '../src/common.dart';
void main() {
group('gradle build', () {
test('do not crash if there is no Android SDK', () {
Exception shouldBeToolExit;
try {
// We'd like to always set androidSdk to null and test updateLocalProperties. But that's
// currently impossible as the test is not hermetic. Luckily, our bots don't have Android
// SDKs yet so androidSdk should be null by default.
//
// This test is written to fail if our bots get Android SDKs in the future: shouldBeToolExit
// will be null and our expectation would fail. That would remind us to make these tests
// hermetic before adding Android SDKs to the bots.
updateLocalProperties();
} on Exception catch (e) {
shouldBeToolExit = e;
}
// Ensure that we throw a meaningful ToolExit instead of a general crash.
expect(shouldBeToolExit, isToolExit);
});
test('regexp should only match lines without the error message', () {
final List<String> nonMatchingLines = <String>[
'NDK is missing a "platforms" directory.',
......
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