Skip to content

[flutter_tools] Fix flutter drive device selection for unsupported project platforms - #192444

Open
bkonyi wants to merge 10 commits into
flutter:masterfrom
bkonyi:investigation/issue-134073
Open

bkonyi wants to merge 10 commits into
flutter:masterfrom
bkonyi:investigation/issue-134073

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #134073

flutter drive previously inverted includeDevicesUnsupportedByProject (applicationBinaryPath == null), so building from source could auto-select a device whose platform the project does not support. When getPackageForPlatform then returned null, FlutterDriverService.start passed null straight to device.startApp, crashing with a covariant _TypeError (which also happened when explicitly targeting an unsupported platform with -d).

This change fixes the device-filter condition (allowing unsupported project platforms only for --use-application-binary or --use-existing-app) and makes FlutterDriverService.start throw a ToolExit with the platform's missing-package hint when no ApplicationPackage is found.

Previous output:

_TypeError: type 'Null' is not a subtype of type 'IOSApp' of 'package'

Current output (default device selection):

No supported devices connected.

The following devices were found, but are not supported by this project:
iPhone 16 Pro (mobile) • ios-sim-1 • ios • Test SDK (1.2.3) (simulator)
If you would like your app to run on ios, consider running `flutter create .` to generate projects for these platforms.

Current output (explicit -d targeting unsupported platform):

Error: No application found for TargetPlatform.ios.
Is your project missing an ios/Runner/Info.plist?
Consider running "flutter create ." to create one.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

…oject platforms

Fixes an issue where flutter drive targeted devices unsupported by the
project when building from source due to an inverted
includeDevicesUnsupportedByProject condition in DriveCommand.

Also adds defensive handling in DefaultDriverService.start when
ApplicationPackageFactory returns null.

Fixes flutter#134073
@bkonyi bkonyi added the CICD Run CI/CD label Sep 8, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 8, 2026
…-134073

# Conflicts:
#	packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart
Resolves conflicts with upstream `DriverService` DI migration by preserving `FlutterDriverService` constructor parameters and extracting `missingApplicationPackageMessage` in `resident_runner.dart` to share error formatting between `runHot`, `runCold`, and `FlutterDriverService.start`. Simplifies `drive_test.dart` using `_TestDeviceManager` and `FakeDevice`.

Fixes flutter#134073
@bkonyi
bkonyi marked this pull request as ready for review November 16, 2026 23:18

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the flutter drive command to include devices unsupported by the project when using a prebuilt application binary, while ignoring them when building from source. It also refactors the missing application package error reporting into a shared helper function and adds corresponding tests. A critical issue was identified in drive_service.dart where destructuring ToolContext with :FileSystem fs will cause a compilation error because the property is named fileSystem.

applicationBinary: applicationBinary,
);
if (_applicationPackage == null) {
final ToolContext(:FileSystem fs, :FlutterProjectFactory projectFactory) = toolContext;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The ToolContext class defines the property as fileSystem, not fs. Destructuring with :FileSystem fs (which is shorthand for fs: FileSystem fs) will cause a compilation error because the getter fs does not exist on ToolContext. Use fileSystem: FileSystem fs to correctly map the fileSystem property to the local variable fs.

Suggested change
final ToolContext(:FileSystem fs, :FlutterProjectFactory projectFactory) = toolContext;
final ToolContext(fileSystem: FileSystem fs, :FlutterProjectFactory projectFactory) = toolContext;

Restores `packages/flutter_tools/lib/src/resident_runner.dart` to base by calling `getMissingPackageHintForPlatform` directly in `FlutterDriverService.start` when `applicationBinary == null`, avoiding a new public helper while keeping the `ToolExit` message concise. Trims 8 unused `ApplicationPackageFactory` overrides from `packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart`, retaining the override only on the 3 `ThrowingScreenshotDevice` tests.

Previous output:
```text
_TypeError: type 'Null' is not a subtype of type 'IOSApp' of 'package'
```

Current output:
```text
No supported devices connected.

The following devices were found, but are not supported by this project:
iPhone 16 Pro (mobile) • ios-sim-1 • ios • Test SDK (1.2.3) (simulator)
If you would like your app to run on ios, consider running `flutter create .` to generate projects for these platforms.
```

Current output (explicit `-d` targeting unsupported platform):
```text
Error: No application found for TargetPlatform.ios.
Is your project missing an ios/Runner/Info.plist?
Consider running "flutter create ." to create one.
```

Fixes flutter#134073
Resolves merge conflicts with flutter#196571 by keeping both `hook_runner.dart` and `project.dart` imports in `drive_service.dart` and passing `assetBundleFactory`, `devtoolsLauncher`, and `applicationPackages` directly to `DriveCommand` in `drive_test.dart`.

Fixes flutter#134073
Resolves merge conflicts with flutter#196571, picks up flutter#196572 and flutter#196740, and converts the remaining prebuilt-binary filter test in `drive_test.dart` to `testWithoutContext`.

Fixes flutter#134073
… drive tests

Merges `upstream/master` into `investigation/issue-134073` (resolving test conflicts from `testUsingContext` and `testWithoutContext` removals), updates `DriveCommand.targetedDevice` to also allow devices unsupported by the project when `--use-existing-app` is set, uses a local promoted `ApplicationPackage` variable in `FlutterDriverService.start`, and simplifies `drive_test.dart` to reuse `createToolContext()` and `createCommandRunner()`.

Previous output:
```text
_TypeError: type 'Null' is not a subtype of type 'IOSApp' of 'package'
```

Current output (default device selection):
```text
No supported devices connected.

The following devices were found, but are not supported by this project:
iPhone 16 Pro (mobile) • ios-sim-1 • ios • Test SDK (1.2.3) (simulator)
If you would like your app to run on ios, consider running `flutter create .` to generate projects for these platforms.
```

Current output (explicit `-d` targeting unsupported platform):
```text
Error: No application found for TargetPlatform.ios.
Is your project missing an ios/Runner/Info.plist?
Consider running "flutter create ." to create one.
```

Fixes flutter#134073
@bkonyi
bkonyi requested a review from chingjun November 27, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter drive crashes when targeting device with unsupported platform

2 participants