Unverified Commit d9a3ced9 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Check whether we can run sdkmanager in AndroidWorkflow.licensesAccepted (#16343)

Fixes https://github.com/flutter/flutter/issues/16332
parent d121cbc8
......@@ -185,10 +185,23 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
}
}
final Process process = await runCommand(<String>[androidSdk.sdkManagerPath, '--licenses'], environment: androidSdk.sdkManagerEnv);
_ensureCanRunSdkManager();
final Process process = await runCommand(
<String>[androidSdk.sdkManagerPath, '--licenses'],
environment: androidSdk.sdkManagerEnv,
);
process.stdin.write('n\n');
final Future<void> output = process.stdout.transform(const Utf8Decoder(allowMalformed: true)).transform(const LineSplitter()).listen(_onLine).asFuture<void>(null);
final Future<void> errors = process.stderr.transform(const Utf8Decoder(allowMalformed: true)).transform(const LineSplitter()).listen(_onLine).asFuture<void>(null);
final Future<void> output = process.stdout
.transform(const Utf8Decoder(allowMalformed: true))
.transform(const LineSplitter())
.listen(_onLine)
.asFuture<void>(null);
final Future<void> errors = process.stderr
.transform(const Utf8Decoder(allowMalformed: true))
.transform(const LineSplitter())
.listen(_onLine)
.asFuture<void>(null);
try {
await Future.wait<void>(<Future<void>>[output, errors]).timeout(const Duration(seconds: 30));
} catch (TimeoutException) {
......@@ -205,12 +218,7 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
return false;
}
if (!processManager.canRun(androidSdk.sdkManagerPath))
throwToolExit(
'Android sdkmanager tool not found.\n'
'Try re-installing or updating your Android SDK,\n'
'visit https://flutter.io/setup/#android-setup for detailed instructions.'
);
_ensureCanRunSdkManager();
final Version sdkManagerVersion = new Version.parse(androidSdk.sdkManagerVersion);
if (sdkManagerVersion == null || sdkManagerVersion.major < 26)
......@@ -234,4 +242,15 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
final int exitCode = await process.exitCode;
return exitCode == 0;
}
static void _ensureCanRunSdkManager() {
assert(androidSdk != null);
final String sdkManagerPath = androidSdk.sdkManagerPath;
if (!processManager.canRun(sdkManagerPath))
throwToolExit(
'Android sdkmanager tool not found ($sdkManagerPath).\n'
'Try re-installing or updating your Android SDK,\n'
'visit https://flutter.io/setup/#android-setup for detailed instructions.'
);
}
}
......@@ -38,6 +38,20 @@ void main() {
return (List<String> command) => new MockProcess(stdout: stdoutStream);
}
testUsingContext('licensesAccepted throws if cannot run sdkmanager', () async {
processManager.succeed = false;
MockAndroidSdk.createSdkDirectory();
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
final AndroidWorkflow androidWorkflow = new AndroidWorkflow();
expect(androidWorkflow.licensesAccepted, throwsToolExit());
}, overrides: <Type, Generator>{
AndroidSdk: () => sdk,
FileSystem: () => fs,
Platform: () => new FakePlatform()..environment = <String, String>{'HOME': '/home/me'},
ProcessManager: () => processManager,
Stdio: () => stdio,
});
testUsingContext('licensesAccepted handles garbage/no output', () async {
MockAndroidSdk.createSdkDirectory();
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
......
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