关于React Native报Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>错误(解决方案)

2022-01-11,,,,

这篇文章主要介绍了关于React Native报Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>错误,本文给大家分享解决方案,需要的朋友可以参考下

最近,在运行一个老RN项目的时候,使用Xcode运行的时候报了如下的代码错误:

Cannot initialize a parameter of type 'NSArray<id> *'
                with an lvalue of type 'NSArray *__strong'
Cannot initialize a parameter of type 'NSArray *'
                with an lvalue of type 'NSArray<id> *__strong'
Cannot initialize a parameter of type 'NSArray<id> *'
                with an rvalue of type 'NSArray *'

这是由于升级XCode 12.5之后的问题,在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> *)modules", "_initializeModules:(NSArray *)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

然后,重新执行pod install 命令安装即可。

到此这篇关于关于React Native报Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>错误(解决方案)的文章就介绍到这了,更多相关React Native报错内容请搜索本站以前的文章或继续浏览下面的相关文章希望大家以后多多支持本站!

以上就是关于React Native报Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>错误(解决方案)的详细内容,更多请关注本站其它相关文章!

《关于React Native报Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>错误(解决方案).doc》

下载本文的Word格式文档,以方便收藏与打印。