diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 1715f655a92e..51ae79a34820 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -778,7 +778,12 @@ class AndroidDevice extends Device { @override void clearLogs() { - _processUtils.runSync(adbCommandForDevice(['logcat', '-c'])); + final RunResult result = _processUtils.runSync(adbCommandForDevice(['logcat', '-c'])); + // Do not log to standard error because that causes test to fail. + if (result.exitCode != 0) { + _logger.printTrace('"adb logcat -c" failed: exitCode: ${result.exitCode}' + ' stdout: ${result.stdout} stderr: ${result.stderr}'); + } } @override diff --git a/packages/flutter_tools/test/general.shard/android/android_device_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_test.dart index 6746dde00996..65ee261afb51 100644 --- a/packages/flutter_tools/test/general.shard/android/android_device_test.dart +++ b/packages/flutter_tools/test/general.shard/android/android_device_test.dart @@ -331,6 +331,18 @@ flutter: expect(await device.emulatorId, isNull); }); + testWithoutContext('AndroidDevice clearLogs does not crash', () async { + final AndroidDevice device = setUpAndroidDevice( + processManager: FakeProcessManager.list([ + const FakeCommand( + command: ['adb', '-s', '1234', 'logcat', '-c'], + exitCode: 1, + ), + ]) + ); + device.clearLogs(); + }); + testWithoutContext('AndroidDevice lastLogcatTimestamp returns null if shell command failed', () async { final AndroidDevice device = setUpAndroidDevice( processManager: FakeProcessManager.list([