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

MacBook Air M2上Flutter iOS项目构建失败求助

Flutter iOS构建失败问题(MacBook Air M2)

问题背景

刚入手MacBook Air M2做Flutter开发,Android模拟器能正常启动应用,但iOS应用构建失败。Flutter自带的计数器示例项目能在iOS模拟器正常运行,自己的项目不行,怀疑是Firebase配置或从Windows克隆项目导致的问题。

构建错误日志

Launching lib/main.dart on iPhone 12 in debug mode...
    Running pod install...                                             13.3s
    Running Xcode build...                                                   
    Xcode build done.                                           192.9s
    Failed to build iOS app
    Error output from Xcode build:
    ↳
        2022-08-23 10:54:07.757 xcodebuild[44481:4428285] Requested but did not find
        extension point with identifier
        Xcode.IDEKit.ExtensionSentinelHostApplications for extension
        Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in
        com.apple.dt.IDEWatchSupportCore
        2022-08-23 10:54:07.757 xcodebuild[44481:4428285] Requested but did not find
        extension point with identifier
        Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension
        Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of
        plug-in com.apple.dt.IDEWatchSupportCore
        2022-08-23 10:55:05.182 xcodebuild[44481:4428321]
        /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-20504/XCSo
        urceControl/Service/XCSourceControlXPCServiceClient.swift:
        'com.apple.dt.GitHubHostBuiltInExtension' XPC connection interrupted:
        <NSXPCConnection: 0x600001f22120> connection to service named
        com.apple.dt.GitHubHostBuiltInExtension
        ** BUILD FAILED **
    
    
    Xcode's output:
    ↳
        Writing result bundle at path:
            /var/folders/_b/h3qp3_6d675d938v23_ns4_80000gn/T/flutter_tools.7l9oeA/flutt
            er_ios_build_temp_dir6UlSvA/temporary_xcresult_bundle
    
        Command CompileSwiftSources failed with a nonzero exit code
        Command CompileSwiftSources failed with a nonzero exit code
        Command CompileSwiftSources failed with a nonzero exit code
        error: emit-module command failed with exit code 1 (use -v to see
        invocation)
        <module-includes>:1:9: note: in file included from <module-includes>:1:
        #import "Headers/FirebaseCoreExtension-umbrella.h"
                ^
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FirebaseCoreExtension-umbrella.h:13
        :9: note: in file included from
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FirebaseCoreExtension-umbrella.h:13
        :
        #import "FIRAppInternal.h"
                ^
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FIRAppInternal.h:17:9: error:
        include of non-modular header inside framework module
        'FirebaseCoreExtension.FIRAppInternal':
        '/Users/jarjar/project1/ios/Pods/Headers/Public/FirebaseCore/FIRApp.h'
        #import <FirebaseCore/FIRApp.h>
                ^
        /Users/jarjar/project1/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Stor
        age.swift:23:29: error: could not build Objective-C module
        'FirebaseCoreExtension'
        @_implementationOnly import FirebaseCoreExtension
                                    ^
        <module-includes>:1:9: note: in file included from <module-includes>:1:
        #import "Headers/FirebaseCoreExtension-umbrella.h"
                ^
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FirebaseCoreExtension-umbrella.h:13
        :9: note: in file included from
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FirebaseCoreExtension-umbrella.h:13
        :
        #import "FIRAppInternal.h"
                ^
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FIRAppInternal.h:17:9: error:
        include of non-modular header inside framework module
        'FirebaseCoreExtension.FIRAppInternal':
        '/Users/jarjar/project1/ios/Pods/Headers/Public/FirebaseCore/FIRApp.h'
        #import <FirebaseCore/FIRApp.h>
                ^
        /Users/jarjar/project1/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Stor
        age.swift:23:29: error: could not build Objective-C module
        'FirebaseCoreExtension'
        @_implementationOnly import FirebaseCoreExtension
                                    ^
        <module-includes>:1:9: note: in file included from <module-includes>:1:
        #import "Headers/FirebaseCoreExtension-umbrella.h"
                ^
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FirebaseCoreExtension-umbrella.h:13
        :9: note: in file included from
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FirebaseCoreExtension-umbrella.h:13
        :
        #import "FIRAppInternal.h"
                ^
        /Users/jarjar/project1/build/ios/Debug-iphonesimulator/FirebaseCoreExtension
        /FirebaseCoreExtension.framework/Headers/FIRAppInternal.h:17:9: error:
        include of non-modular header inside framework module
        'FirebaseCoreExtension.FIRAppInternal':
        '/Users/jarjar/project1/ios/Pods/Headers/Public/FirebaseCore/FIRApp.h'
        #import <FirebaseCore/FIRApp.h>
                ^
     ...
    
    
    Swift Compiler Error (Xcode): Could not build Objective-C module
    'FirebaseCoreExtension'
    /Users/jarjar/project1/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Storage.
    swift:22:28
    
    
    Uncategorized (Xcode): Command EmitSwiftModule failed with a nonzero exit code
    
    
    Could not build the application for the simulator.
    Error launching application on iPhone 12.

