You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo SDK 47 搭配Xcode 15构建失败:std::unary_function名称不匹配求解决方案

Expo 47托管工作流iOS构建:std::unary_function 错误临时修复方案

这个错误源于Xcode 14+(对应iOS SDK 16+)移除了C++标准库中的std::unary_function,而Expo 47依赖的boost版本仍在使用该类型。以下是无需升级Expo版本的临时解决办法:

方法1:用patch-package给boost打补丁

  • 安装依赖:
    npm install patch-package --save-dev
    
  • 找到本地项目的ios/Pods/boost/boost/container_hash/hash.hpp文件,修改第131行:
    将
    struct hash_base : std::unary_function<T, std::size_t> {};
    
    替换为
    struct hash_base {};
    
    或添加C++版本判断以兼容旧标准:
    #if __cplusplus <= 201703L
    struct hash_base : std::unary_function<T, std::size_t> {};
    #else
    struct hash_base {};
    #endif
    
  • 生成补丁并提交到版本控制:
    npx patch-package boost
    
  • 在package.json中添加postinstall脚本,确保EAS构建时自动应用补丁:
    "scripts": {
      "postinstall": "patch-package"
    }
    

方法2:EAS构建预安装脚本自动修改文件

无需本地维护补丁,通过构建流程自动修复:

  • 项目根目录创建eas-build-pre-install.sh脚本:
    #!/bin/bash
    if [ "$PLATFORM" = "ios" ]; then
      sed -i '' 's/struct hash_base : std::unary_function<T, std::size_t> {}/struct hash_base {};/' ios/Pods/boost/boost/container_hash/hash.hpp
    fi
    
  • 赋予脚本执行权限:
    chmod +x eas-build-pre-install.sh
    
  • 在eas.json的各iOS构建配置中添加预安装命令:
    {
      "build": {
        "production": {
          "ios": {
            "preInstallCommand": "./eas-build-pre-install.sh"
          }
        },
        "development": {
          "ios": {
            "preInstallCommand": "./eas-build-pre-install.sh"
          }
        }
      }
    }
    

方法3:指定兼容的iOS部署目标

降低iOS部署目标到15.x,使用仍支持std::unary_function的标准库:
修改app.json中的iOS配置:

{
  "expo": {
    "ios": {
      "deploymentTarget": "15.5",
      "sdkVersion": "47.0.0"
    }
  }
}

注意:此方法可能影响部分依赖的兼容性,需测试验证。

内容的提问来源于stack exchange,提问作者Piotr Szlagura

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 20:02:42