升级React Native至0.64.4后Xcode无法构建Darwin模块求助
解决React Native 0.64.4在M1设备上构建时「无法构建模块'Darwin'」的问题
针对你升级RN后在M1 MacBook Pro上遇到的构建错误,以下是经过验证的解决步骤:
1. 调整Podfile配置
修改你的Podfile,重点更新post_install钩子的编译设置,同时确保iOS版本适配:
source 'https://github.com/CocoaPods/Specs.git' require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' # RN 0.64最低支持iOS 11.0,升级到13.0提升M1设备兼容性 platform :ios, '13.0' target 'MyApp' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], :hermes_enabled => false ) pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo' pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler' permissions_path = '../node_modules/react-native-permissions/ios' pod 'Permission-Camera', :path => "#{permissions_path}/Camera" pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency" #use_flipper!() post_install do |installer| react_native_post_install(installer) # 处理M1设备架构冲突与系统模块引用问题 installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # 排除i386架构,避免模拟器编译报错 config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'i386' # 确保系统框架路径被正确识别 config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= [] config.build_settings['FRAMEWORK_SEARCH_PATHS'] << '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks' # 修复Darwin头文件引用问题 config.build_settings['HEADER_SEARCH_PATHS'] ||= [] config.build_settings['HEADER_SEARCH_PATHS'] << '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include' end end end end
2. 彻底清理并重新安装依赖
执行以下操作清除旧缓存,确保新配置生效:
- 删除
ios/Pods文件夹和ios/Podfile.lock文件 - 运行终端命令:
cd ios && pod install --repo-update - 打开Xcode,按下
Cmd+Shift+K清理构建,再按Cmd+Option+Shift+K彻底清理构建文件夹
3. 检查Xcode项目Build Settings
打开Xcode中的项目目标,确认以下设置:
- 搜索
VALID_ARCHS:确保真机配置包含arm64,模拟器配置包含arm64 x86_64 - 搜索
FRAMEWORK_SEARCH_PATHS:确认已包含系统框架路径,若未添加则手动补充/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks - 搜索
HEADER_SEARCH_PATHS:添加/usr/include和上述iOS SDK的usr/include路径
4. 验证第三方库兼容性
检查react-native-permissions版本是否适配RN 0.64.x,建议升级到3.6.0及以上版本(该版本对RN 0.64有良好支持),升级后重新执行pod install
完成以上步骤后,重新构建项目即可解决「无法构建模块'Darwin'」的错误。
内容的提问来源于stack exchange,提问作者profidash_98
相关产品推荐
相关产品推荐

