I had an initial functioning setup to get offerings and make a purchase. It worked : I could make a test purchase.
The code was in a ‘shop’ page, and I decided to move the RevenueCat initialisation to main.dart as initial entry point. But maybe this wrong because it screwed everything up, and the app crashed on loading (error below). So I put it back to what it was.
The app now loads and all screens function EXCEPT I am now getting the same error when I open the shop page. Even though it was working before.
*** Assertion failure in +[RCPurchases sharedPurchases](), RCPurchases.m:160
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There is no singleton instance. Make sure you configure Purchases before trying to get the default instance. More info here: https://errors.rev.cat/configuring-sdk'
*** First throw call stack:
(0x183586754 0x19804d7a8 0x1834883f8 0x1848afa6c 0x1009762f4 0x1009f2d34 0x100cb7bc0 0x100cb5b04 0x10109ea60 0x100dafd7c 0x1010b9070 0x1010531d4 0x1010559fc 0x18350122c 0x183500e28 0x183500278 0x1834fa02c 0x1834f9360 0x19ab37734 0x185f74584 0x185f79df4 0x100906e24 0x1831b5cf8)
libc++abi: terminating with uncaught exception of type NSException
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001b169d334 libsystem_kernel.dylib`__pthread_kill + 8
-> 0x1b169d334 <+8>: b.lo 0x1b169d354 ; <+40>
0x1b169d338 <+12>: pacibsp
0x1b169d33c <+16>: stp x29, x30, [sp, #-0x10]!
0x1b169d340 <+20>: mov x29, sp
Target 0: (Runner) stopped.
Lost connection to device.
Error says I should configure Purchases …. but I did !
static const revcatapiKey = 'xxxxxxxxxxxxxxxxxxxxxxxx';
appUserId: appUserId, observerMode: false);
I did `flutter clean` and `flutter pub get`. Same situation : app builds and loads and crashes on opening shop screen.
I don’t understand. App is now in same state as it was before when working.
Any debug or reset suggestions? Help!
Best answer by ryanView original
Well, I don’t know but I suspect the earlier crash somehow corrupted the appuserID.
So I set it specifically before calling Purchases.setup, and shop page now opens and retrieves data.
Worrying though if this happens in production through some app crash. Better make sure the testing regime covers everything !
OK, that was short lived.
Overnight the same error message has come back when starting the app on actual iPhone via cable.
Not aware of any relevant code changes since last working version.
Problem persists after `flutter clean` and `flutter pub get`
@Tim Considine 👋,
The error indicates that you have something trying to access
This could be a request to
.getPurchaserInfo()or something like that.
I’m not a Flutter dev myself, but maybe this sample app helps? https://github.com/RevenueCat/purchases-flutter/tree/main/revenuecat_examples/MagicWeather
I’m initialising it before I use the library in any way:
There is no error when calling Purchases.setup. I’ve also tried moving the initialisation code to main, before flutter even runs, and I still get the error:
Here is the error:
Any advise would be welcome
Just to add some more info here. It turns out that this error is being thrown before my app even gets a chance to call Purchases.setup(apiKey). I’ve added these log statements:
And here’s the full console output. As you can see, the error is thrown before you see “Initialising revenue cat”. This is happening despite the fact that I’m running this in main, *before the flutter app even starts*. So, something is trying to access the Purchases singleton instance, and it isn’t me - I’m assuming it’s the revenue cat package itself? I’m going to try and downgrade to the package version I was using earlier because it seems to me that there is something really broken here…
Okay, downgrading the purchases_flutter package to the version I was using previously has NOT resolved the problem. So now I’m totally stumped.
For others who may encounter this issue, I have worked around the problem by adding additional calls to Purchases.setup before any time I use any Purchases method.
I don’t know why this problem started happening even though I haven’t changed the parts of my code which use Purchases for over a year. It may be related to my upgrading my app to flutter 2 and dart null safety, but it may not.
I don’t know why my first call to Purchases.setup on app initialisation doesn’t seem to work anymore.
I don’t know why the ‘There is no singleton instance’ seems to be thrown before my app even starts, and what’s even more strange, I don’t know how adding additional calls to Purchases.setup AFTER my app starts seems to stop the error being thrown.
I have given up trying to understand this and just filing it under ‘weird, random and unexplained error’.
How is this marked as resolved?
I’ve the same problem as
I had a working app and now, after updating everything, I get this error right after running the app.
Did you find the problem and solution
@James Allen ? Or just this horrible workaround?
Would be great if the revenue cat team, who actually know the changes made, could point us somewhere. Right now, I’ll have to inspect the entire code and re-learn the plugin.
I have actually spent the last few weeks updating to flutter 3.7, which now natively supports using plugins in isolates, which means I can remove dependency on isolate_handler. Hopefully now I can remove this workaround.