react-native: use_framework! + hermes enable = Undefined symbols "vtable for facebook::react::HermesExecutorFactory"

Description

Hi guys,

I’m trying to use hermes with use_framework!.

  • I was on 0.66.4, with hermes disabled and use_framework enabled. My app was working great, but on some Android device i got a crash from JSC so we decided to enable hermes.
  • I tried to use both hermes and use_framework but it don’t work. After some research i understand i have to upgrade RN to 0.69.3.
  • After Upgrade i got an issue wich was fixed by this PR :https://github.com/facebook/react-native/commit/88b7b640a74bafd918b8b1cd5d58e1f5ddfb730
  • I patched react-native to integrate this PR

After the patch i got another issue:

Undefined symbols for architecture x86_64: “vtable for facebook::react::HermesExecutorFactory”, referenced from: facebook::react::HermesExecutorFactory::HermesExecutorFactory(std::__1::function<void (facebook::jsi::Runtime&)>, std::__1::function<void (std::__1::function<void ()> const&, std::__1::function<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > ()>)> const&, hermes::vm::RuntimeConfig) in RCTCxxBridge.o NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Someone know how i can fix this issue ? Cause for now, i can’t use hermes and use_framework together on all version of RN

Version

0.69.3

Output of npx react-native info

System: OS: macOS 12.0.1 CPU: (10) x64 Apple M1 Pro Memory: 135.61 MB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v14.17.0/bin/yarn npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm Watchman: 2022.05.16.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.10.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7935034 Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild Languages: Java: 11.0.11 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.3 => 0.69.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Snack, code example, screenshot, or link to a repository

image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 12
  • Comments: 43 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I think we must use frameworks like this

use_frameworks! :linkage => :static

In my case, I am using Firebase, and with react-native 0.70 and Firebase v9+ the docs advised to use this way.

still happens on 0.70

try https://github.com/Jichao/react-native/commit/f54159f774b57d7d2380ce51a9fa2e4a8c6ee039 add s.dependency "React-hermes", version to react-core.podspec

I also just tested with an empty project, only added use_frameworks! to Podfile and got the same error image

arch -x86_64 pod install and running Xcode with Rosetta results in the same error with x86_64 instead of arm64

I have this issue too in my Intel Mac. I have never been able to build for iOS with Hermes enabled. 0.70.0 did not change this.

Undefined symbols for architecture arm64:
  "vtable for facebook::react::HermesExecutorFactory", referenced from:
      facebook::react::HermesExecutorFactory::HermesExecutorFactory(std::__1::function<void (facebook::jsi::Runtime&)>, std::__1::function<void (std::__1::function<void ()> const&, std::__1::function<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > ()>)> const&, hermes::vm::RuntimeConfig) in RCTCxxBridge.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I think we must use frameworks like this

use_frameworks! :linkage => :static

In my case, I am using Firebase, and with react-native 0.70 and Firebase v9+ the docs advised to use this way.

This solved my issue use_frameworks! :linkage => :static

and commented out
:flipper_configuration => FlipperConfiguration.enabled,

I also have this problem (without an M1 and with architecture x86_64) Fabric is disabled Flipper is disabled (won’t work with use_framework anyway) Derived data and build folder are clean XCode 13.4.1

System:
    OS: macOS 12.5.1
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 1.64 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/Library/Caches/fnm_multishells/40339_1662544747645/bin/node
    Yarn: 1.22.18 - ~/Library/Caches/fnm_multishells/40339_1662544747645/bin/yarn
    npm: 8.5.5 - ~/Library/Caches/fnm_multishells/40339_1662544747645/bin/npm
    Watchman: 2022.02.28.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /Users/louislagrange/.rvm/gems/ruby-2.7.2/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK:
      API Levels: 28, 29, 30, 31, 32, 33
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0
      System Images: android-31 | Google Play Intel x86 Atom_64, android-33 | Google Play Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: Chipmunk 2021.2.1 Patch 2 Chipmunk 2021.2.1 Patch 2
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.0 => 0.70.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

1- use_frameworks! :linkage => :static (inside target ‘projectName’ do) 2- disabled :flipper_configuration => FlipperConfiguration.enabled 3- add s.dependency "React-hermes", version in side /node_modules/react-native/React-Core.podspec

