Skip to content

[CP-stable][iOS] Remove async prefetch of Swift package dependencies#187384

Merged
auto-submit[bot] merged 6 commits into
flutter:flutter-3.44-candidate.0from
vashworth:swiftpm_fixes
Jun 8, 2026
Merged

[CP-stable][iOS] Remove async prefetch of Swift package dependencies#187384
auto-submit[bot] merged 6 commits into
flutter:flutter-3.44-candidate.0from
vashworth:swiftpm_fixes

Conversation

@vashworth

@vashworth vashworth commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR cherry-picks multiple commits due to the incremental nature of them. They all touch the same files and therefore have many merge conflicts in cherry-picked individually.

Issue Link:

What is the link to the issue this cherry-pick is addressing?

#186054, #185775

Impact Description:

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

iOS apps may fail to download SwiftPM dependencies, especially in CI.

Also, SwiftPM was printing warnings on non-iOS/macOS builds, which it shouldn't.

Changelog Description:

Explain this cherry pick:

  • In one line that is accessible to most Flutter developers.
  • That describes the state prior to the fix.
  • That includes which platforms are impacted.
    See best practices for examples.

[flutter/186054] When building an iOS or macOS app with Swift Package Manager enabled, remote package dependencies may fail to download.
[flutter/185775] When building for non-iOS or macOS apps, Swift Package Manager warnings may appear.

Workaround:

Is there a workaround for this issue?

Pin to an older version of Flutter or disable SwiftPM.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

What are the steps to validate that this fix works?

It's a race condition so it's not always consistent:

flutter config --no-enable-swift-package-manager
mkdir temp_workspace && cd temp_workspace
mkdir packages && cd packages
flutter create unmigrated_app && cd unmigrated_app
flutter pub add google_maps_flutter google_maps_flutter_ios_sdk10
echo "resolution: workspace" >> pubspec.yaml
cd ..
flutter config --enable-swift-package-manager
flutter create migrated_app && cd migrated_app
flutter pub add google_maps_flutter google_maps_flutter_ios_sdk10
flutter build ios --config-only
echo "resolution: workspace" >> pubspec.yaml
cd .. 
rm -rf build
cd ..
echo -e "name: _\npublish_to: none\nenvironment:\n  sdk: ^3.6.0\nworkspace:\n  - packages/unmigrated_app\n  - packages/migrated_app" >> pubspec.yaml
rm -rf $HOME/Library/Caches/org.swift.swiftpm
rm -rf $HOME/Library/org.swift.swiftpm
flutter pub get && cd packages/unmigrated_app && flutter build ios

vashworth added 5 commits June 1, 2026 10:00
Currently, we show SwiftPM warnings during
`ensureReadyForPlatformSpecificTooling`, which can happen while
targeting any build (such as targeting an Android device on a macOS
host). We should only show SwiftPM warnings when building for iOS or
macOS, so we move the logic to be called right before the build.

