在 BigSur、XCode 12 上 Flutter iOS 构建失败

Posted

技术标签:

【中文标题】在 BigSur、XCode 12 上 Flutter iOS 构建失败【英文标题】:Flutter iOS build failing on BigSur, XCode 12 【发布时间】:2021-02-26 16:50:29 【问题描述】:

由于标头问题,Flutter ios 构建失败。

我按照 flutter.dev 中提到的简单步骤在 iOS 模拟器上启动应用程序。我在 android/Web 上使用 Flutter 没有任何问题,但这是我第一次尝试在 iOS 上运行它。

错误摘要 - (完整错误:https://gist.github.com/mannprerak2/520f8a749431a50b8472783c71d67dda)

...
   #import "Headers/CoreMedia.h"
            ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.4.sdk/System/Library/Frameworks/CoreMedia.framework/Headers/CoreMedia.h:15:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.4.sdk/System/Library/Frameworks/CoreMedia.framework/Headers/CoreMedia.h:15:
    #include <CoreMedia/CMFormatDescription.h>
             ^
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.4.sdk/System/Library/Frameworks/CoreMedia.framework/Headers/CMFormatDescription.h:26:10: error: could not build module 'CoreAudio'
    #include <CoreAudio/CoreAudioTypes.h>
             ^
    /Users/prerakmann/development/test_ios/ios/Runner/Runner-Bridging-Header.h:1:9: note: in file included from /Users/prerakmann/development/test_ios/ios/Runner/Runner-Bridging-Header.h:1:
    #import "GeneratedPluginRegistrant.h"
            ^
    /Users/prerakmann/development/test_ios/ios/Runner/GeneratedPluginRegistrant.h:8:9: error: could not build module 'Flutter'
    #import <Flutter/Flutter.h>
            ^
    192 errors generated.
    <unknown>:0: error: failed to emit precompiled header '/Users/prerakmann/Library/Developer/Xcode/DerivedData/Runner-ahrcvwuwhqnepxdcpfsagztcuwrr/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_1QEOMJ6SUMBGB-clang_3BG5Q8JCTPBV5.pch' for bridging header '/Users/prerakmann/development/test_ios/ios/Runner/Runner-Bridging-Header.h'
    384 errors generated.
    <unknown>:0: error: generate-pch command failed with exit code 1 (use -v to see invocation)
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description
...

系统:Macbook Pro 13 (2020)、BigSur 11.2.1、Xcode 12.4

Flutter:在最新的稳定版和测试版上试用。

模拟器:在 iOS 8、iOS 12 上试用。

重现步骤:创建一个新的 Flutter 应用,运行它。

【问题讨论】:

【参考方案1】:

原来这是因为 CPATH 是这样定义的。

╰─$ echo $CPATH
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

临时解决方法是在当前终端窗口中设置CPATH=,运行flutter clean,然后运行应用程序。

【讨论】:

以上是关于在 BigSur、XCode 12 上 Flutter iOS 构建失败的主要内容,如果未能解决你的问题,请参考以下文章

Xcode 12 - 下载更多模拟器运行时为空

使用 BigSur 在 Xcode 上的导航器和检查器行为

在 Mac OS 11.1 中运行 Xcode 12.3 项目时您无权保存文件

运行 python3 Xcode 项目时出错(符号链接级别过多且不允许操作)-macOS BigSur

如何在 Flutter 中使用 Xcode 12.5 解决 Stripe 支付问题?

无法在 Bigsur 上安装 mysql2 Gem