Xcode 15.0/15.0.1下Flutter集成Sentry运行失败求助
遇到的报错:
模块问题(Xcode):在extern "C"语言链接规范内导入了C模块'Darwin.Mach'
路径:/Users/xxx/xxx/Projects/flutter_project/ios/Pods/Sentry/Sources/SentryCrash/Recording/Tools/SentryCrashMachineContext.h:35:0
模块问题(Xcode):在extern "C"语言链接规范内导入了C模块'Darwin.POSIX.sys.types'
路径:/xxx/xxx/Desktop/Projects/flutter_project/ios/Pods/Sentry/Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.h:35:0
以下是几个实测有效的解决方法:
更新 Sentry Flutter 插件到最新版
打开项目根目录的pubspec.yaml,将sentry_flutter的版本号替换为当前最新稳定版,执行flutter pub get拉取依赖。然后进入 ios 目录,执行pod install --repo-update重新安装 Pods。这类编译器兼容性问题通常会在插件新版本中修复,优先尝试这个方案。修改 Podfile 关闭 SentryCrash 的模块编译
在 ios/Podfile 末尾添加如下配置:post_install do |installer| installer.pods_project.targets.each do |target| if target.name == 'SentryCrash' target.build_configurations.each do |config| config.build_settings['CLANG_ENABLE_MODULES'] = 'NO' end end end end保存后执行
pod install,重新编译项目即可。清理项目缓存
执行flutter clean清理 Flutter 缓存,删除 ios 目录下的Pods文件夹和Podfile.lock文件,再重新执行pod install。同时在 Xcode 中按下Cmd+Shift+K清理构建缓存,重启 Xcode 后再尝试编译。临时降级 Xcode 版本
如果上述方法都无效,可以暂时降级到 Xcode 14.x 稳定版本(比如 14.3.1),等待 Sentry 官方完全适配 Xcode 15 后再升级。
内容的提问来源于stack exchange,提问作者Am Koem Heang

