12

I have enabled Hermes in my react-native(v0.64) Application. Everytime I run app I get following stack trace.

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) 

I have enabled hermes in Podfile and after pod install pod is available in Pods folder. Project is in monorepo architecture along side another projects. Another app enabled with Hermes in same mono-repo package is working fine without crash.

Podfile:

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

I am using Xcode 12.4.

Solutions I tried which did not work:

  1. Clean Pods and npm packages, clean previous build and rebuild
  2. Clear watchman and metro bundler cache and rebuild
Manish Mahajan
  • 1,140
  • 1
  • 14
  • 38

6 Answers6

14

I was facing the same problem on react native 0.70

Select App Target then follow the steps

  • goto Build Phases
  • Inside Link Binary With Libraries section
  • Click on Add Items and search for hermes.xcframework and add it
  • Rebuild application

enter image description here

Kamaljit
  • 457
  • 4
  • 7
7

The other answers suggest disabling Hermes or manually adding it as a linked library, but this should not be necessary.

The latest version should install the Hermes framework automatically.

The problem seems to be related to using the incorrect version of CocoaPods and the pods repo.

To bring everything up to date, do the following:

  1. Make sure your Gemfile is up to date for your version of React Native. You can use the Upgrade Helper to see if it needs changed.
  2. Upgrade Ruby to the version listed in your project's Gemfile. (Instructions)
  3. Upgrade CocoaPods to the latest version: bundle install
  4. Update the CocoaPods repo: bundle exec pod repo update
  5. Delete Podfile.lock
  6. Reinstall pods cd ./ios && bundle exec pod install

If you're still getting errors, double check that the correct versions are actually being used (are in your PATH).

I also made a blog post about this error if you would like more details: https://traviswimer.com/blog/cocoapods-could-not-find-compatible-versions-for-pod-hermes-engine/

Update (Jan 17, 2023)

I updated this answer to use the Bundler tool to manage Ruby and Cocoapods versions. The bundle command is now the recommended way to use Cocoapods in React Native projects. It runs commands based on the versions listed in your project's Gemfile (which is updated with each version of React Native). If for some reason you are unable to use bundle, you can manually upgrade Cocoapods using: gem install cocoapods

Then run the other commands without bundle exec. (e.g. pod repo update and pod install

twiz
  • 9,041
  • 8
  • 52
  • 84
  • 2
    This should have more upvotes and be the answer. One should not have to edit the xcode project to start a clean react native project. – Andrew Meyer Jan 17 '23 at 12:42
  • @AndrewMeyer If you're still having problems, you may want to check the edits I just made. I forgot to edit this answer when I updated my blog post a while ago. React Native now expects you to use a `Gemfile`, which means the maintainers don't need to support a bunch of random versions/combinations of Ruby and Cocoapods. I think this error is actually a result of most people being unaware of this change. – twiz Jan 18 '23 at 03:02
  • That's a good update. I have no issues, but as a library maintainer for `realm` I run into a lot of users that do. – Andrew Meyer Jan 27 '23 at 08:45
  • @AndrewMeyer In case you need it, here is the GitHub comment where I got this info: https://github.com/facebook/react-native/issues/34608#issuecomment-1320407893 I don't know of any official RN documentation about using the Gemfile/bundle. – twiz Jan 27 '23 at 13:26
  • Updating CocoaPods from 1.10.2 to 1.12.0 solved this issue in my Expo app. Thank you! – Piotr Sobuś Apr 15 '23 at 09:58
  • 1
    This should be the official answer. I tried the other solutions and this is the only one that works for me. No need to add Hermes. Thank you so much. – Cedriga Jun 10 '23 at 00:40
6

This resolved my issue in RN 0.70. In Xcode, Targets -> Build Phases -> Link Binary With Libraries

enter image description here

Iva
  • 2,447
  • 1
  • 18
  • 28
Khurram Ishaq
  • 61
  • 1
  • 2
4

Try following:

  1. Change hermes_enabled value from true to false in Podfile
  2. Reinstall npm/yarn dependencies by (yarn install)
  3. Reinstall pods (cd ios && pods install)
  4. Run app (react-native run-ios)

I tried this a couple of times changing hermes_enabled from true to false and back, and once it starts working.

stavrogyn
  • 79
  • 4
  • I am facing this issue with React native 0.70. As per the above steps now i am able to build the application without any crashing. Thanks lot – karthik mano Sep 06 '22 at 10:48
  • 1
    My dear friend, some projects rely on hermes for better performance and bundle size. Those should not disable hermes as it's suggest in this answer. – ofundefined Nov 30 '22 at 20:27
0

The right answer depends on your react-native version

This error means that your react-native project is set to use hermes a lightweight Javascript engine created by facebook specially for react-native. It is supposed to make the app faster and lighter.

If you want to use hermes, open your Podfile (ios/Podfile), look for hermes_enabled and set its value to true. The line should look like the following

:hermes_enabled => true

Besides that, you might needs to follow few more steps from the official page.

If your Podfile does not have any hermes_enabled property, please make sure your react-native project is using at least 0.60.

For react-native > 0.60 and < 0.70

For react-native >= 0.70

Hermes is the default engine for this version and beyond. Maybe you just need to reinstall your node packages, clean your Podfile.lock and reinstall your pods by running pod install from inside your ios folder.

ofundefined
  • 2,692
  • 2
  • 18
  • 35
0

just replace this code in Podfile the line that disable hermes,

:hermes_enabled => false, #flags[:hermes_enabled], 

then in ios directory run

pod install

and it's done.

AMINEDGE
  • 439
  • 3
  • 12