编译一个远古RN项目的时候抛出了如下异常
Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type 'NSArray<Class> *'
RN 配置
"dependencies": {
"@react-native-community/async-storage": "^1.8.1",
"@react-native-community/masked-view": "^0.1.7",
"@react-native-community/viewpager": "^4.0.0",
"@react-navigation/bottom-tabs": "^5.1.1",
"@react-navigation/drawer": "^5.1.1",
"@react-navigation/native": "^5.0.9",
"@react-navigation/stack": "^5.1.1",
"@types/react-dom": "^16.9.6",
"@yz1311/react-native-signature-pad": "^0.1.5",
"decimal.js": "^10.3.1",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-actionsheet": "^2.4.2",
"react-native-easy-grid": "^0.2.2",
"react-native-easy-table": "^1.0.2",
"react-native-elements": "^1.2.7",
"react-native-fit-image": "^1.5.5",
"react-native-gesture-handler": "^1.6.0",
"react-native-image-picker": "^2.3.3",
"react-native-keyboard-manager": "^4.0.13-16",
"react-native-photo-browser": "^0.6.0",
"react-native-render-html": "^4.2.3",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.2.0",
"react-native-scrollable-tab-view": "^1.0.0",
"react-native-table-component": "^1.2.1",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^8.1.2",
"rn-fetch-blob": "^0.12.0",
"rxjs": "latest",
"rxjs-hooks": "^0.6.2",
"teaset": "^0.7.4"
},
解决办法
在 iOS 项目的 Podfile 中添加如下 code 后重新尝试 pod install
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
以上便是此次分享的全部内容,希望能对大家有所帮助!
网友评论