项目Podfile配置

# Uncomment this line to define a global platform for your project
platform :ios, '10.0'

use_modular_headers!
# Add the Firebase pod for Google Analytics


pod 'FirebaseAnalytics'

# For Analytics without IDFA collection capability, use this pod instead
# pod 'Firebase/AnalyticsWithoutAdIdSupport'

# Add the pods for any other Firebase products you want to use in your app
# For example, to use Firebase Authentication and Cloud Firestore
pod 'FirebaseAuth'
pod 'FirebaseFirestore'
pod 'Firebase'
pod 'FirebaseCoreInternal'
pod 'GoogleUtilities'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)

    # Start of the permission_handler configuration
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'

      # You can enable the permissions needed here. For example to enable camera
      # permission, just remove the `#` character in front so it looks like this:
      #
      # ## dart: PermissionGroup.camera
      # 'PERMISSION_CAMERA=1'
      #
      #  Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler_apple/ios/Classes/PermissionHandlerEnums.h
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.calendar
        # 'PERMISSION_EVENTS=1',

        ## dart: PermissionGroup.reminders
        # 'PERMISSION_REMINDERS=1',

        ## dart: PermissionGroup.contacts
        # 'PERMISSION_CONTACTS=1',

        ## dart: PermissionGroup.camera
        'PERMISSION_CAMERA=1',

        ## dart: PermissionGroup.microphone
        'PERMISSION_MICROPHONE=1',

        ## dart: PermissionGroup.speech
        # 'PERMISSION_SPEECH_RECOGNIZER=1',

        ## dart: PermissionGroup.photos
        'PERMISSION_PHOTOS=1',

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        # 'PERMISSION_LOCATION=1',

        ## dart: PermissionGroup.notification
        # 'PERMISSION_NOTIFICATIONS=1',

        ## dart: PermissionGroup.mediaLibrary
        'PERMISSION_MEDIA_LIBRARY=1',

        ## dart: PermissionGroup.sensors
        # 'PERMISSION_SENSORS=1',   

        ## dart: PermissionGroup.bluetooth
        # 'PERMISSION_BLUETOOTH=1',

        ## dart: PermissionGroup.appTrackingTransparency
        # 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

        ## dart: PermissionGroup.criticalAlerts
        # 'PERMISSION_CRITICAL_ALERTS=1'
      ]

    end 
    # End of the permission_handler configuration

  end
end

项目Info.plist配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>project1</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>project1</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
    </array>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>https</string>
        <string>http</string>
    </array>
    <key>NSCameraUsageDescription</key>
    <string>Share photos and add profile images</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>Create audio to be shared with other app users</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Share photos and add profile images</string>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
</dict>
</plist>

解决步骤

核心问题是FirebaseCoreExtension模块无法构建,原因是框架模块内引入了非模块化头文件,以下是可行的解决方法:

  • 清理旧构建文件和Pods
    执行命令清理Flutter缓存:

    flutter clean
    

    进入iOS目录删除冗余文件:

    cd ios
    rm -rf Pods Podfile.lock
    
  • 调整Podfile配置

    1. 升级最低iOS版本到12.0,适配新版Firebase,替换框架配置为静态链接:
      platform :ios, '12.0'
      use_frameworks! :linkage => :static
      
    2. 移除手动添加的pod 'FirebaseCoreInternal'、pod 'GoogleUtilities',这些会被Flutter Firebase插件自动管理,手动添加易引发版本冲突。
    3. 使用Firebase集成式pod简化配置:
      pod 'Firebase/Analytics'
      pod 'Firebase/Auth'
      pod 'Firebase/Firestore'
      
  • 重新安装Pods并构建
    回到项目根目录执行:

    flutter pub get
    cd ios
    pod install --repo-update
    flutter run
    
  • 临时修复头文件问题(可选)
    打开iOS目录下的Runner.xcworkspace,在Build Settings中找到Allow Non-modular Includes In Framework Modules,设置为YES。

  • 修复跨平台克隆文件问题
    从Windows克隆的项目可能存在换行符或权限问题,执行以下命令修复:

    git config --global core.autocrlf input
    git rm --cached -r .
    git reset --hard
    

内容的提问来源于stack exchange,提问作者Jar Jar Claus

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 16:27:39