【问题标题】:Flutter iOS build failing on BigSur, XCode 12在 BigSur、XCode 12 上 Flutter iOS 构建失败
【发布时间】: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 应用,运行它。

【问题讨论】:

    标签: ios xcode flutter dart xcode12


    【解决方案1】:

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

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

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

    【讨论】: