Zharif
Zharif

Reputation: 61

'NSInternalInconsistencyException' failure in RCTBridge delegation - React Native

Description

I've successfully build a react-native project using XCode 8 but the app crashes after the build with the following error message. I've been trying everything but to no avail, and seems there are no similar issues out there. The issue, i think from trying to debug this, lies in 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;
}

where the bridgeClass returns the assertion error due to the selection between the RCTBatchedBridge class and the RCTCxxBridge returning neither as explained in the comments below found in 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;

Reproduction Steps and Sample Code

All the RN modules involved have been installed, linked etc with npm and CocoaPods. There are no prior build errors and the build is in debug mode. I've also been using the Ignite boilerplate but from the logs it hasn't yet gone to app specific codes.

The error after successful build:

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

Additionally produces a Thread 1:signal SIGABRT error in the main.m file.

Additional info:

1) XCode 8 2) react-native: 0.44 3) macOSx

Need assistance in solving this. Thank you in advance for your help!

Upvotes: 2

Views: 2122

Answers (1)

Zharif
Zharif

Reputation: 61

I've finally manage to solve this issue and am posting this answer for those who might come across this issue as well.

The error is due to a separate fix, which having hindsight, is a temporary one:

Duplicate symbols for architecture x86_64 under Xcode

Removing the -ObjC from Other Linker Flags will cause the issue above as any linking done with native classes will not work and causes the App to crash. So what I did instead was the following:

1) Find the files which contain the duplicate symbols and removing any references to the duplicate files while maintaining the ones in the Libraries folder of the project.

2) Reinserting -ObjC in the Other Linker Flags for the main project target and the App will stop crashing.

Hope this helps.

Upvotes: 4

Related Questions