Xcode中React Native Hermes-engine沙箱错误:构建时rsync.samba拒绝写入
iOS模拟器rsync.samba沙箱写入权限错误解决方案
问题详情
在iPhone 15模拟器(iOS 17.5)上运行React Native应用时,触发以下沙箱权限错误:
Sandbox: rsync.samba(18075) deny(1) file-write-create /Users/vrtechsol/Library/Developer/Xcode/DerivedData/DermPro-brtigadkswuknhfeyqfvrkuganwx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/hermes-engine/Pre-built/hermes.framework/.Info.plist.wddhxQ Sandbox: rsync.samba(18075) deny(1) file-write-create /Users/vrtechsol/Library/Developer/Xcode/DerivedData/DermPro-brtigadkswuknhfeyqfvrkuganwx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/hermes-engine/Pre-built/hermes.framework/.hermes.HeTRbR
项目在真机环境运行正常,切换到模拟器后出现该问题,已尝试常规清理操作但无效。
项目Podfile配置
# Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( "react-native/scripts/react_native_pods.rb", {paths: [process.argv[1]]}, )', __dir__]).strip platform :ios, min_ios_version_supported prepare_react_native_project! linkage = ENV['USE_FRAMEWORKS'] if linkage != nil Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green # use_frameworks! :linkage => linkage.to_sym end target 'DermPro' do config = use_native_modules! use_react_native!( :path => config[:reactNativePath], # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) target 'DermProTests' do inherit! :complete # Pods for testing end post_install do |installer| # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false, # :ccache_enabled => true ) end end
已尝试无效的解决方法
- 删除
node_modules、Pods文件夹及Podfile.lock,重新安装依赖 - Xcode中清理构建文件夹并手动删除DerivedData目录
- 将Xcode全局构建设置中的
ENABLE_USER_SCRIPT_SANDBOXING改为NO
有效解决方案
方案1:针对hermes-engine目标单独禁用脚本沙箱
在Podfile的post_install块中添加代码,单独为hermes-engine目标关闭脚本沙箱限制:
post_install do |installer| # 保留原有react_native_post_install代码 react_native_post_install( installer, config[:reactNativePath], :mac_catalyst_enabled => false, # :ccache_enabled => true ) # 新增:为hermes-engine禁用脚本沙箱 installer.pods_project.targets.each do |target| if target.name == 'hermes-engine' target.build_configurations.each do |config| config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'NO' end end end end
修改后执行pod install,重新构建项目。
方案2:调整rsync脚本的临时文件路径
如果方案1无效,可修改hermes-engine的rsync脚本,将临时文件写入系统允许的临时目录:
- 找到
Pods/hermes-engine/hermes-engine.podspec文件 - 定位到
prepare_command相关代码,将rsync命令中的临时文件路径替换为$(TMPDIR)下的目录,避免写入沙箱限制的DerivedData路径
方案3:降级Xcode版本(临时兼容方案)
若上述方案均无效,可尝试降级到Xcode 15.3或更早版本,部分开发者反馈iOS 17.5模拟器在Xcode 15.4中存在沙箱权限兼容问题。
内容的提问来源于stack exchange,提问作者Abdullah Jaspal
相关产品推荐
相关产品推荐

