从 0.68.x 升级到 0.69.0 后出现 FBReactNativeSpec.h 错误

53 javascript xcode ios reactjs react-native


我刚刚使用react-native升级命令从RN 0.68.x升级到0.69.0。它显示了有关FBReactNativeSpec“值”不可用的错误:在ios 12.0反应本机中引入 ,当我使用最新版本创建新项目时显示相同的错误版本。

xcode: 12.4 mac版本:10.15.7

在此输入图像描述

在此输入图像描述

Tou*_*der 168

为那些可能很难找到选项的人提供图解答案:

  1. 在 Xcode 项目导航器中,选择 Pods。
  2. 在目标下,选择 React-Codegen
  3. 将窗口设置为“构建设置”
  4. 在“部署”下,将“iOS 部署目标”设置为 12.4
  5. 清理项目并重建:产品>清理构建文件夹,产品>构建

来源:https ://github.com/facebook/react-native/issues/34106#issuecomment-1489549051

在此输入图像描述


小智 33

跟进阿扎兹的回答

您可以为 podfile 中的所有构建配置自动化它

添加

post_install do |installer|
   installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
               config.build_settings['SWIFT_VERSION'] = '5.0'
               config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.4'
       end
   end
end
Run Code Online (Sandbox Code Playgroud)

  • 是的,但最好使用“if target.to_s === 'React-Codegen'”仅针对有问题的 pod,如下面 Joe Davis 的回复所述。 (2认同)

Cem*_*Cem 27

  1. 在 XCode 中打开项目。
  2. Pod>React-Codegen
  3. 将目标版本从 11.0 更改为 12.x。
  4. 建造。

来自 React Native 社区的更新(我还没有尝试升级):https ://github.com/facebook/react-native/issues/34106#issuecomment-1495970568

  • 请检查 XCode 中的“Project Navigator”选项卡(您可以在该选项卡中搜索文件/文件夹)。您可以在那里看到“Pod”。https://imgur.com/a/SHLwAAr 选择“Pods”后,在“Targets”下选择“React-Codegen”,然后从窗口中选择“Build Settings”。“部署”→ 将“iOS 部署目标”设置为 12.x。 (3认同)

Joe*_*vis 8

我知道这个问题已经解决了,但如果有人想要一个仅使用世博会的解决方案(我现在是世博会的忠实粉丝)

下面是如何使用 expo 配置插件修改 podfile,就像 Vivek 的答案一样。

我还添加了一个 if 语句来仅更新,React-codegen因为它是更新 xcode 后唯一给我带来问题的语句14.3

// ./expo-plugins/fix-rn-codegen.js
const { withDangerousMod, withPlugins } = require("@expo/config-plugins");
const { ExpoConfig } = require("@expo/config-types");
const {
  mergeContents,
} = require("@expo/config-plugins/build/utils/generateCode");
const { readFileSync, writeFileSync } = require("fs");
const { resolve } = require("path");

const withFixedDeploymentTarget = (c) => {
  return withDangerousMod(c, [
    "ios",
    async (config) => {
      const file = resolve(config.modRequest.platformProjectRoot, "Podfile");
      const contents = readFileSync(file, { encoding: "utf-8" });
      writeFileSync(file, fixDeploymentTarget(contents));
      return config;
    },
  ]);
};

function fixDeploymentTarget(src) {
  return mergeContents({
    tag: `rn-fix-deployment-target`,
    src,
    newSrc: `
  installer.pods_project.targets.each do |target|
    if target.to_s === 'React-Codegen'
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '5.0'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
      end
    end
  end
`,
    anchor: /post_install/,
    offset: 1,
    comment: "#",
  }).contents;
}

module.exports = (config) => withPlugins(config, [withFixedDeploymentTarget]);
Run Code Online (Sandbox Code Playgroud)

然后将其链接到app.json中

// ./app.json
{
  "expo": {
    "plugins": [
      ["./expo-plugins/fix-rn-codegen.js"]
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你!解决了问题。不要忘记删除 node_modules 和 ios 文件夹,然后运行 ​​'npx expo run:ios' (2认同)

小智 8

下面由Vivek Verma 回答

只需防止覆盖具有更高目标的 Pod(新的 Expo Pod 的目标为 13)。

ios/Podfile

// ios/Podfile
post_install do |installer|
...
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '5.0'
      if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] < '12.4'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.4'
      end
    end
  end
...
end

Run Code Online (Sandbox Code Playgroud)


Dan*_*cki 7

Xcode最近几天升级后就开始出现这种情况。

  1. Xcode项目导航器中,选择Pods
  2. 在 下Targets,选择React-Codegen窗口并将其设置为Build Settings
  3. Deployment,设置iOS Deployment Target12.4
  4. 清理项目并重建。

关于这个问题, https://github.com/facebook/react-native/issues/34106上有一个大讨论。


ryd*_*212 3

我认为这是由您的react-native项目中的一些pod引起的,这些pod不是最新版本,因此其中一些pod的IPHONEOS_DEPLOYMENT_TARGET可能小于12.0

就我而言,我执行了以下步骤

  • 在 VS Code 中,我搜索了 IPHONEOS_DEPLOYMENT_TARGET,我可以看到在 ios/Pods/Pods.xcodeproj/project.pbxproj 文件中,一些 pod 的目标版本低于 12.0,我将它们更新到 12.4(我觉得这一步可以按以下方式排序)将您的软件包更新到最新版本并重新运行 pod install/update 但我有一些软件包最新更新并没有为我改变
  • 在 XCode 顶部菜单下,转到 XCode->首选项 -> 位置 -> 打开派生数据文件夹(通过单击箭头按钮)
  • Finder 将打开 Derived Data 文件夹
  • 删除派生数据文件夹
  • 使用npm start或yarn start启动Metro服务器
  • 在 Xcode 中,使用 cmd+shift+k 执行 Clean build
  • 在 Xcode 中,使用 cmd+r 运行应用程序