skip to Main Content

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

6

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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)));
    Login or Signup to reply.
  3. 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
    
    Login or Signup to reply.
  4. 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
    
    Login or Signup to reply.
  5. Open your project in Xcode and go to File > Workspace settings > Build System > Legacy Build System

    Login or Signup to reply.
  6. I had the same problem with Xcode 13.1. But I resolved the problem with this method.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search