diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 0a3b9e680a5..46b52c10149 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -647,6 +647,9 @@ class AndroidDevice extends Device { @override Future stopApp(AndroidApk app) { + if (app == null) { + return Future.value(false); + } final List command = adbCommandForDevice(['shell', 'am', 'force-stop', app.id]); return processUtils.stream(command).then( (int exitCode) => exitCode == 0 || allowHeapCorruptionOnWindows(exitCode)); diff --git a/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart b/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart new file mode 100644 index 00000000000..c7fc8db9b15 --- /dev/null +++ b/packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart @@ -0,0 +1,15 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_tools/src/android/android_device.dart'; + +import '../../src/common.dart'; + +void main() { + testWithoutContext('AndroidDevice.stopApp handles a null ApplicationPackage', () async { + final AndroidDevice androidDevice = AndroidDevice('2'); + + expect(await androidDevice.stopApp(null), false); + }); +}