Xcode 13 和 Flutter 2.5.1 - 致命错误:找不到“Flutter/Flutter.h”文件 #import <Flutter/Flutter.h>
Posted
技术标签:
【中文标题】Xcode 13 和 Flutter 2.5.1 - 致命错误:找不到“Flutter/Flutter.h”文件 #import <Flutter/Flutter.h>【英文标题】:Xcode 13 & Flutter 2.5.1 - fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> 【发布时间】:2021-09-29 15:37:26 【问题描述】:我在升级到Xcode 13
后才开始遇到这个问题。几天前我将Flutter
升级为2.5.1
。
这就是我所看到的:
Failed to build ios app
Error output from Xcode build:
↳
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device
platform:iOS Simulator, id:AA0EE6D2-4E24-48C6-B9D6-4F2598B68E4E, OS:15.0, name:iPad (9th generation)
platform:iOS Simulator, id:765C02E6-837E-4443-9073-722162C490DC, OS:15.0, name:iPad Air (4th generation)
platform:iOS Simulator, id:30429B61-93BC-4497-B556-3639373A10D0, OS:15.0, name:iPad Pro (9.7-inch)
platform:iOS Simulator, id:57217E13-F700-4673-9ABF-1866BAE1E435, OS:15.0, name:iPad Pro (11-inch) (3rd generation)
platform:iOS Simulator, id:A85DD0A6-EA0F-480C-9A6F-07966F4FE66B, OS:15.0, name:iPad Pro (12.9-inch) (5th generation)
platform:iOS Simulator, id:1D568B75-852B-42BE-8178-C39E6C515C41, OS:15.0, name:iPad mini (6th generation)
platform:iOS Simulator, id:347466A9-6BA4-4674-94B6-BCB3ACB11F00, OS:15.0, name:iPhone 8
platform:iOS Simulator, id:F74B444A-2838-4920-91DB-83893719250E, OS:15.0, name:iPhone 8 Plus
platform:iOS Simulator, id:2D4AF847-04A7-463C-A46C-D5D1E200CFDC, OS:15.0, name:iPhone 11
platform:iOS Simulator, id:BCD3D3BD-6485-4575-AA35-BF9ADEEBB4BD, OS:15.0, name:iPhone 11 Pro
platform:iOS Simulator, id:06DE013F-BF48-4857-B952-BFC2AA1BD304, OS:15.0, name:iPhone 11 Pro Max
platform:iOS Simulator, id:8A06D628-6132-4558-BB65-5598FFAC98DC, OS:15.0, name:iPhone 12
platform:iOS Simulator, id:885B1C8A-0497-4D95-8A87-447E40AB9238, OS:15.0, name:iPhone 12 Pro
platform:iOS Simulator, id:FF519331-8490-4219-92D0-ED9A08F11976, OS:15.0, name:iPhone 12 Pro Max
platform:iOS Simulator, id:51671583-ED36-4330-839B-401BA09B3996, OS:15.0, name:iPhone 12 mini
platform:iOS Simulator, id:950FC388-6567-40BD-AD31-6CC5A334AC97, OS:15.0, name:iPhone 13
platform:iOS Simulator, id:562728AB-E0CA-4675-BF75-787299ECE105, OS:15.0, name:iPhone 13 Pro
platform:iOS Simulator, id:CBB3D2FF-97DF-4328-8AD0-7350F83989D1, OS:15.0, name:iPhone 13 Pro Max
platform:iOS Simulator, id:D99FD6E3-C6DC-4F16-8092-83EA0216367F, OS:15.0, name:iPhone 13 mini
platform:iOS Simulator, id:2A06C9C4-9D8C-4C9B-9620-12265131A747, OS:15.0, name:iPhone SE (2nd generation)
platform:iOS Simulator, id:EA2B1A03-78F8-42B2-9818-41FE3F1E833A, OS:15.0, name:iPod touch (7th generation)
platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device
** BUILD FAILED **
Xcode's output:
↳
/Users/abc/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock-0.5.2/ios/Classes/messages.m:4:9: fatal error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel
Could not build the application for the simulator.
我尝试过重新安装 Flutter,删除并重新克隆我的项目,移除 pod,flutter clean + pod install,flutter 缓存修复,以及从项目中移除 Flutter 并重新添加。
每一个都会导致上述错误的一些变化。
我还必须更改我的Podfile
--
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
如果我将其还原,则会收到一组不同的错误,其中一些 pod 抱怨设置为 8.0,需要从 9.0 到 14.9.9。
我尝试更改 Runner 项目中的各个 pod,但这不起作用。以上清除了该错误,但现在我面临另一个错误。
请注意,android 运行良好。这只是 iOS。
对这个有什么其他建议吗?
【问题讨论】:
【参考方案1】:这对我有用:
在 Podfile 中: 替换
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
由
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
然后在 Xcode 和 Pods 中打开 iOS 文件,对于每个 Target,在 Build Settings 中,将部署目标设置为 11(也许 9 就足够了)
这是你已经尝试过的吗?
【讨论】:
【参考方案2】:XCode 13 和 Flutter 2.5.3 有类似的问题:通过 xcodebuild 构建随机模块时出现错误(从 UI 构建可以正常工作)。在我尝试删除“有问题的”库之后 - 错误是针对下一个随机库,直到我卡在 Flutter.h 中。
我的问题是,在解决问题的过程中,我在 XCode 中将部署目标更改为 13,但却弄得一团糟:我在 Podfile、Project->Runner->Info中更新了它>,Project->Runner->Build settings,但是忘记为 Targets->Runner->Build Settings 做。
一旦我更新了Targets->Runner->Build Settings,它也开始成功编译。
最终我在所有地方都回滚到了 Target 11.0,它仍然可以编译。
【讨论】:
以上是关于Xcode 13 和 Flutter 2.5.1 - 致命错误:找不到“Flutter/Flutter.h”文件 #import <Flutter/Flutter.h>的主要内容,如果未能解决你的问题,请参考以下文章
iOS - 无法在真实设备 iPhone 11 中运行 Flutter 应用程序。iOS - 15.2,Xcode 13.2.1,它在模拟器中工作
xcode 上的 Flutter audioplayers 插件错误(未找到模块“audioplayers”)
2021-11-17 xcode12.3 &xcode13.1 下lipo合并framework问题
无法在 Xcode 中分发我的 iOS 版 Flutter 应用程序 - “包中的 ipa 包含无效字符”