RCTBridge委派中的“NSInternalInconsistencyException”失败 - React Native

时间:2017-06-06 01:32:50

标签: ios xcode react-native

描述

我已经使用XCode 8成功构建了一个react-native项目,但是在构建之后应用程序崩溃并出现以下错误消息。我一直在尝试一切,但无济于事,似乎没有类似的问题。我想从试图调试这个问题出发,问题在于RCTBridge.m:

- (Class)bridgeClass
{
  // In order to facilitate switching between bridges with only build
  // file changes, this uses reflection to check which bridges are
  // available.  This is a short-term hack until RCTBatchedBridge is
  // removed.

  Class batchedBridgeClass = objc_lookUpClass("RCTBatchedBridge");
  Class cxxBridgeClass = objc_lookUpClass("RCTCxxBridge");

  Class implClass = nil;

  if ([self.delegate respondsToSelector:@selector(shouldBridgeUseCxxBridge:)]) {
    if ([self.delegate shouldBridgeUseCxxBridge:self]) {
      implClass = cxxBridgeClass;
    } else {
      implClass = batchedBridgeClass;
    }
  } else if (batchedBridgeClass != nil) {
    implClass = batchedBridgeClass;
  } else if (cxxBridgeClass != nil) {
    implClass = cxxBridgeClass;
  }

  RCTAssert(implClass != nil, @"No bridge implementation is available, giving up.");
  return implClass;
}

其中bridgeClass返回断言错误,因为RCTBatchedBridge类和RCTCxxBridge之间的选择都没有返回,如下面RCTBridgeDelegate.h中的注释中所解释的

/**
 * Configure whether the legacy RCTBatchedBridge or new RCTCxxBridge
 * should be used.  If this method is implemented and the specified
 * bridge is not linked in, startup will fail.  If this method is not
 * implemented, the implementation will default to RCTBatchedBridge,
 * but if it is not linked in, will try RCTCxxBridge instead.  If
 * neither bridge is linked in, startup will fail.  This order will be
 * reversed in the near future, as the legacy bridge is closer to
 * being removed.
 *
 * @experimental
 */
- (BOOL)shouldBridgeUseCxxBridge:(RCTBridge *)bridge;

复制步骤和示例代码

所有涉及的RN模块已经与npm和CocoaPods安装,链接等。没有先前的构建错误,并且构建处于调试模式。我也一直在使用Ignite样板,但是从日志开始它还没有使用特定应用代码。

成功构建后的错误:

2017-06-06 08:48:57.019 rn_irnext_demo[16376:122081] *** Assertion failure in -[RCTBridge bridgeClass](), myApp/node_modules/react-native/React/Base/RCTBridge.m:292
2017-06-06 08:48:57.031 rn_irnext_demo[16376:122081] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No bridge implementation is available, giving up.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000113344b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000112da9141 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000113348cf2 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000011297869f -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 165
    4   rn_irnext_demo                      0x000000010e578e27 -[RCTBridge bridgeClass] + 535
    5   rn_irnext_demo                      0x000000010e578f7d -[RCTBridge setUp] + 285
    6   rn_irnext_demo                      0x000000010e578387 -[RCTBridge initWithDelegate:bundleURL:moduleProvider:launchOptions:] + 375
    7   rn_irnext_demo                      0x000000010e5781a2 -[RCTBridge initWithBundleURL:moduleProvider:launchOptions:] + 146
    8   rn_irnext_demo                      0x000000010e54fee7 -[RCTRootView initWithBundleURL:moduleName:initialProperties:launchOptions:] + 183
    9   rn_irnext_demo                      0x000000010e540c58 -[AppDelegate application:didFinishLaunchingWithOptions:] + 280
    10  UIKit                               0x0000000111008957 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299
    11  UIKit                               0x000000011100a23c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4119
    12  UIKit                               0x0000000111010584 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
    13  UIKit                               0x000000011100d793 -[UIApplication workspaceDidEndTransaction:] + 182
    14  FrontBoardServices                  0x000000011a3775f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    15  FrontBoardServices                  0x000000011a37746d -[FBSSerialQueue _performNext] + 186
    16  FrontBoardServices                  0x000000011a3777f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    17  CoreFoundation                      0x00000001132eac01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    18  CoreFoundation                      0x00000001132d00cf __CFRunLoopDoSources0 + 527
    19  CoreFoundation                      0x00000001132cf5ff __CFRunLoopRun + 911
    20  CoreFoundation                      0x00000001132cf016 CFRunLoopRunSpecific + 406
    21  UIKit                               0x000000011100c02f -[UIApplication _run] + 468
    22  UIKit                               0x00000001110120d4 UIApplicationMain + 159
    23  rn_irnext_demo                      0x000000010e54103f main + 111
    24  libdyld.dylib                       0x00000001139cb65d start + 1
    25  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

另外产生Thread 1:signal SIGABRT error in the main.m file.

其他信息:

1)XCode 8 2)反应原生:0.44 3)macOSx

需要帮助解决这个问题。提前感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

我终于设法解决了这个问题,并且正在为那些可能遇到这个问题的人发布这个答案。

错误是由于一个单独的修复,具有后见之明,是一个临时修复:

Duplicate symbols for architecture x86_64 under Xcode

删除-ObjC from Other Linker Flags将导致上述问题,因为使用本机类完成的任何链接都将无效并导致应用程序崩溃。所以我做的是以下内容:

1)查找包含重复符号的文件,并删除对重复文件的任何引用,同时保留项目的Libraries文件夹中的文件。

2)为主项目目标重新插入-ObjC in the Other Linker Flags,应用程序将停止崩溃。

希望这会有所帮助。