"Undefined symbols for architecture x86_64 error" 在 iOS 从 React Navigation 5 迁移到 6 时

"Undefined symbols for architecture x86_64 error" when migrating from React Navigation 5 to 6 on iOS

我正在使用 React Native 开发应用程序并尝试从 React Navigation 5 迁移到 6。为此,我遵循了 Upgrading from 5.x 指南中的步骤。

React 和 React Native 的版本是:

"react": "17.0.2",
"react-native": "0.67.2",

我已经安装了这些软件包:

"@react-navigation/bottom-tabs": "^6.2.0",
"@react-navigation/native": "^6.0.8",
"@react-navigation/stack": "^6.1.1",
"react-native-safe-area-context": "^3.4.1",
"react-native-screens": "^3.12.0",
"react-native-tab-view": "^3.1.1",

升级包后,我在 ios 文件夹中 运行 pod install 命令。

如果我 运行 npx react-native run-ios --simulator="iPhone 13" 命令或我在使用 Xcode 的设备上 运行,我得到这个错误:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_RNSSearchBar", referenced from:
      objc-class-ref in libRNScreens.a(RNSScreenStackHeaderConfig.o)
  "_OBJC_CLASS_$_RNSScreenStackAnimator", referenced from:
      objc-class-ref in libRNScreens.a(RNSScreenStack.o)
  "_OBJC_CLASS_$_RNSScreenWindowTraits", referenced from:
      objc-class-ref in libRNScreens.a(RNSScreen.o)
      objc-class-ref in libRNScreens.a(RNSScreenStack.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

看起来 libRNScreens.a 来自 react-native-screens 包。

你知道如何解决这个问题吗?

可能与在 Podfile 中使用 use_frameworks! 有关。尝试将以下步骤添加到您的 Podfile:

pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNScreens')
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

详情Here

解决方法很简单

删除这个

Xcode -> 构建设置 -> 搜索路径 -> 库搜索路径 -> "$(TOOLCHAINDIR)/usr/lib/swift-5.0/$(PLATFORMNAME)"

解决我的问题的最简单方法是将 react-native-screens 库降级到版本 3.11.1。现在它运行没有问题。