Xcode 13 + M1芯片下iOS构建报错求助(模块映射文件缺失)
问题:Xcode 13 + Apple M1设备构建项目时模块映射文件缺失错误
构建项目时抛出以下错误:
<unknown>:0: error: module map file '/Users/xxxx/Library/Developer/Xcode/DerivedData/xx-cwbykxafbbbrfjbaeyuaxhdrivdp/Build/Products/Debug-iphonesimulator/Stripe/Stripe.modulemap' not found <unknown>:0: error: module map file '/Users/xxxx/Library/Developer/Xcode/DerivedData/xx-cwbykxafbbbrfjbaeyuaxhdrivdp/Build/Products/Debug-iphonesimulator/YogaKit/YogaKit.modulemap' not found Command PrecompileSwiftBridgingHeader emitted errors but did not return a nonzero exit code to indicate failure
已尝试修改Podfile添加架构排除配置(如下),并尝试打开workspace文件重新构建,但错误仍未解决:
installer.aggregate_targets.each do |aggregate_target| aggregate_target.user_project.native_targets.each do |target| target.build_configurations.each do |config| config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(inherited)'] # or it won't build on apple silicon # without explicitly clearing this out, it flaps between excluding arm64 or not # Fix some library / linker errors config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES' # only one at a time config.build_settings['VALID_ARCHS'] = 'arm64 x86_64' # you need both to work on both CPU archs / release etc config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end end aggregate_target.user_project.save end installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # We support a smaller range of deployment than some libraries, eliminate related noise # This also avoids a nasty Folly bug about an API not available until ios10+ config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' end end
可行解决方向
1. 清理构建缓存并重新安装依赖
- 执行Xcode菜单栏的
Product > Clean Build Folder(快捷键Cmd+Shift+K)清理本地构建缓存 - 手动删除项目对应的DerivedData目录:前往
~/Library/Developer/Xcode/DerivedData,找到当前项目的文件夹直接删除 - 终端执行
pod deintegrate && pod install,重新生成Pods配置后打开workspace构建
2. 优化Podfile的架构配置
替换原有Podfile中的post_install代码块为更精准的版本,避免架构冲突:
post_install do |installer| # 配置Pods项目的模拟器架构排除 installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" # 清空VALID_ARCHS避免与Xcode默认配置冲突 config.build_settings['VALID_ARCHS'] = '' end end # 配置主项目的架构排除及Swift路径 installer.aggregate_targets.each do |aggregate_target| aggregate_target.user_project.native_targets.each do |target| target.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" config.build_settings['VALID_ARCHS'] = '' config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(inherited)'] end end aggregate_target.user_project.save end end
修改后执行pod install,重新构建项目。
3. 检查Swift桥接文件配置
- 确认项目
Build Settings中,Swift Compiler - General下的Objective-C Bridging Header路径正确,需使用相对于项目根目录的相对路径(例如$(SRCROOT)/YourProjectName/Bridging-Header.h) - 检查桥接文件中是否重复导入Stripe或YogaKit的头文件,如有则删除冗余导入
4. 更新依赖版本
- 终端执行
sudo gem install cocoapods将CocoaPods升级到最新稳定版,确保对M1设备的支持 - 执行
pod update Stripe YogaKit更新这两个依赖到适配M1模拟器的版本,旧版本可能存在模块映射生成的兼容性问题
5. 调整Release配置的架构编译选项
如果是Release构建出现该问题,检查项目和Pods的Build Settings:
- 将
Build Active Architecture Only在Release配置下设置为NO,确保编译所有指定的架构 - 确认
VALID_ARCHS在Release配置中包含arm64 x86_64
内容的提问来源于stack exchange,提问作者KOTIOS
相关产品推荐
相关产品推荐

