Flutter iOS RevenueCat uncaught exception 'NSInternalInconsistencyException'

I got this error in console:

[Purchases] - INFO: There is no singleton instance. Make sure you configure Purchases before trying to get the default instance.
*** Assertion failure in +[RCCommonFunctionality getPurchaserInfoWithCompletionBlock:], RCCommonFunctionality.m:118
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You must call setup first.'
*** First throw call stack:
(0x1a0379654 0x1a009bbcc 0x1a027c6ec 0x1a06c216c 0x1032908ac 0x1032cdf9c 0x1032cc0d4 0x105c3ae30 0x1053ef758 0x1056d58b4 0x1053f90ec 0x1053fb818 0x1a02f8134 0x1a02f7e50 0x1a02f752c 0x1a02f253c 0x1a02f1ba8 0x1aa461344 0x1a442d3e4 0x102c4069c 0x1a01798f0)
libc++abi.dylib: terminating with uncaught exception of type NSException
* thread #1, queue = '', stop reason = signal SIGABRT
    frame #0: 0x00000001a016ed88 libsystem_kernel.dylib`__pthread_kill + 8
->  0x1a016ed88 <+8>:  b.lo   0x1a016eda4               ; <+36>
    0x1a016ed8c <+12>: stp    x29, x30, [sp, #-0x10]!
    0x1a016ed90 <+16>: mov    x29, sp
    0x1a016ed94 <+20>: bl     0x1a014dad0               ; cerror_nocancel
Target 0: (Runner) stopped.
Lost connection to device.

However, this is an intermittent problem (i.e: doesn't always happen). In fact, I have setup the Purchases instance at startup (i.e: immediately after user is authenticated and I got the UID):

 await Purchases.setDebugLogsEnabled(isDebugEnabled);
 await Purchases.setup(kRevenueCatApiKey, appUserId: uid);

Is there anything I missed? (but most of the time it works)


  • I found the problem. So whenever getPurchaserInfo is called, but if Purchaser.setup hasn't finish processing, then it will fire this exception. Thanks to the comment by @Cesar above.

    In my case, I found the problem was because:

    • I had two Blocs that handles IAP and Business logic respectively.
    • The IAP calls Purchases.setup as soon as the user is authenticated. Then at the main screen, the Business logic will check validity of local data with server by doing getPurchaserInfo.
    • The problem comes when the internet connection is not great and getPurchaserInfo gets fired by Business logic bloc before Purchases.setup finish processing.

    So the solution I did was by making sure that Business logic bloc starts initializing once IAP bloc done with Purchases.setup. Such as placing them in an async function that awaits for each process.