UIKit迁移SwiftUI后Xcode报错:找不到Info.plist构建输入文件
iOS项目UIKit转SwiftUI后Info.plist构建错误排查
错误信息
Build input file cannot be found: '/Users/rgf10hotmail.es/Desktop/Developer/Recipeas2024/CocinArtGit/Recipeas/Info.plist'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?
项目背景
- 迁移操作:将应用从UIKit过渡到SwiftUI
- Xcode版本:2024-12-03最新版
- SwiftUI配置:迁移时移除了
AppDelegate和SceneDelegate - Info.plist:已在
Recipeas/Info.plist路径下创建新文件
已尝试的修复步骤
- 验证项目设置中的Info.plist路径:检查Build Settings → Packaging → Info.plist File,更新为新路径
Recipeas/Info.plist - 检查Build Phases:确认Copy Bundle Resources中包含Info.plist,且自定义构建脚本无旧路径引用
- 清理构建文件夹与Derived Data:执行
Product > Clean Build Folder,手动删除~/Library/Developer/Xcode/DerivedData下的Derived Data - 移除过时引用:确保项目导航器中无旧Info.plist路径引用,删除红色高亮的缺失文件引用
- 直接更新项目文件:打开
project.pbxproj搜索旧路径并修正,确保无指向已删除位置的绝对路径 - 验证搜索路径:检查Build Settings中的Header Search Paths、Library Search Paths、Framework Search Paths,确认无旧路径引用
- 重新添加Info.plist到项目:移除当前Info.plist引用后重新添加,确保Xcode正确识别新文件
- 重启Xcode与系统:多次重启Xcode,重启Mac以清除缓存
- 检查多Target:验证项目中所有Target均引用正确的Info.plist
- 确保使用相对路径:确认项目使用相对路径避免路径解析问题
补充说明
- 错误信息指向的旧路径已被删除:
/Users/rgf10hotmail.es/Desktop/Developer/Recipeas2024/CocinArtGit/Recipeas/Info.plist - 已确认无脚本或构建规则尝试访问该旧路径
- 迁移前项目运行正常
相关代码
Info.plist文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <!-- Google移动广告SDK --> <key>GADApplicationIdentifier</key> <string>ca-app-pub-9021089007171782~8539445706</string> <!-- 应用传输安全设置 --> <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> <!-- 自定义字体 --> <key>UIAppFonts</key> <array> <string>Montserrat-Black.ttf</string> <string>Montserrat-Bold.ttf</string> <string>Montserrat-ExtraBold.otf</string> <string>Montserrat-ExtraLight.ttf</string> <string>Montserrat-Light.ttf</string> <string>Montserrat-Medium.ttf</string> <string>Montserrat-Regular.ttf</string> </array> <!-- 用户界面样式 --> <key>UIUserInterfaceStyle</key> <string>Light</string> </dict> </plist>
SwiftUI入口与视图代码
import SwiftUI struct ContentView: View { var body: some View { NavigationView { HomeView() .navigationTitle("食谱集") } } } import SwiftUI import GoogleMobileAds @main struct RecipeasApp: App { // 初始化Google移动广告SDK init() { GADMobileAds.sharedInstance().start(completionHandler: nil) } var body: some Scene { WindowGroup { ContentView() } } }
额外排查方向
- 检查Scheme配置:Edit Scheme → Build → 查看是否有旧的Info.plist路径引用,或勾选了不必要的Target
- 验证文件系统权限:系统设置→隐私与安全性→文件与文件夹,确认Xcode有权限访问新的Info.plist文件
- 检查xcconfig配置文件:如果项目使用
.xcconfig,搜索其中是否有旧的INFOPLIST_FILE配置项 - 查看构建日志详情:Command+9打开构建日志,展开错误对应步骤,定位调用旧路径的具体任务
- 清理Git缓存:执行
git clean -fdx清除未跟踪文件与缓存(先备份本地修改),重新拉取项目 - 重置CocoaPods依赖:删除
project.xcworkspace和Podfile.lock,重新执行pod install
内容的提问来源于stack exchange,提问作者Rubén García
相关产品推荐
相关产品推荐

