diff --git a/lib/src/orientation.dart b/lib/src/orientation.dart index e5b09455..d6a54321 100644 --- a/lib/src/orientation.dart +++ b/lib/src/orientation.dart @@ -39,7 +39,7 @@ void changeDeviceOrientation(DeviceType deviceType, Orientation orientation, 'system', 'user_rotation', androidOrientations[_orientation] - ]); + ], retry: true); break; case DeviceType.ios: // requires permission when run for first time diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 54eb558a..7fc44f0a 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert' as cnv; import 'dart:convert'; +import 'dart:io'; import 'package:path/path.dart' as p; import 'package:process/process.dart'; @@ -416,18 +417,26 @@ Future isEmulatorPath() async { /// Run command and return stdout as [string]. String cmd(List cmd, - {String workingDirectory, bool silent = true, bool trace = true}) { - final result = processManager.runSync(cmd, - workingDirectory: workingDirectory, runInShell: true); - if(trace) _traceCommand(cmd, workingDirectory: workingDirectory); - if (!silent) printStatus(result.stdout); - if (result.exitCode != 0) { - if (silent) printError(result.stdout); - printError(result.stderr); - throw 'command failed: exitcode=${result.exitCode}, cmd=\'${cmd.join(" ")}\', workingDir=$workingDirectory'; + {String workingDirectory, bool silent = true, bool trace = true, bool retry = false, int retryAttempts = 5 }) { + + StdoutException error = StdoutException(''); + for (var i = 0; i < retryAttempts; i++) { + try { + final result = processManager.runSync(cmd, workingDirectory: workingDirectory, runInShell: true); + if(trace) _traceCommand(cmd, workingDirectory: workingDirectory); + if (result.exitCode != 0) { + error = StdoutException(result.stdout, OSError(result.stderr, result.exitCode)); + throw error; + } + // return stdout + return result.stdout; + } on StdoutException catch (e) { + sleep(Duration(seconds: 5)); + } } - // return stdout - return result.stdout; + if (silent) printError(error.message); + printError(error.osError.message); + throw 'command failed: exitcode=${error.osError.errorCode}, cmd=\'${cmd.join(" ")}\', workingDir=$workingDirectory'; } /// Run command and return exit code as [int].