You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter iOS编译报错:Swift编译器错误及文件缺失求助

解决Flutter iOS编译时的Swift错误与缺失构建文件问题

错误现象

编译iOS应用时出现以下Swift编译器错误:

Swift Compiler Error (Xcode): Cannot call value of non-function type 'String?'
/Users/rabinacharya/.pub-cache/hosted/pub.dev/flutter_inappwebview-5.7.2+3/ios/Classes/MyCookieManager.swift:259:43

Swift Compiler Error (Xcode): Cannot call value of non-function type 'String?'
/Users/rabinacharya/.pub-cache/hosted/pub.dev/flutter_inappwebview-5.7.2+3/ios/Classes/MyCookieManager.swift:293:43

Swift Compiler Error (Xcode): Build input files cannot be found:
'/Users/rabinacharya/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.2/darwin/Classes/messages.g.swift',
'/Users/rabinacharya/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.2.2/darwin/Classes/SharedPreferencesPlugin.swift'

Swift Compiler Error (Xcode): Build input files cannot be found:
'/Users/rabinacharya/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.3/darwin/Classes/messages.g.swift',
'/Users/rabinacharya/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.3/darwin/Classes/PathProviderPlugin.swift'

Could not build the application for the simulator.
Error launching application on iPhone 11.

复现步骤

删除现有iOS工程后,执行命令 flutter create -i swift .,运行代码时触发上述错误,无法在iPhone 11模拟器启动应用。

解决方法

  • 清理Flutter项目缓存与依赖

    1. 执行命令清理项目:flutter clean
    2. 删除项目根目录下的pubspec.lock文件
    3. 重新获取依赖:flutter pub get
  • 重置CocoaPods依赖

    1. 进入iOS目录:cd ios
    2. 删除Podfile.lock和Pods文件夹:rm -rf Podfile.lock Pods
    3. 解除CocoaPods关联:pod deintegrate
    4. 重新安装Pods:pod install
    5. 返回项目根目录:cd ..
  • 升级问题依赖包

    1. 打开项目根目录的pubspec.yaml文件,检查flutter_inappwebview、shared_preferences、path_provider的版本号
    2. 将这些依赖升级到最新稳定版本(旧版本可能与当前Xcode/Swift版本不兼容)
    3. 执行命令升级依赖:flutter pub upgrade
  • 重新生成iOS工程文件
    如果上述步骤无效,先删除项目根目录下的ios文件夹,再重新执行:flutter create -i swift .

  • Xcode手动清理构建

    1. 用Xcode打开项目的ios/Runner.xcworkspace文件
    2. 按下Cmd+Shift+K清理构建文件夹
    3. 按下Cmd+B重新构建项目

内容的提问来源于stack exchange,提问作者Rabin Acharya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:52:24