React Native 0.82.1在 Xcode 26上构建失败,原因是Yoga、fmt、glog的 C++ constexpr错误

移动开发 2026-07-09

环境

  • React Native: 0.82.1
  • React: 19.1.1
  • Node: 20.19.6
  • CocoaPods: 最新版
  • Xcode: 26
  • macOS Tahoe

错误

构建在原生依赖项中失败,例如:

  • Yoga
  • fmt
  • glog

一些主要错误包括:

constexpr function never produces a constant expression
call to consteval function ... is not a constant expression

以及来自以下文件的失败:

Pods/fmt/src/format.cc
ReactCommon/yoga/...
Pods/glog/src/...

最终构建以以下内容退出:

xcodebuild exited with error code 65

我已经尝试过的办法

  • 清理Pods / DerivedData
  • 重新安装node_modules
  • 再次运行 pod install
  • 禁用Hermes
  • 禁用Fabric / 新架构(New Architecture)
  • 强制 gnu++17
  • 添加自定义 OTHER_CPLUSPLUSFLAGS

然而,React Native 0.82似乎在内部强制使用新架构的部分内容,因此禁用它现在也无法完全奏效。

尝试的Podfile变更

config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'gnu++17'

以及:

:hermes_enabled => false

问题

有没有人在Xcode 26上成功构建React Native 0.82.x?

这是否是RN 0.82与 Xcode 26工具链之间的已知兼容性问题,还是除了降级Xcode之外有稳定的解决办法?

解决方案

在把我的Expo应用向前推进并使用更新的Xcode版本构建后,我遇到了同样的失败。

就我而言,清理pods或禁用新架构并没有解决。问题最终出在原生pods使用了与更新后的编译器不太兼容的新设置,尤其是对 fmtconsteval 的检测。

解决方法是在pod install期间用一个expo插件对该pod进行打补丁。

在我的Expo应用中,我把它包装在一个配置插件里,这样每次重新生成iOS项目/Podfile时都会应用。

const fs = require("fs");
const path = require("path");
const generateCode = require("@expo/config-plugins/build/utils/generateCode");
const configPlugins = require("@expo/config-plugins");

const code = `
  installer.pods_project.targets.each do |target|
    next unless target.name == 'fmt'

    target.build_configurations.each do |config|
      config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'

      definitions = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] || ['$(inherited)']
      definitions = [definitions] unless definitions.is_a?(Array)
      unless definitions.include?('FMT_USE_CONSTEVAL=0')
        definitions << 'FMT_USE_CONSTEVAL=0'
      end
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = definitions

      cpp_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] || ['$(inherited)']
      cpp_flags = [cpp_flags] unless cpp_flags.is_a?(Array)
      unless cpp_flags.include?('-DFMT_USE_CONSTEVAL=0')
        cpp_flags << '-DFMT_USE_CONSTEVAL=0'
      end
      config.build_settings['OTHER_CPLUSPLUSFLAGS'] = cpp_flags
    end
  end

  fmt_base_header = File.join(installer.sandbox.root.to_s, 'fmt', 'include', 'fmt', 'base.h')
  if File.exist?(fmt_base_header)
    contents = File.read(fmt_base_header)
    old = "#if !defined(__cpp_lib_is_constant_evaluated)\n"
    new_text = "#ifdef FMT_USE_CONSTEVAL\n// Use the provided definition.\n#elif !defined(__cpp_lib_is_constant_evaluated)\n"
    if contents.include?(old)
      File.write(fmt_base_header, contents.sub(old, new_text))
    end
  end
`;

const withIosFmtFix = (config) => {
  return configPlugins.withDangerousMod(config, [
    "ios",
    async (config) => {
      const filePath = path.join(
        config.modRequest.platformProjectRoot,
        "Podfile",
      );
      const contents = fs.readFileSync(filePath, "utf-8");

      const addCode = generateCode.mergeContents({
        tag: "withIosFmtFix",
        src: contents,
        newSrc: code,
        anchor: /post_install do \|installer\|/i,
        offset: 1,
        comment: "#",
      });

      if (!addCode.didMerge) {
        console.error(
          "ERROR: Cannot add fmt iOS workaround to the project's ios/Podfile because it's malformed.",
        );
        return config;
      }

      fs.writeFileSync(filePath, addCode.contents);
      return config;
    },
  ]);
};

module.exports = withIosFmtFix;

在app.json

{
...
    "plugins": [
        ...,
        "./expo-plugins/ios-fmt-fix",
]
}

这实现了三件事:

  • 专门针对fmt Pod
  • 将CLANG_CXX_LANGUAGE_STANDARD强制设为C++17
  • 添加FMT_USE_CONSTEVAL=0
  • 修补Pods/fmt/include/fmt/base.h,使该宏真正生效

这解决了我的构建中的 fmt / consteval / constexpr 失败。

需要注意的是,你的错误列表中也提到了 Yogaglog,因此这份补丁未必单独就能完全解决问题。它只是针对 fmt 的有针对性的解决方法,并非通用的React Native 0.82 / Xcode 26兼容性修复。如果你的首个硬性失败是fmt,这可能会为你解难。但如果构建继续并在Yoga或 glog处失败,你可能需要类似的Pod级变通方法,或等待上游的React Native / CocoaPods依赖更新。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章