Fixes flutter#185775.

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…Interpreter (flutter#186378)

Pass `XcodeBasedProject` instead of the project path string.

This will enable us to be able to get more information about the project
(other than just the project path) from places in `xcodeproj.dart`.
Needed for flutter#185218,
https://github.com/flutter/flutter/pull/186006/changes#r3191012567

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This PR moves the logic for `prefetchSwiftPackages` from the
`XcodeProjectInterpreter` class to the `XcodeBasedProject` class so that
it can be run per platform

Incremental step toward flutter#185218.

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
When you use a federated plugin, it can have a default package per
platform. However, app developers can override the default package by
adding a different package that implements the federated plugin as a
direct dependency. For example, the federated plugin
`google_maps_flutter` has `google_maps_flutter_ios` set as it's default
package for iOS. App developers can add `google_maps_flutter_sdk_10` to
their app's pubspec.yaml to override the default plugin and use
`google_maps_flutter_sdk_10` instead.

SwiftPM was not previously handling this use case. This PR fixes that.

Fixes flutter#186770.

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
We were previously calling `prefetchSwiftPackagesForProject` in
`DarwinDependencyManagement`, which would be called during `flutter pub
get`. This would start the process silently and not wait for it to
complete. The original idea was so that when you added a dependency in
your IDE, it would start downloading any remote dependencies without you
needing to trigger a build. However, if 2 processes are fetching the
dependencies at the same time, this can cause one to fail.

I'm guessing that's what's happening in
flutter#186054 (comment).

This PR removes the silent prefetch call from `flutter pub get`.
Instead, it will be called during `flutter build`/`flutter run`

Speculative fix for flutter#186054.

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 1, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@vashworth vashworth changed the title [CP-stable][iOS] [CP-stable][iOS] Remove async prefetch of Swift package dependencies Jun 1, 2026
@github-actions github-actions Bot added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. platform-macos Building on or for macOS specifically a: desktop Running on desktop team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Jun 1, 2026
@vashworth vashworth marked this pull request as ready for review June 1, 2026 16:59
@vashworth vashworth requested review from a team as code owners June 1, 2026 16:59
@vashworth vashworth requested a review from hellohuanlin June 1, 2026 16:59
@vashworth vashworth added the cp: review Cherry-picks in the review queue label Jun 1, 2026

@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 refactors Darwin dependency management and Swift Package Manager (SwiftPM) prefetching by moving the prefetch logic from XcodeProjectInterpreter to XcodeBasedProject and introducing a static validatePluginSupport method in DarwinDependencyManagement. It also updates various commands and tests to pass XcodeBasedProject instances instead of raw paths. The review feedback suggests avoiding quiet: true during plugin validation to prevent empty error outputs on ToolExit, and recommends resetting SwiftPM prefetch process and subscription state variables to null upon completion to support instance reuse.

Comment on lines +185 to +189
final List<Plugin> filteredPlugins = resolvePluginImplementationsForPlatform(
plugins,
platform.pluginConfigKey,
quiet: true,
);

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.

high

Passing quiet: true to resolvePluginImplementationsForPlatform suppresses all warning and error messages during plugin resolution. However, if a resolution or pubspec error occurs, resolvePluginImplementationsForPlatform will still throw a fatal ToolExit with the message 'Please fix the pubspec.yaml errors above.'. Because the actual errors were suppressed, the user will see a build failure with no context or explanation of what went wrong.

Consider setting quiet: false (or removing the parameter since it defaults to false) so that the actual errors are printed before the tool exits.

Suggested change
final List<Plugin> filteredPlugins = resolvePluginImplementationsForPlatform(
plugins,
platform.pluginConfigKey,
quiet: true,
);
final List<Plugin> filteredPlugins = resolvePluginImplementationsForPlatform(
plugins,
platform.pluginConfigKey,
);

Comment on lines +437 to +440
final int exitCode = await process.exitCode.whenComplete(() async {
await _swiftPackageFetchStdoutSubscription?.cancel();
await _swiftPackageFetchStderrSubscription?.cancel();
});

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.

medium

The state variables _swiftPackageFetchProcess, _swiftPackageFetchStdoutSubscription, and _swiftPackageFetchStderrSubscription are not reset to null when the prefetch process completes or fails. If the same XcodeBasedProject instance is reused (e.g., in subsequent builds, resident runner sessions, or test suites), any future calls to prefetchSwiftPackages will either immediately return without doing anything (because _swiftPackageFetchProcess is still non-null) or fail due to reusing cancelled subscriptions.

Reset these variables to null in the whenComplete callback.

      final int exitCode = await process.exitCode.whenComplete(() async {
        await _swiftPackageFetchStdoutSubscription?.cancel();
        await _swiftPackageFetchStderrSubscription?.cancel();
        _swiftPackageFetchProcess = null;
        _swiftPackageFetchStdoutSubscription = null;
        _swiftPackageFetchStderrSubscription = null;
      });

hellohuanlin
hellohuanlin previously approved these changes Jun 2, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 3, 2026
@vashworth vashworth added the CICD Run CI/CD label Jun 3, 2026

@justinmc justinmc 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.

CPLGTM 👍

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 8, 2026
@auto-submit auto-submit Bot merged commit 638b3c8 into flutter:flutter-3.44-candidate.0 Jun 8, 2026
155 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue platform-ios iOS applications specifically platform-macos Building on or for macOS specifically team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants