Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native / iOS SDK. No matching function for call to 'RCTBridgeModuleNameForClass' after update iOS SDK to 14.5

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

like image 852
Tomas Avatar asked Apr 27 '21 16:04

Tomas


5 Answers

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!

like image 193
Tiago Angelo Avatar answered Oct 25 '22 07:10

Tiago Angelo


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
like image 34
Michael Blanton Avatar answered Oct 25 '22 07:10

Michael Blanton


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.

like image 24
Tomas Avatar answered Oct 25 '22 06:10

Tomas


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
like image 12
parse Avatar answered Oct 25 '22 05:10

parse


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))).

like image 1
Sarabjeet Singh Avatar answered Oct 25 '22 07:10

Sarabjeet Singh