41

I have updated the iOS SDK platform to version 14.5. The Xcode version is now 12.5. After updating, I cannot launch the application on my device. And the compiler throws an error:

No matching function for call to 'RCTBridgeModuleNameForClass'

I tried reinstalling the pods but it didn't help. How can fix it? Thanks

enter image description here

AnderCover
  • 2,488
  • 3
  • 23
  • 42
Tomas
  • 1,567
  • 3
  • 21
  • 38

5 Answers5

72

Put this code at the bottom of your ios/Podfile

post_install do |installer|
  ## Fix for XCode 12.5
      find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
      "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
      find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
      "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))")
  end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

save it, do a pod install on terminal and try to run/build your project again!

Tiago Angelo
  • 827
  • 1
  • 5
  • 4
28

I put together all the proposed solutions and got a working version.

Podfile

post_install do |installer|
    ## Fix for XCode 12.5
    find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm", "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
    find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm", "RCTBridgeModuleNameForClass(strongModule))", "RCTBridgeModuleNameForClass(Class(strongModule)))")
  end
def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

After that I got a new error which is related to Flipper:

Flipper-Folly/folly/synchronization/DistributedMutex-inl.h:1051:5: 'atomic_notify_one<unsigned long>' is unavailable

I used the solution from Xcode throws 'atomic_notify_one' is unavailable to fix this problem.

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

And commented out the line # flipper_post_install(installer) inside post_install do |installer|

Last, re-install your pods, rebuil and run your project.

Alan
  • 2,888
  • 7
  • 34
  • 36
Tomas
  • 1,567
  • 3
  • 21
  • 38
  • It might be worth noting that you'll also need to comment out any Flipper object initializations in the AppDelegate file as well. – DBrown May 27 '21 at 19:44
  • Looks like you are missing the "-" in react-native on the first find_and_replace call for the RCTCxxBridge.mm file. – spd Jun 02 '21 at 20:26
  • This fixed my issue as well. But can you share us what is the issue? Why it occurred? And what the proposed solution has managed to fix? – Shoeb Mirza Jul 06 '21 at 11:57
  • If you're still experiencing issues (I did with Xcode 13) then the first comment on this answer which explains putting both fix_and_replace onto a single line worked for me. https://stackoverflow.com/a/68245484/2061520 – HungryArthur Oct 22 '21 at 08:25
  • That solved my issue. I had to disable Flipper completely to make it work! – DaniloJs Sep 05 '22 at 21:46
27

My post_install function had to be slightly different (using strongModule instead of module in the second replace):

  post_install do |installer|
    ## Fix for XCode 12.5
    find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
    "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
    find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
    "RCTBridgeModuleNameForClass(strongModule))", "RCTBridgeModuleNameForClass(Class(strongModule)))")
  end
Michael Blanton
  • 341
  • 2
  • 3
  • 1
    I am still unable to build after making those changes and getting this error : ```Flipper-Folly/folly/synchronization/DistributedMutex-inl.h:1051:5: 'atomic_notify_one' is unavailable``` – Anuneet Anand Apr 28 '21 at 07:40
  • @AnuneetAnand i have the same error. I used the solution from https://stackoverflow.com/a/67286470/4512868 – Tomas Apr 28 '21 at 10:12
  • That's a different issue, and need to disable flipper in the Podfile as well. See: https://stackoverflow.com/questions/66189325/xcode-throws-atomic-notify-oneunsigned-long-is-unavailable – DBrown May 27 '21 at 19:43
  • Thanks, it works perfectly for `Xcode 12.5.1` with `React Native 0.62.2` on my side, while I do the file changes in `patch-package` instead of post_install function. – Wing Choy Jul 18 '21 at 16:03
  • You are great! It helped. thanks – sanjeev shetty Nov 14 '21 at 14:25
15

After updating to Xcode 13.1, I started getting that issue! However, the famous fix that's shared everywhere (RN GitHub issues and here on StackOverflow) didn't work for me but needed a little change!

RCTBridgeModuleNameForClass(module)) should change to RCTBridgeModuleNameForClass(strongModule))

and RCTBridgeModuleNameForClass(Class(module))) to RCTBridgeModuleNameForClass(Class(strongModule)))

As you can see, the given variable name was changed at least in the React Native version I have.

The final code should be looking like this:

post_install do |installer|
     # Fix after updating to Xcode 13.1
     find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
    "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
    find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
    "RCTBridgeModuleNameForClass(strongModule))", "RCTBridgeModuleNameForClass(Class(strongModule)))")
end

def find_and_replace(dir, findstr, replacestr)
    Dir[dir].each do |name|
        text = File.read(name)
        replace = text.gsub(findstr,replacestr)
        if text != replace
            puts "Fix: " + name
            File.open(name, "w") { |file| file.puts replace }
            STDOUT.flush
        end
    end
    Dir[dir + '*/'].each(&method(:find_and_replace))
  end
parse
  • 1,706
  • 17
  • 27
4

This works for me.

Step 1: Open RCTCxxBridge.mm search this code:

- (NSArray<RCTModuleData *> *)_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules
                               withDispatchGroup:(dispatch_group_t)dispatchGroup
                                lazilyDiscovered:(BOOL)lazilyDiscovered

And change in to this

- (NSArray<RCTModuleData *> *)_initializeModules:(NSArray<Class> *)modules
                               withDispatchGroup:(dispatch_group_t)dispatchGroup
                                lazilyDiscovered:(BOOL)lazilyDiscovered

Step 2: Open RCTTurboModuleManager.mm (line 300) and change RCTBridgeModuleNameForClass(module)) to RCTBridgeModuleNameForClass(Class(module))).

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Thanks, this was the one part that I was missing! Xcode now builds properly for me as well – B L Sep 14 '22 at 20:18
  • For me, these files were located at: `./node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm` and `./node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm` – BU0 Jun 02 '23 at 18:26