如何迁移到Xcode12.5
我无法使用 Xcode 12.5 构建使用 Xcode 11 正确构建的 React Native 项目。
我不能再使用 Xcode 11,因为只有更新的 Xcode 版本才带有必要的 API 来发布/上传到 TestFlight 和应用商店。
现在我收到三个构建错误:
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> *'
我还注意到部署目标从 10 和 9 自动升级:
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 12.1;
添加了一些与 Clang 相关的新属性:
+ CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
如何配置项目以使用 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 二进制文件:节点:10.16.0 - /usr/local/bin/node 纱线:1.21.1 - ~/npm-global/bin/yarn npm:6.9.0 - /usr/local/ bin/npm Watchman:4.9.0 - /usr/local/bin/watchman SDK:iOS SDK:平台:iOS 14.5、DriverKit 20.4、macOS 11.3、tvOS 14.5、watchOS 7.4 IDE: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
回答
我通过更改 React 模块 RCTCxxBridge.mm 中的参数来解决这个问题,如下所示:
- (NSArray<RCTModuleData *> *)_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules
withDispatchGroup:(dispatch_group_t)dispatchGroup
lazilyDiscovered:(BOOL)lazilyDiscovered
到:
- (NSArray<RCTModuleData *> *)_initializeModules:(NSArray<Class> *)modules
withDispatchGroup:(dispatch_group_t)dispatchGroup
lazilyDiscovered:(BOOL)lazilyDiscovered
我正在运行 0.59 并且没有使用 CocoaPods,但基本的修复是以下形式的转换:
NSArray<id<RCTBridgeModule>> *)modules
应替换为:
NSArray<Class> *)modules
- I had edited my above response to be I belive the fix, rather than saying I had the same issue with Xcode 12.5.
- @haleonj, please refer to this https://github.com/facebook/react-native/issues/28405#issuecomment-827424477. You have to change RCTBridgeModuleNameForClass(module)) to RCTBridgeModuleNameForClass(Class(module))) as well
- 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.
- After using this fix all the old errors are removed but one error manifests, `NSArray<id<RCTBridgeModule>>`, on line 300 of `RCTTurboModuleManager.mm`.
回答
这个对我有用。
- 打开RCTCxxBridge.mm(第 770 行)并将参数类型从:更改
(NSArray<id<RCTBridgeModule>> *)modules为(NSArray<Class> *)modules - 打开RCTTurboModuleManager.mm(第 300 行)并从:更改
RCTBridgeModuleNameForClass(module))为RCTBridgeModuleNameForClass(Class(module)));