2021-09-13

解决XCode 12.5版本 React-Native 适配出现的问题:

报错信息如下

cannot initialize a parameter of type 'NSArray> *' with an lvalue of type 'NSArray *__strong' NSArray *newModules = [self _initializeModules:modules withDispatchGroup:NULL lazilyDiscovered:YES];


在podfile中添加:


 post_installdo|installer|

    flipper_post_install(installer)

    ## Fix for XCode 12.5 编译错误

    find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",

       "_initializeModules:(NSArray> *)modules", "_initializeModules:(NSArray *)modules")

    find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",

         "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass([module class]))")

    find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",

              "RCTBridgeModuleNameForClass(strongModule))", "RCTBridgeModuleNameForClass([strongModule class]))")

  end


  ## Fix for XCode 12.5 编译错误

  deffind_and_replace(dir, findstr, replacestr)

    Dir[dir].eachdo|name|

        text = File.read(name)

        replace = text.gsub(findstr,replacestr)

        iftext != replace

            puts"Fix: "+ name

            File.open(name,"w") { |file| file.puts replace }

            STDOUT.flush

        end

    end

    Dir[dir +'*/'].each(&method(:find_and_replace))

  end


参考地址:https://github.com/facebook/react-native/issues/28405

你可能感兴趣的:(2021-09-13)