Javascript/本机代码不同步(参数数量不同)错误

Ada*_*ski 4 ios cocoapods react-native react-native-navigation

我最近从 1.24 更新到了ReactNativeControllers 2.03。我还把 RN 更新到了 0.25。我使用的fork只添加了 Podspec 文件。在整理完 RN 中的所有导入更改后,我现在对这个错误感到困惑:

(另请参阅https://github.com/wix/react-native-controllers/issues/59

RCCManager.setRootController 被调用时使用了 3 个参数,但期望有 2 个参数。如果您自己没有更改此方法,这通常意味着您的本机代码和 JavaScript 代码的版本不同步。更新两者应该可以消除此错误。

有问题的代码:

RCCManagerModule.m

setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
Run Code Online (Sandbox Code Playgroud)

并在index.js

ControllerRegistry: {
    registerController: function (appKey, getControllerFunc) {
      _controllerRegistry[appKey] = getControllerFunc();
    },
    setRootController: function (appKey, animationType = 'none', passProps = {}) {
      var controller = _controllerRegistry[appKey];
      if (controller === undefined) return;
      var layout = controller.render();
      _validateDrawerProps(layout);
      RCCManager.setRootController(layout, animationType, passProps);
    }
  },
Run Code Online (Sandbox Code Playgroud)

很明显,两者都有 3 个参数。

我已经杀死并重新启动了打包程序。我已经清理了 Xcode 项目,包括派生数据,并使用watchman watch-del-all. 我已经删除了我的node_modules文件夹,完成npm installpod install.

我已经重建了 Xcode 项目。还是没有运气。我不知道如何进一步调试。

编辑:我还尝试清理 pod 缓存,更新到 Cocoapods 1.01...

我有一种感觉,这里的某个地方可能存在转移注意力的情况。作为参考,我的完整跟踪如下所示:

2016-06-10 14:15:18.179 [warn][tid:com.facebook.React.JavaScript] Warning: ReactNative.Component is deprecated. Use React.Component from the "react" package instead.
2016-06-10 14:15:18.239 JustTuner[7523:185768] Launching Couchbase Lite...
2016-06-10 14:15:19.048 JustTuner[7523:185768] Couchbase Lite url = http://adamwilsonsMBP.lan:5984/
2016-06-10 14:15:19.050 JustTuner[7523:185768] Launching Couchbase Lite...
2016-06-10 14:15:19.058 JustTuner[7523:185768] Couchbase Lite url = http://adamwilsonsMBP.lan:5984/
2016-06-10 14:15:19.538 [error][tid:main][RCTModuleMethod.m:456] RCCManager.setRootController was called with 3 arguments, but expects 2.                   If you haven't changed this method yourself, this usually means that                   your versions of the native code and JavaScript code are out of sync.                   Updating both should make this error go away.
Run Code Online (Sandbox Code Playgroud)

Ada*_*ski 5

在花了很多时间尝试解决这个问题之后,我libReactNativeControllers.a发现build/Products/Debug-iphonesimulator.

删除libReactNativeControllers.a并重建项目解决了这个问题。

看来 Pod 静态库现在保存在各自的文件夹中,例如build/Products/Debug-iphonesimulator/ReactNativeControllers/libReactNativeControllers.a

我的猜测是,最近的构建将静态库保存在子文件夹中,但链接器选择了过时的库。有人知道为什么这最近可能发生变化吗?

  • 有点题外话,但我希望有一个叫 XCode 的大稻草人,我们每年都可以聚在一起烧掉它。喝着酒,互相靠着肩膀哭泣。 (13认同)