升级Xcode14.3后Flutter iOS编译报错:找不到__ObjC模块
Flutter iOS编译失败:找不到__ObjC模块问题解决
问题背景
升级Xcode至14.3版本后,使用Flutter构建iOS应用时编译失败,核心报错为找不到__ObjC模块,完整报错信息如下:
Launching lib/main.dart on iPhone 13 Pro Max in debug mode... main.dart:1 Xcode build done. 42.7s Failed to build iOS app Swift Compiler Error (Xcode): Using bridging headers with module interfaces is unsupported Uncategorized (Xcode): Command SwiftDriver emitted errors but did not return a nonzero exit code to indicate failure Error (Xcode): no such module '__ObjC' /Users/myname/Library/Developer/Xcode/DerivedData/Runner-gnvomxdvkbnvhiftqgeatxtbshib/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Objects-normal/arm64/Runner.private.swiftinterface:11:18 Error (Xcode): failed to verify module interface of 'Runner' due to the errors above; the textual interface may be broken by project issues or a compiler bug /Users/myname/Library/Developer/Xcode/DerivedData/Runner-gnvomxdvkbnvhiftqgeatxtbshib/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Objects-normal/arm64/Runner.private.swiftinterface:0:0 Error (Xcode): no such module '__ObjC' /Users/myname/Library/Developer/Xcode/DerivedData/Runner-gnvomxdvkbnvhiftqgeatxtbshib/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Objects-normal/arm64/Runner.swiftinterface:11:18 Error (Xcode): failed to verify module interface of 'Runner' due to the errors above; the textual interface may be broken by project issues or a compiler bug /Users/myname/Library/Developer/Xcode/DerivedData/Runner-gnvomxdvkbnvhiftqgeatxtbshib/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Objects-normal/arm64/Runner.swiftinterface:0:0 Could not build the application for the simulator. Error launching application on iPhone 13 Pro Max. Exited
当前环境信息
[✓] Flutter (Channel stable, 3.7.6, on macOS 13.3.1 22E261 darwin-arm64, locale ja-JP) • Flutter version 3.7.6 on channel stable at /Users/myname/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 12cb4eb7a0 (6 weeks ago), 2023-03-01 10:29:26 -0800 • Engine revision ada363ee93 • Dart version 2.19.3 • DevTools version 2.20.1 [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/myname/Library/Android/sdk • Platform android-33, build-tools 32.1.0-rc1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E222b • CocoaPods version 1.12.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) [✓] VS Code (version 1.77.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.62.0 [✓] Connected device (3 available) • iPhone 13 Pro Max (mobile) • 63E17FF6-0922-418E-A209-49173C8A4E71 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.3.1 22E261 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.49 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found!
解答
一、__ObjC是什么?
__ObjC是Swift编译器自动生成的底层模块,用于实现Swift与Objective-C代码之间的桥接交互,属于系统级支撑模块,无需开发者手动引入或修改。
二、解决方法
结合报错信息中的Using bridging headers with module interfaces is unsupported,以及当前Flutter和Xcode版本的兼容性问题,按以下步骤逐一尝试:
升级Flutter到兼容版本
Flutter 3.7.6对Xcode 14.3的兼容性存在缺陷,建议升级到stable通道的3.7.10及以上版本,或直接切换到3.10.x系列版本:flutter channel stable flutter upgrade调整Xcode项目编译设置
打开iOS目录下的Runner.xcworkspace,执行以下操作:- 选中
Runner目标,进入Build Settings面板 - 搜索
Swift Compiler - General分类下的Enable Module Interfaces,将其设置为NO - 清理构建缓存:通过Xcode菜单选择
Product > Clean Build Folder,或手动删除~/Library/Developer/Xcode/DerivedData下对应项目的缓存文件夹
- 选中
更新CocoaPods并重新安装依赖
升级CocoaPods至最新版本,然后重置iOS依赖:sudo gem install cocoapods cd ios pod deintegrate pod install临时降级Xcode(可选)
若上述方法均无效,可临时降级至Xcode 14.2版本,该版本与Flutter 3.7.6兼容性更好。
内容的提问来源于stack exchange,提问作者yolo
相关产品推荐
相关产品推荐

