iOS端Flutter应用编译报错:No such module 'Flutter'求解决
iOS端Flutter应用编译失败求助
无法在iOS设备上构建预编译Flutter应用,报错信息如下:
Could not build the precompiled application for the device. Swift Compiler Error (Xcode): No such module 'Flutter' /Users/victorpelle/.pub-cache/hosted/pub.dev/url_launcher_ios-6.3.1/ios/url_launcher_ios/Sources/url_launcher_ios/messages.g.swift:9:9 Swift Compiler Error (Xcode): No such module 'Flutter' /Users/victorpelle/.pub-cache/hosted/pub.dev/path_provider_foundation-2.4.0/darwin/path_provider_foundation/Sources/path_provider_foundation/messages.g.swift:9:9 Uncategorized (Xcode): Command SwiftEmitModule failed with a nonzero exit code Error launching application on eziopelle’s iPhone.
已尝试以下操作但未解决:
flutter cleanflutter pub getpod installpod update- 关闭Xcode并删除
Podfile.lock
附Launcher代码:
// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import UIKit /// Protocol for UIApplication methods relating to launching URLs. /// /// This protocol exists to allow injecting an alternate implementation for testing. protocol Launcher { /// Returns a Boolean value that indicates whether an app is available to handle a URL scheme. func canOpenURL(_ url: URL) -> Bool /// Attempts to asynchronously open the resource at the specified URL. func open( _ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?) } /// Launcher is intentionally a direct passthroguh to UIApplication. extension UIApplication: Launcher {}
解决方法
1. 重置iOS项目配置
执行以下命令彻底清理并重建iOS相关文件:
flutter clean rm -rf ios/Pods ios/Podfile.lock ios/Runner.xcworkspace flutter pub get cd ios pod install --repo-update cd .. flutter run
2. 检查Flutter框架引用
打开ios/Runner.xcworkspace,进入Runner目标的Frameworks, Libraries, and Embedded Content,确认是否包含Flutter.framework。若缺失:
- 右键点击
Runner→Add Files to "Runner" - 导航到Flutter SDK路径下的
bin/cache/artifacts/engine/ios,选择Flutter.framework,勾选Copy items if needed
3. 修复Xcode框架搜索路径
在Xcode的Runner目标Build Settings中,搜索Framework Search Paths,添加Flutter SDK的bin/cache/artifacts/engine/ios路径(替换为你的实际SDK路径),确保路径设置为recursive。
4. 降级兼容插件版本
在pubspec.yaml中指定与当前Flutter版本兼容的插件版本:
dependencies: url_launcher_ios: ^6.2.0 path_provider_foundation: ^2.3.0
执行flutter pub get后重新运行pod install。
5. 清理CocoaPods缓存
清理本地CocoaPods缓存并重新初始化:
pod cache clean --all rm -rf ~/.cocoapods/repos pod setup cd ios pod install
内容的提问来源于stack exchange,提问作者eziopelle
相关产品推荐
相关产品推荐