works for me in Recat Native 0.70.6

Still having the same issue with use_frameworks! :linkage => :static and disabled flipper.

Here is my config, any advice ?

RN 0.70.4

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

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false
use_frameworks! :linkage => :static

$RNFirebaseAsStaticFramework = true

target 'Tellingtone' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()
  
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text', :modular_headers => true

  use_react_native!(
    :path => config[:reactNativePath],
    
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => true,
    :fabric_enabled => false,
    
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    #:flipper_configuration => FlipperConfiguration.enabled,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-async-storage/async-storage'
  pod 'RNFS', :path => '../node_modules/react-native-fs'

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

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

@avenable8 I have no idea, which ones to set static and which dynamic. I’ll just disable Hermes and wait until it and all dependencies are mature enough.

React-native: 0.72.0 @react-native-firebase/app: 18.1.0

I had the same issue. I cleaned my IOS build folder in Xcode (Product -> Clean Build folder)

Then I added the following line in multiple files;

s.dependency 'React-hermes', version node_modules/react-native/RNReanimated.podsec , node_modules/react-native/React.podspec, node_modules/react-native-reanimated/React-Core.podspec

I changed the following in the Podfile:

    :hermes_enabled => true,
    :fabric_enabled => false,
    # :flipper_configuration => flipper_config,
    use_frameworks! :linkage => :static

If you are upgrading your react native version this repo might help you. This maintainer has a repo with the release versions for a basic react native application, the branches shows the release version: https://github.com/react-native-community/rn-diff-purge/tree/release/0.72.0 Or if you would like to compare the changes you can use this website; https://react-native-community.github.io/upgrade-helper/

Hope it helped someone 😃

@Mrezagolbaba This makes the build progress, but still fails with ld: 98 duplicate symbols for architecture arm64. I installed the default RN repo, ran it successfully, went for a walk, and by the time I came back the project no longer built with the issues above.

I have the same problem:

818 duplicate symbols for architecture arm64 on my project.

I’m not sure how to fix it, but I’ve been running around in circles for a few days now 😕

I’ve put the line use_frameworks in my podfile! :linkage => :static and I activated hermes

Thank you !

For those who can’t use use_frameworks! :linkage => :static, you can manually convert only react-specific libraries by doing:

use_frameworks!

$static_framework = [ 'YogaKit', 'RCT-Folly', 'RCTTypeSafety', 'ReactCommon']
  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  
    installer.pod_targets.each do |pod|
      if pod.name.start_with?('React-') || $static_framework.include?(pod.name)
        def pod.build_type;
          # Uncomment the line corresponding to your CocoaPods version
          # Pod::BuildType.static_library # >= 1.9
          # Pod::Target::BuildType.static_library # < 1.9
        end
      end
    end
  end

You can also add other frameworks/libraries to the $static_framework list to convert it as well. Tested on RN 0.70.6.

I think we must use frameworks like this

use_frameworks! :linkage => :static

In my case, I am using Firebase, and with react-native 0.70 and Firebase v9+ the docs advised to use this way.

This one worked for me

s.dependency "React-hermes", version to react-core.podspec

Thanks a lot! It works for me with RN 0.70.5 with Hermes Enabled without static linkage for use_frameworks!. Any Idea when it will going to merge in RN update?

Still having the same issue with use_frameworks! :linkage => :static and disabled flipper.

Here is my config, any advice ?

RN 0.70.4

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

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false
use_frameworks! :linkage => :static

$RNFirebaseAsStaticFramework = true

target 'Tellingtone' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()
  
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text', :modular_headers => true

  use_react_native!(
    :path => config[:reactNativePath],
    
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => true,
    :fabric_enabled => false,
    
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    #:flipper_configuration => FlipperConfiguration.enabled,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-async-storage/async-storage'
  pod 'RNFS', :path => '../node_modules/react-native-fs'

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

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

@GrimDev Try to set “use_frameworks! :linkage => :static” inside the target like this:

target 'Tellingtone' do
    use_frameworks! :linkage => :static    <--- HERE
    config = use_native_modules!
    .....