Flutter Run卡在‘Launching’阶段,模拟器启动失败求助
Flutter 模拟器启动卡顿问题排查方案
问题概述
首次启动Flutter应用失败,执行flutter run后卡在**“Launching lib/main.dart on iPhone 14 Pro Max in debug mode...”**阶段,相关细节:
- 问题仅出现在iOS模拟器
- 控制台无任何报错日志输出
flutter doctor检测结果无异常- 新建Flutter项目测试仍出现相同问题
flutter run -v执行后卡在以下步骤:
/Users/taruneswar/.pub-cache/hosted/pub.dev/cloud_firestore-3.5.1/ [ ] Found plugin cloud_firestore_web at /Users/taruneswar/.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/ [ ] Found plugin firebase_core at /Users/tarun/.pub-cache/hosted/pub.dev/firebase_core-1.24.0/ [ ] Found plugin firebase_core_web at /Users/tarun/.pub-cache/hosted/pub.dev/firebase_core_web-1.7.3/ [ +8 ms] executing: [/Users/tarun/Documents/Front-end App Development/afg/macos/] /usr/bin/arch -arm64e xcrun xcodebuild -list -project Runner.xcodeproj [ +6 ms] <- compile package:afg/main.dart
解决步骤
1. 彻底清理项目与缓存
依次执行以下命令,清除冗余构建文件与依赖缓存:
flutter clean rm -rf ios/Pods ios/Podfile.lock pubspec.lock flutter pub get cd ios && pod install --repo-update cd ..
2. 重置iOS模拟器
- 打开模拟器,点击顶部菜单 Hardware > Erase All Content and Settings
- 等待模拟器重置完成后,重启模拟器再尝试启动应用
3. 校准Xcode命令行工具路径
执行命令查看当前Xcode命令行工具路径:
xcode-select -p
若路径不是/Applications/Xcode.app/Contents/Developer,执行以下命令修正:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
重启终端后重新执行flutter run
4. 禁用Xcode构建缓存
打开Xcode,进入 File > Project Settings(或Workspace Settings),点击 Build Location 下的 Advanced,选择 Legacy 模式,关闭Xcode后重新运行Flutter项目
5. 调整Flutter版本
如果是版本兼容性问题,切换到稳定版:
flutter channel stable flutter upgrade
或降级到之前可用的版本(替换<版本号>为具体版本):
flutter downgrade <版本号>
6. 适配M系列芯片架构
针对M系列芯片Mac,尝试强制使用x86架构运行:
arch -x86_64 flutter run
或在iOS目录的Podfile中添加以下配置,执行pod install后重试:
post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64' end end end
内容的提问来源于stack exchange,提问作者Tarun Eswar
相关产品推荐
相关产品推荐

