diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 6892b95c36..597c78f34b 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -543,6 +543,7 @@ class AndroidDevice extends Device { return LaunchResult.failed(); } + AndroidApk? builtPackage = package; AndroidArch androidArch; switch (devicePlatform) { case TargetPlatform.android_arm: @@ -587,18 +588,18 @@ class AndroidDevice extends Device { ); // Package has been built, so we can get the updated application ID and // activity name from the .apk. - package = await ApplicationPackageFactory.instance! - .getPackageForPlatform(devicePlatform, buildInfo: debuggingOptions.buildInfo) as AndroidApk; + builtPackage = await ApplicationPackageFactory.instance! + .getPackageForPlatform(devicePlatform, buildInfo: debuggingOptions.buildInfo) as AndroidApk?; } // There was a failure parsing the android project information. - if (package == null) { + if (builtPackage == null) { throwToolExit('Problem building Android application: see above error(s).'); } - _logger.printTrace("Stopping app '${package.name}' on $name."); - await stopApp(package, userIdentifier: userIdentifier); + _logger.printTrace("Stopping app '${builtPackage.name}' on $name."); + await stopApp(builtPackage, userIdentifier: userIdentifier); - if (!await installApp(package, userIdentifier: userIdentifier)) { + if (!await installApp(builtPackage, userIdentifier: userIdentifier)) { return LaunchResult.failed(); } @@ -672,7 +673,7 @@ class AndroidDevice extends Device { if (userIdentifier != null) ...['--user', userIdentifier], ], - package.launchActivity, + builtPackage.launchActivity, ]; final String result = (await runAdbCheckedAsync(cmd)).stdout; // This invocation returns 0 even when it fails. @@ -681,7 +682,7 @@ class AndroidDevice extends Device { return LaunchResult.failed(); } - _package = package; + _package = builtPackage; if (!debuggingOptions.debuggingEnabled) { return LaunchResult.succeeded(); } diff --git a/packages/flutter_tools/lib/src/application_package.dart b/packages/flutter_tools/lib/src/application_package.dart index 35bdae7248..8141092e1f 100644 --- a/packages/flutter_tools/lib/src/application_package.dart +++ b/packages/flutter_tools/lib/src/application_package.dart @@ -10,10 +10,10 @@ abstract class ApplicationPackageFactory { static ApplicationPackageFactory? get instance => context.get(); /// Create an [ApplicationPackage] for the given platform. - Future getPackageForPlatform( + Future getPackageForPlatform( TargetPlatform platform, { - BuildInfo buildInfo, - File applicationBinary, + BuildInfo? buildInfo, + File? applicationBinary, }); } diff --git a/packages/flutter_tools/lib/src/commands/install.dart b/packages/flutter_tools/lib/src/commands/install.dart index 554d57ebd4..9ad0aa57bf 100644 --- a/packages/flutter_tools/lib/src/commands/install.dart +++ b/packages/flutter_tools/lib/src/commands/install.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import '../android/android_device.dart'; import '../application_package.dart'; import '../base/common.dart'; @@ -18,8 +16,6 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts usesDeviceUserOption(); usesDeviceTimeoutOption(); argParser.addFlag('uninstall-only', - negatable: true, - defaultsTo: false, help: 'Uninstall the app if already on the device. Skip install.', ); } @@ -33,10 +29,10 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts @override final String category = FlutterCommandCategory.tools; - Device device; + Device? device; bool get uninstallOnly => boolArg('uninstall-only'); - String get userIdentifier => stringArg(FlutterOptions.kDeviceUser); + String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser); @override Future validateCommand() async { @@ -52,19 +48,23 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts @override Future runCommand() async { - final ApplicationPackage package = await applicationPackages.getPackageForPlatform( - await device.targetPlatform, + final Device targetDevice = device!; + final ApplicationPackage? package = await applicationPackages?.getPackageForPlatform( + await targetDevice.targetPlatform, ); + if (package == null) { + throwToolExit('Could not find or build package'); + } if (uninstallOnly) { - await _uninstallApp(package); + await _uninstallApp(package, targetDevice); } else { - await _installApp(package); + await _installApp(package, targetDevice); } return FlutterCommandResult.success(); } - Future _uninstallApp(ApplicationPackage package) async { + Future _uninstallApp(ApplicationPackage package, Device device) async { if (await device.isAppInstalled(package, userIdentifier: userIdentifier)) { globals.printStatus('Uninstalling $package from $device...'); if (!await device.uninstallApp(package, userIdentifier: userIdentifier)) { @@ -75,7 +75,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts } } - Future _installApp(ApplicationPackage package) async { + Future _installApp(ApplicationPackage package, Device device) async { globals.printStatus('Installing $package to $device...'); if (!await installApp(device, package, userIdentifier: userIdentifier)) { @@ -87,7 +87,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts Future installApp( Device device, ApplicationPackage package, { - String userIdentifier, + String? userIdentifier, bool uninstall = true }) async { if (package == null) { diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 53bcf189b4..3a9d229d03 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -490,7 +490,7 @@ abstract class Device { /// Specify [userIdentifier] to check if installed for a particular user (Android only). Future isAppInstalled( covariant ApplicationPackage app, { - String userIdentifier, + String? userIdentifier, }); /// Check if the latest build of the [app] is already installed. diff --git a/packages/flutter_tools/lib/src/flutter_application_package.dart b/packages/flutter_tools/lib/src/flutter_application_package.dart index e3cdf03332..a0f924bef9 100644 --- a/packages/flutter_tools/lib/src/flutter_application_package.dart +++ b/packages/flutter_tools/lib/src/flutter_application_package.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import 'android/android_sdk.dart'; @@ -28,11 +25,11 @@ import 'windows/application_package.dart'; /// A package factory that supports all Flutter target platforms. class FlutterApplicationPackageFactory extends ApplicationPackageFactory { FlutterApplicationPackageFactory({ - @required AndroidSdk androidSdk, - @required ProcessManager processManager, - @required Logger logger, - @required UserMessages userMessages, - @required FileSystem fileSystem, + required AndroidSdk androidSdk, + required ProcessManager processManager, + required Logger logger, + required UserMessages userMessages, + required FileSystem fileSystem, }) : _androidSdk = androidSdk, _processManager = processManager, _logger = logger, @@ -49,10 +46,10 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { final FileSystem _fileSystem; @override - Future getPackageForPlatform( + Future getPackageForPlatform( TargetPlatform platform, { - BuildInfo buildInfo, - File applicationBinary, + BuildInfo? buildInfo, + File? applicationBinary, }) async { switch (platform) { case TargetPlatform.android: @@ -111,7 +108,5 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { case TargetPlatform.windows_uwp_x64: return BuildableUwpApp(project: FlutterProject.current().windowsUwp); } - assert(platform != null); - return null; } } diff --git a/packages/flutter_tools/lib/src/ios/application_package.dart b/packages/flutter_tools/lib/src/ios/application_package.dart index 6693a3b86f..062e8243a8 100644 --- a/packages/flutter_tools/lib/src/ios/application_package.dart +++ b/packages/flutter_tools/lib/src/ios/application_package.dart @@ -72,7 +72,7 @@ abstract class IOSApp extends ApplicationPackage { ); } - static Future fromIosProject(IosProject project, BuildInfo buildInfo) async { + static Future fromIosProject(IosProject project, BuildInfo? buildInfo) async { if (!globals.platform.isMacOS) { return null; } @@ -109,7 +109,7 @@ class BuildableIOSApp extends IOSApp { : _hostAppBundleName = hostAppBundleName, super(projectBundleId: projectBundleId); - static Future fromProject(IosProject project, BuildInfo buildInfo) async { + static Future fromProject(IosProject project, BuildInfo? buildInfo) async { final String? hostAppBundleName = await project.hostAppBundleName(buildInfo); final String? projectBundleId = await project.productBundleIdentifier(buildInfo); if (projectBundleId != null) { diff --git a/packages/flutter_tools/lib/src/xcode_project.dart b/packages/flutter_tools/lib/src/xcode_project.dart index 494ae09506..300773c698 100644 --- a/packages/flutter_tools/lib/src/xcode_project.dart +++ b/packages/flutter_tools/lib/src/xcode_project.dart @@ -216,7 +216,7 @@ class IosProject extends XcodeBasedProject { } /// The bundle name of the host app, `My App.app`. - Future hostAppBundleName(BuildInfo buildInfo) async { + Future hostAppBundleName(BuildInfo? buildInfo) async { if (!existsSync()) { return null; } @@ -224,7 +224,7 @@ class IosProject extends XcodeBasedProject { } String? _hostAppBundleName; - Future _parseHostAppBundleName(BuildInfo buildInfo) async { + Future _parseHostAppBundleName(BuildInfo? buildInfo) async { // The product name and bundle name are derived from the display name, which the user // is instructed to change in Xcode as part of deploying to the App Store. // https://flutter.dev/docs/deployment/ios#review-xcode-project-settings diff --git a/packages/flutter_tools/test/general.shard/ios/mac_test.dart b/packages/flutter_tools/test/general.shard/ios/mac_test.dart index 682703256b..f641e655a4 100644 --- a/packages/flutter_tools/test/general.shard/ios/mac_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/mac_test.dart @@ -489,7 +489,7 @@ class FakeIosProject extends Fake implements IosProject { final File xcodeProjectInfoFile; @override - Future hostAppBundleName(BuildInfo buildInfo) async => 'UnitTestRunner.app'; + Future hostAppBundleName(BuildInfo? buildInfo) async => 'UnitTestRunner.app'; @override Directory get xcodeProject => xcodeProjectInfoFile.fileSystem.directory('Runner.xcodeproj');