Flutter iOS项目执行flutter run时出现xcodebuild无法读取Runner.xcodeproj错误
报错信息:
ProcessException: Process exited abnormally: Command line invocation: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -list
User defaults from command line: IDEPackageSupportUseBuiltinSCM = YES
xcodebuild: error: Unable to read project 'Runner.xcodeproj'.
Reason: Project /Users/Zer01onE/Desktop/flutter/deliveryapp/ios/Runner.xcodeproj cannot be opened because it is missing its project.pbxproj file.
Command: xcrun xcodebuild -list
核心原因
project.pbxproj是Xcode项目的核心配置文件,该报错触发的核心原因是配置文件丢失、损坏,或Flutter/Xcode缓存异常导致文件无法被正常识别。
修复步骤
校验配置文件是否存在
进入项目ios目录执行命令:ls Runner.xcodeproj/若输出中没有
project.pbxproj文件,优先从Git等版本控制系统中恢复该文件;无备份则走后续重建步骤。全量清理项目缓存
在项目根目录依次执行以下命令:- 清理Flutter缓存:
flutter clean - 删除ios目录下残留的Pod相关文件与工作空间:
rm -rf ios/Podfile ios/Podfile.lock ios/Pods ios/Runner.xcworkspace pubspec.lock - 重新拉取Dart依赖:
flutter pub get
- 清理Flutter缓存:
若确认
project.pbxproj文件丢失无备份,执行命令重建iOS平台配置:flutter create .该命令只会补全缺失的平台原生配置,不会覆盖已编写的业务代码。
重新安装Pod依赖
进入ios目录依次执行:- 解除现有Pod绑定:
pod deintegrate - 安装依赖:
pod install --allow-root(普通用户可省略--allow-root参数)
- 解除现有Pod绑定:
校验Xcode命令行工具配置
执行命令查看当前命令行工具路径:xcode-select -p若输出不是
/Applications/Xcode.app/Contents/Developer,执行以下命令切换:sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer验证修复结果
在ios目录下执行xcodebuild -list,无报错即可回到项目根目录执行flutter run启动项目。
内容的提问来源于stack exchange,提问作者Vepa Sabyrow

