库未加载:@rpath/hermes.framework/hermes

Dra*_*ian 13 xcode cocoapods react-native react-native-hermes

我已经在我的react-native(v0.64)应用程序中启用了Hermes。每次我运行应用程序时,我都会得到以下堆栈跟踪。

dyld: dyld cache load error: shared cache file open() failed
dyld: Library not loaded: @rpath/hermes.framework/hermes
  Referenced from: /Users/sharktank/Library/Developer/CoreSimulator/Devices/A32F4931-51A8-4D22-AEFB-625F834CE221/data/Containers/Bundle/Application/71773888-08D5-4B82-9545-07F6B1538864/COSPM-DEV.app/COSPM-DEV
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/sharktank/Library/Developer/CoreSimulator/Caches/dyld/20E232/com.apple.CoreSimulator.SimRuntime.iOS-14-4.18D46
DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/sharktank/Library/Developer/Xcode/DerivedData/COSPM-atbujvbobdbyehckyoqrdgmqiubm/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSim
(lldb) 
Run Code Online (Sandbox Code Playgroud)

我已经在 Podfile 中启用了 Hermes,在 pod install 后,Pods 文件夹中可以使用 pod。项目与其他项目一起采用单一存储库架构。在同一个 mono-repo 包中启用 Hermes 的另一个应用程序工作正常,没有崩溃。

播客文件:

require_relative '../../../node_modules/react-native/scripts/react_native_pods'
require_relative '../../../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'
source 'https://github.com/CocoaPods/Specs.git'

target 'COSPM' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => true
  )

  pod 'RNVectorIcons', :path => '../../../node_modules/react-native-vector-icons'

 # Firebase
  pod 'Firebase'
  pod 'Firebase/Core'
  pod 'Firebase/Messaging'
  pod 'CodePush', :path => '../../../node_modules/react-native-code-push'


  target 'COSPMTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
  end
end

Run Code Online (Sandbox Code Playgroud)

我正在使用 Xcode 12.4。

我尝试过但不起作用的解决方案:

  1. 清理 Pod 和 npm 包,清理以前的构建并重建
  2. 清除守望者和地铁捆绑器缓存并重建

小智 13

我在 React Native 0.70 上遇到了同样的问题

选择应用程序目标,然后按照步骤操作

  • 转到构建阶段
  • 内部链接二进制与库部分
  • 单击“添加项目”并搜索hermes.xcframework并添加它
  • 重建应用程序

在此输入图像描述


twi*_*wiz 9

其他答案建议禁用 Hermes 或手动将其添加为链接库,但这不是必需的。

最新版本应该会自动安装 Hermes 框架。

该问题似乎与使用不正确版本的 CocoaPods 和 pods 存储库有关。

要使所有内容保持最新,请执行以下操作:

  1. 确保您的GemfileReact Native 版本是最新的。您可以使用升级助手来查看是否需要更改。
  2. 将 Ruby 升级到项目的Gemfile. (指示
  3. 将 CocoaPods 升级到最新版本:bundle install
  4. 更新 CocoaPods 存储库:bundle exec pod repo update
  5. 删除Podfile.lock
  6. 重新安装 Podcd ./ios && bundle exec pod install

如果仍然出现错误,请仔细检查是否实际使用了正确的版本(在您的 中PATH)。

如果您想了解更多详细信息,我还发表了一篇关于此错误的博客文章:https://traviswimer.com/blog/cocoapods-could-not-find-兼容-versions-for-pod-hermes-engine/

更新(2023 年 1 月 17 日)

我更新了这个答案以使用Bundler 工具来管理 Ruby 和 Cocoapods 版本。该bundle命令现在是在 React Native 项目中使用 Cocoapods 的推荐方式。它根据项目中列出的版本运行命令Gemfile(随每个版本的 React Native 更新)。如果由于某种原因您无法使用bundle,您可以使用以下方法手动升级 Cocoapods:gem install cocoapods

然后运行其他不带bundle exec. (例如pod repo updatepod install

  • 这应该有更多的赞成票并成为答案。人们不必编辑 xcode 项目来启动一个干净的 React Native 项目。 (2认同)

小智 6

这解决了我在 RN 0.70 中的问题。在 Xcode 中,目标 -> 构建阶段 -> 将二进制文件与库链接

在此输入图像描述


小智 4

尝试以下操作:

  1. 将 Podfile 中的值从 true更改hermes_enabled为 false
  2. 通过 (yarn install) 重新安装 npm/yarn 依赖项
  3. 重新安装 pods(cd ios && pods install)
  4. 运行应用程序(react-native run-ios)

我尝试了几次将 hermes_enabled 从 true 更改为 false 并返回,一旦它开始工作。