31

I'm not able to build a React Native project, which built correctly using Xcode 11, using Xcode 12.5.

I can no longer use Xcode 11 because only more current versions of Xcode carry the necessary API to publish/upload to TestFlight and the app store.

Now I get three build errors:

Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type 'NSArray<Class> *'

Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type 'NSArray<Class> *'

Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type 'NSArray<Class> *'

I also noticed that deployment targets were automatically upgraded from 10 and 9:

- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.1;

Some new properties were added related to Clang:

+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;

How can I configure the project to deploy this app using Xcode 12.5?

$ react-native info info Fetching system and libraries information... System: OS: macOS 11.3 CPU: (4) x64 Intel(R) Core(TM) i3-8100B CPU @ 3.60GHz Memory: 256.45 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.16.0 - /usr/local/bin/node Yarn: 1.21.1 - ~/npm-global/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 IDEs: Xcode: 12.5/12E262 - /usr/bin/xcodebuild npmPackages: react: ^16.11.0 => 16.12.0 react-native: 0.61.4 => 0.61.4 npmGlobalPackages: react-native-cli: 2.0.1

1
  • At this point, it seems that the best answer is likely to upgrade React Native, but even then there are likely unfortunate consequences in that path. Upgrading RN means not having to use a solution of find and replace, but I have different build errors now.
    – haleonj
    Commented Jun 28, 2021 at 11:35

6 Answers 6

45

I fixed this by changing a parameter cast in the React module RCTCxxBridge.mm like so:

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

To:

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

I am running 0.59 and not using CocoaPods, but the basic fix is that casts of the form:

NSArray<id<RCTBridgeModule>> *)modules

Should be replaced with:

NSArray<Class> *)modules
5
  • 3
    I had edited my above response to be I belive the fix, rather than saying I had the same issue with Xcode 12.5. Commented Apr 28, 2021 at 1:43
  • 2
    After using this fix all the old errors are removed but one error manifests, NSArray<id<RCTBridgeModule>>, on line 300 of RCTTurboModuleManager.mm.
    – haleonj
    Commented Apr 28, 2021 at 14:01
  • 3
    @haleonj, please refer to this github.com/facebook/react-native/issues/…. You have to change RCTBridgeModuleNameForClass(module)) to RCTBridgeModuleNameForClass(Class(module))) as well
    – The1993
    Commented Apr 29, 2021 at 7:28
  • 3
    Can you add "You have to change RCTBridgeModuleNameForClass(module)) to RCTBridgeModuleNameForClass(Class(module))) as well" please? I want to mark the answer once it's complete.
    – haleonj
    Commented Apr 30, 2021 at 17:56
  • Worked for me as well running RN 60.6
    – isick
    Commented May 3, 2021 at 16:37
29

This one worked for me.

  1. Open RCTCxxBridge.mm (line 770) and change parameter type from: (NSArray<id<RCTBridgeModule>> *)modules to (NSArray<Class> *)modules
  2. Open RCTTurboModuleManager.mm (line 300) and change from: RCTBridgeModuleNameForClass(module)) to RCTBridgeModuleNameForClass(Class(module)));
0
13

This one worked for me. Update the PODFILE with:

post_install do |installer|
    ## Fix for XCode 12.5 beta
    find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
    "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
end

And at the end of podfile add a function:

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

The last step if to run:

pod install
1
  • This worked for me. I like this more than the other answers because it doesn't require directly modifying the .mm files, which could be overwritten the next time you run npm install. Related react-native issue report: github.com/facebook/react-native/issues/… Commented Jun 29, 2021 at 22:56
7

i've faced the same issue and after using this script the problem was solved for this three error but faced a new one (No matching function for call to 'RCTBridgeModuleNameForClass')

which was solved by adding this line in the postinstall script

Fix for XCode 12.5 beta

post_install do |installer|

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
1
  • 2
    This worked for me, just a comment about what I had to do in order to make it work: 1. There's a line break in the second find_and_replace which leads to the RCTTurboModuleManager.mm file not being updated properly. Using a one-liner fixes this: find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm", "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))") 2. The find_and_replace function needs to be defined at the end of the Podfile as well.
    – skizzo
    Commented Oct 12, 2021 at 9:42
1

Open your project in Xcode and go to File > Workspace settings > Build System > Legacy Build System

1
  • 1
    Did nothing for me.
    – stevehs17
    Commented Feb 21, 2022 at 22:15
0

I had the same problem with Xcode 13.1. But I resolved the problem with this method.

Not the answer you're looking for? Browse other questions tagged or ask your own question.