Repository navigation
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listplatform-iosiOS applications specificallyiOS applications specificallyteam-iosOwned by iOS platform teamOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform teamTriaged by iOS platform team
Description
Hey Flutter Community, I've looked at similar issues but non resemble the issue we have.
While running the usual command flutter clean we've noticed several months ago that it takes too long, nearly up to 3 minutes, which definitely is not the case for new projects. Maybe it has to do with the fact that we use too many dependencies? We're using SPM and the latest Flutter Version 3.35.1. If needed I can supply the packages we have in our pubspec.yaml.
flutter clean -v (provided as a file because it's very big with >500.000 chars): clean.txt
flutter doctor -v
[✓] Flutter (Channel stable, 3.35.1, on macOS 15.6 24G84 darwin-arm64, locale de-DE) [499ms]
• Flutter version 3.35.1 on channel stable at /Users/emre.yurtseven/Dev/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 20f8274939 (4 days ago), 2025-08-14 10:53:09 -0700
• Engine revision 1e9a811bf8
• Dart version 3.9.0
• DevTools version 2.48.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-swift-package-manager, enable-lldb-debugging
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [3,7s]
• Android SDK at /Users/emre.yurtseven/Library/Android/sdk
• Emulator version 36.1.9.0 (build_id 13823996) (CL:N/A)
• Platform android-36, build-tools 36.0.0
• Java binary at: /Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java
This JDK is specified in your Flutter configuration.
To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment Corretto-17.0.13.11.1 (build 17.0.13+11-LTS)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1.194ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16F6
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [6ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2025.1) [6ms]
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)
[✓] VS Code (version 1.103.1) [4ms]
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.116.0
[✓] Connected device (3 available) [6,4s]
• iPhone 16 (mobile) • 620FF751-F320-4085-915B-D8DA36474288 • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-5 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.6 24G84 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 139.0.7258.128
[✓] Network resources [1.232ms]
• All expected network resources are available.
• No issues found!This is already impacting us on our daily workflows, CI/CD and fixing bugs.
Best regards
Emre Yurtseven
Reacted by Amr Eniou, Sergey Shumov, Simone Stasi, Jan Marsh, nboyashko, Pawel Lugowski, Paurakh Sharma Humagain, Mike, Artem Petrushenko, Zamkovoy Vadim and 30 more
Reacted by Bart van Andel, Pawel Lugowski, Mike, RomanKapshuk and Denis Latygin
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listplatform-iosiOS applications specificallyiOS applications specificallyteam-iosOwned by iOS platform teamOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform teamTriaged by iOS platform team
Activity
darshankawar commentedon Aug 18, 2025
From the verbose log, it seems the the command is taking ~ 158 seconds to cleanup xcode workspace:
You can take a look at what the command does in background which essentially is same as deleting above file contents per:
flutter/packages/flutter_tools/lib/src/commands/clean.dart
Line 47 in 660c234
@EmreDET Yes, please share the same for further analysis on the reported behavior.
EmreDET commentedon Aug 18, 2025
Thank you for your quick response.
pubspec.yaml
Maybe for extra detail, we're using internationalization with
intlfor german and english (but english is currently manually disabled) and using 3 flavors, beta, production and local. The app was also created way back in flutter 2 but we've had no issues updating it over the years.The issue has also happened, as I've tried to recreate the app with a new blank project. (All the configurations in ios/, android/ and web/ folders manually adapted as our package's configurations demanded).
EmreDET commentedon Aug 18, 2025
I've now seen that enabling SPM back then must have added a bunch of schemes, which we can see in the
clean.txt, are triggering the repeated cleaning process.https://github.com/flutter/flutter/blob/660c234bb02e60669d5d02bc814bb65c40b9cff9/packages/flutter_tools/lib/src/commands/clean.dart#L100C9-L106C10
I don't know if that was necessary, as I've checked another project with doesn't them at all.
After deleting them (but not the FlutterGeneratedPluginSwiftPackage one) the cleaning process reduced to about 30-33 seconds.
flutter clean -v
clean.txt
I think about disabling SPM and removing all the config and re-enabling it to try to get to the old slow clean to further investigate this behavior.
EmreDET commentedon Aug 19, 2025
After removing all SPM related and confirming that everything still works (app builds and runs).
I've re-enabled SPM and I did not get any more extra schemes this time. I did add it manually though.
My flutter clean takes roundabout 30-40 seconds, which is far better than 150-180 seconds it took before.
What do you think, is the reason for the creation of the extra schemes for the packages?
darshankawar commentedon Aug 19, 2025
Thanks for the update @EmreDET I think it could be related to enabling and disabling SPM. I tried to recreate the behavior by adding all the dependencies you shared earlier and then building the iOS. With SPM enabled, it took
flutter cleanbelow time[ ] "flutter clean" took 322,205ms.After disabling SPM, building iOS again and then running
flutter cleandidn't take that long:[ +1 ms] "flutter clean" took 18,959ms.This seems to be a drastic change and maybe indicates it is not consistent. But I feel adding lot of dependencies since they are external and also the fact that SPM was enabled. I noticed it did take time for workspace to clean each dependency.
I suggest to keep an eye on this behavior and if you again come across such delayed time to clean the workspace, we can probably take this further to the team for further analysis. What do you think ?
EmreDET commentedon Aug 19, 2025
Alright. I'll keep an eye out!
Just as a temp fix for everyone else who stumbles to this "problem" of long
flutter cleantimes.Try to investigate the added schemes in your XCode Project:
For my case, removing the packages with no
Pods projectContainer helped reduce the time offlutter clean.The last should only be
FlutterGeneratedPluginSwiftPackagecheckedAnd above all, you should see your own flavors checked and as
Runner projectdarshankawar commentedon Aug 19, 2025
Based on above findings and per my earlier verifications, I'll keep the issue open and label for team's input on this.
10 remaining items
RusKryzhanovskiy commentedon Jan 16, 2026
Hey!
I’ve opened a PR that adds a new
--xcode-cleanoption toflutter clean, providing better control over Xcode workspace cleanup, especially for large SwiftPM-based projects.In my local setup, using
--xcode-clean=appsignificantly reduces the time spent on Flutter clean by avoiding serial Xcodebuild clean runs for non-application schemes.The change is ready on my side.
I noticed the tree is currently red, so I’m waiting for it to go green before proceeding further.
Would really appreciate any early feedback on the API or heuristics while we wait for the tree to be fixed.
Thanks!
iamgirya commentedon Mar 13, 2026
For large projects, running
flutter clean --scheme Runnercan helpjakobleck commentedon Jun 4, 2026
I am also facing the issue of a massive slowdown of flutter clean. Let me provide some info:
I am working on a flutter app for iOS and Android with three build flavors (each with debug, profile and release configs), about 440k LOC (or 250k counting only dart) and a roster of a few dozen package dependencies including usual things like firebase_messaging, flutter_secure_storage, package_info_plus, camera, flutter_webrtc, freezed etc. etc.
Currently we are using Flutter 3.41.6, tried the migration to Swift Package Manager (auto migration worked, pretty smooth 👍 ), but the time taken for
flutter cleanwent from about 7 seconds to about 7 minutes! This is reproducible going back and forth between commits before and after the migration to SPM (and usage of SPM was set at project level withenable-swift-package-manager: truein the pubspec.yaml). Some observations from comparing the outputs offlutter clean --verbosebefore and after the commit with the SPM migration:The first significant slowdown is in
xcodebuild -list, namely before SPM: 701 msxcodebuild-list.txt
vs. with SPM: 40593 ms
xocdebuild-list-SPM.txt
Package.resolvedfiles added by the SPM auto migration.iOS/Podfile.lockby the SPM auto migration.Each scheme is cleaned, each time taking 10 times longer than before the SPM migration, and of course the number of schemes has increased significantly. One example (of one of the schemes that already existed) before: 1550 ms
clean-flavor1.txt
and after SPM migration: 15139 ms
clean-flavor1-SPM.txt
And then the output from cleaning one of the newly introduced schemes, less text, but similarly slow: 12936 ms
clean-audio-session-SPM.txt
Running some of those commands on their own, e.g.
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace /Users/user/path_to_app_repo/ios/Runner.xcworkspace -scheme audio-session cleanin the iOS directory, it seems that resolving the package graph is the step that takes a lot of time.This is confirmed by:
time /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -resolvePackageDependencies -workspace /Users/user/path_to_app_repo/ios/Runner.xcworkspace -scheme audio-sessionwhich takes about 10 seconds.Also it seems that the list of resolved packages repeats, with the same content but in a different order. If indeed resolving is the slow step, maybe there could or should be some sort of caching of the results?! Even if resolving package dependencies takes 10s for one scheme, not repeating this step for each scheme (29 in the above example) would reduce
flutter cleantimes from abysmal to a little worse than before SPM. :)Edit/P.S.: https://github.com/jakobleck/spm_performance_playground for reproduction... ;)
jakobleck commentedon Jul 1, 2026
@darshankawar Is somebody looking into this at the moment? IMHO this is a significant issue and should ideally be fixed (or improved) within the next few months, given that for example Firebase will stop delivering updates to Cocoapods in October (cf. https://firebase.google.com/docs/ios/cocoapods-deprecation) and Cocoapods as a whole will be read-only by the end of the year.
vaydenloren-design commentedon Jul 1, 2026
jakobleck commentedon Jul 21, 2026
The issue seems to be (EDIT: only partially) resolved, at least for the reproduction example I posted above, in Flutter 3.44 (I assume through #183747).
yurtemre7 commentedon Jul 21, 2026
@jakobleck my flutter clean still takes long times. I'm on Flutter 3.44.7, the most latest version.
$ time flutter clean Cleaning Xcode workspace... 173.3s Deleting build... 5.4s Deleting .dart_tool... 70ms Deleting ephemeral... 2ms Deleting Generated.xcconfig... 0ms Deleting flutter_export_environment.sh... 0ms Deleting Flutter.podspec... 0ms Deleting .flutter-plugins-dependencies... 0ms flutter clean 142.10s user 46.61s system 105% cpu 2:59.25 totaljakobleck commentedon Jul 21, 2026
@yurtemre7 My bad. I only performed the SwiftPM migration for MacOS in the example project (i.e. not started the app on iOS after introducing the setting
enable-swift-package-manager: true). So it seems that the issue is partially fixed, that is,flutter cleanis quick again with Flutter 3.44 for MacOS-only-migrated projects, while for iOS performance of the clean is still bad. And when performing the SwiftPM migration for MacOS only, it seems that afterwards in the macos folderxcodebuild -listis still pretty slow, so the first clean or build would be slow and then caching mitigates the problem for later cleans.Make Xcode workspace cleaning optional during flutter clean (flutter#…
Revert: Make Xcode workspace cleaning optional during flutter clean (f…
Reland "Make Xcode workspace cleaning optional during flutter clean" (f…
intraector commentedon Aug 19, 2026
Same here, it takes up to 90 seconds for a small project. It was under 10 seconds before.
JakobLichterfeld commentedon Aug 19, 2026
Flutter 3.47.0 is a big improvement towards old behavior.
Edit, 3.47.1 as well way better than 3.44.x:
NewLand-Ju commentedon Aug 20, 2026
in 3.47.1, still same
gabrielgarciagava commentedon Sep 2, 2026
Note that comment below was written with the help of github copilot, and reviewed and modified by me
darshankawar If this kind of comment is too verbose, let me know and I will avoid it in the future 😅
Adding a data point from a large SwiftPM workspace, plus what I believe is the concrete root cause and a targeted fix, since this is still unresolved as of 3.44.x/3.47.x.
Summary
flutter cleantakes ~62 minutes (45s per scheme x 81 schemes) on our iOS app. The cause is that_cleanXcoderuns onexcodebuild cleanper scheme, and after the SwiftPM migration Xcode auto-creates one scheme per Swift package product. Our workspace reports 81 schemes, of which only 4 are actually defined by the project.This confirms what @EmreDET and @importRyan identified earlier in this thread — I'm adding measurements and a concrete patch proposal.
Environment
Why the loop is redundant
Three independent reasons the extra ~77 cleans do no useful work:
1. Only 4 of the 81 schemes are real.
2. Cleaning the app scheme already cleans the packages.
Runner.xcschemehasbuildImplicitDependencies = "YES", soxcodebuild -scheme Runner cleantransitively cleans every packageRunnerdepends on. The per-package cleans are pure duplication.3. Many package schemes cannot even be cleaned. For example:
We pay ~26s for that invocation and it fails.
The dominant per-invocation cost is that each
xcodebuildre-opens the workspace and re-resolves the whole SwiftPM package graph.Things that do not work (so they can be ruled out)
I checked a few plausible mitigations before concluding this needs a tool-side fix:
-resolvePackageDependencies.prefetchSwiftPackagesis guarded byif (_swiftPackageFetchProcess != null) return;, so Flutter resolves once. The cost is genuinely 81 ×xcodebuild clean. (Noting this because Warn about slow SwiftPM downloads and centralize SwiftPM cache #183747 helped here but did not address the loop, which matches @jakobleck's "only partially fixed" observation.)xcodebuild -project Runner.xcodeproj -liststill returns all 81 schemes (and took 2m28s), because the packages are dependencies of the.xcodeproj, not only of the workspace.IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded = falseinRunner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettingshad no effect onxcodebuild -list— it only affects the IDE.Manually deleting the auto-created schemes (as suggested earlier in this thread) is not a durable fix for us: they come back, and hand-editing scheme state across a large team is not practical.
Proposed fix
Restrict the loop to schemes the project actually defines, rather than every scheme the workspace reports.
XcodeProjectInfoalready parsestargets, so this needs no additionalxcodebuildinvocations.In
clean.dart:On our project this selects 5 schemes instead of 81 — ~62 min → ~4 min — while still covering flavor schemes such as
devthat a target-name-only filter would miss. The fallback preserves today's behaviour for projects where the heuristic yields nothing.Union of on-disk schemes and targets (rather than targets alone) matters: flavor schemes like
devare shared schemes with no identically-named target, and they do need cleaning.One caveat: this assumes auto-created package schemes are never written into
xcshareddata. That held on our project. A project that deliberately commits a package scheme would still clean it — harmless, just slower.Simpler alternative: drop
-workspace/-schemeand runxcodebuild -project Runner.xcodeproj cleanonce, since a project-scoped clean with no scheme cleans all targets in a single invocation. But that stops cleaning Pods, so it can only be used after Flutter fully drops pods support.Workaround for others landing here
flutter clean --scheme Runnercuts this from ~62 min to ~1 min for us. (Thanks @iamgirya)