React Native iOS构建失败:React Logger与glog相关报错求助
React Native iOS构建失败解决指南
问题概述
Android端运行正常,但执行npx react-native run-ios或直接通过Xcode构建均失败,核心报错包含Swift Package的Docs.docc加载冲突,以及React-logger模块编译失败。
命令行报错详情
2023-02-16 11:27:07.190 xcodebuild[10406:767829] [MT] IDEFileReferenceDebug: [Load] <IDESwiftPackageCore.IDESwiftPackageSpecialFolderFileReference, 0x7f95f65afc30: name:Docs.docc path:group:Docs.docc> Failed to load container at path: /Users/shubhagarwal/Library/Developer/Xcode/DerivedData/weedlemobiledapptraining-cngaloxjuncutwengkgnppfnmbtd/SourcePackages/checkouts/swift-protobuf/Sources/protoc-gen-swift/Docs.docc, Error: Error Domain=com.apple.dt.IDEContainerErrorDomain Code=6 "Cannot open "Docs.docc" as a "Swift Package Folder" because it is already open as a "Folder"." UserInfo={NSLocalizedDescription=Cannot open "Docs.docc" as a "Swift Package Folder" because it is already open as a "Folder".} ** BUILD FAILED ** The following build commands failed: CompileC /Users/shubhagarwal/Library/Developer/Xcode/DerivedData/weedlemobiledapptraining-cngaloxjuncutwengkgnppfnmbtd/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-logger.build/Objects-normal/x86_64/react_native_log.o /Users/shubhagarwal/Desktop/metawork/portal-react-native/node_modules/react-native/ReactCommon/logger/react_native_log.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'React-logger' from project 'Pods') (1 failure)
Xcode构建时也弹出同类错误提示,核心内容与命令行报错一致。
当前Podfile配置
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking") require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods") require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), "native_modules") require 'json' podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {} $RNFirebaseAsStaticFramework = true platform :ios, podfile_properties['ios.deploymentTarget'] || '12.0' install! 'cocoapods', :deterministic_uuids => false target 'weedlemobiledapptraining' do use_expo_modules! use_modular_headers! # use_frameworks! config = use_native_modules! # use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config[:reactNativePath], :hermes_enabled => flags[:hermes_enabled] || podfile_properties['expo.jsEngine'] == 'hermes', :fabric_enabled => flags[:fabric_enabled], # An absolute path to your application root. :app_path => "#{Dir.pwd}/.." ) # Uncomment to opt-in to using Flipper # Note that if you have use_frameworks! enabled, Flipper will not work # # if !ENV['CI'] # use_flipper!() # end post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end post_integrate do |installer| begin expo_patch_react_imports!(installer) rescue => e Pod::UI.warn e end end end
环境版本信息
- node: 14.21.2
- React: 17.0.2
- React Native: 0.68.2
- Xcode: 12.1
已尝试无效方案
- 多次重装Node Modules和Pods
- 移除
use_frameworks!或use_modular_headers!配置 - 在Podfile中添加glog依赖
针对性解决方案
1. 彻底清理Xcode缓存
执行以下命令清理DerivedData和项目构建缓存:
rm -rf ~/Library/Developer/Xcode/DerivedData xcodebuild clean -project ios/weedlemobiledapptraining.xcodeproj -scheme weedlemobiledapptraining -configuration Debug
2. 重置Swift Package缓存
打开Xcode操作步骤:File > Packages > Reset Package Caches
等待缓存重置完成后,重新尝试构建。
3. 适配Xcode版本调整Pod脚本
Xcode 12.1与React Native 0.68.x的C++编译标准存在兼容性问题,修改Podfile的post_install脚本,强制React-logger使用兼容的编译标准:
post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) # 新增:设置React-logger的C++编译标准 installer.pods_project.targets.each do |target| if target.name == 'React-logger' target.build_configurations.each do |config| config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17' config.build_settings['CLANG_CXX_LIBRARY'] = 'libc++' end end end end
4. 重新安装依赖
修改Podfile后,重新执行依赖安装:
rm -rf node_modules && npm install cd ios && pod deintegrate && pod install && cd ..
5. 手动移除冲突的Swift Package缓存
如果上述步骤无效,手动删除swift-protobuf的缓存目录:
rm -rf ~/Library/Developer/Xcode/DerivedData/*/SourcePackages/checkouts/swift-protobuf
内容的提问来源于stack exchange,提问作者shubhraagarwal
相关产品推荐
相关产品推荐

