Question

"Purchases instance already set. Did you mean to configure two Purchases objects?" even though nothing was initialized yet

  • 15 July 2022
  • 3 replies
  • 44 views

Badge +3

Hey everybody,

I started to implement RevenueCat today into our existing Flutter app and so far I’m really enjoying is. The only thing I’m wondering right now is, is the following debug message that shows up all the time:

 

[Purchases] - INFO: ℹ️ Purchases instance already set. Did you mean to configure two Purchases objects?

 

What I’m doing so far in my code is to initialize the Purchases like that:

 

  Future<void> initSubscriptions() async {
await Purchases.setDebugLogsEnabled(true);
if (Platform.isAndroid) {
// TODO Setup Google
// await Purchases.setup("public_google_sdk_key");
} else if (Platform.isIOS) {
final bool revenueCatAlreadyConfigured = await Purchases.isConfigured;
if (!revenueCatAlreadyConfigured) {
await Purchases.setup("<my_api_key>",
appUserId: "SIMULATOR-TEST-CLIENT");
print("iOS setup finished");
} else {
print("RevenueCat is already configured");
}
} else {
print("Platform doesn't support subscriptions yet");
}
}

 

This method is called as one of the very first ones in my app.

Initially I didn’t use the “revenueCatAlreadyConfigured” variable and just triggered the setup, as it’s only used once in the init method and I don’t call it anywhere else. After seeing the debug message I introduced the “revenueCatAlreadyConfigured” bool to work around it but in that case RevenueCat is not configured at all and doesn’t return anything.

The debug message is not popping up whenever I build the app from scratch, so I’m not sure if thats a bug with the hot reload, but it confused me, so I wanted to double check. I found some posts about it and that it could lead to several side effects, so it would be good to know the best practice here.

 

Thanks in advance!


3 replies

Badge

Hi Patrick, 

 

Thanks for reaching out, I’ve been trying to identify the issue but I see nothing in the code you shared that could be causing the duplicate configuration attempt which raises a question on my side. When in the lifecycle of the application the initSubscriptions method is being called? 

From your message I understand that a fresh run doesn't cause it but subsequent one does, so I can only suspect that the initSubscriptions method is being called again at some point.

 

 

Badge +3

Hey Roberto,


thanks for your answer!

And exactly, when doing a fresh app build the message is not logged. Only when using the Flutter “Restart” (not Hot Reload, as initially mentioned).

So when I do this here, the warning is logged:

 

I only call this function once within the main method of the Flutter app, that’s it. So during restart it is retriggered, but I would have expected that the Purchases object also looses its configuration on a Flutter Restart.

As I mentioned, it is also very likely that it won’t affect the end users but during development it raised some concerns for me, that’s why I wanted to double check that.

Badge

Hi Patrick,

 

I’m glad its sorted out, maybe you can push the initiation call earlier when defining the application context so it doesn’t get called again during restarts. Its good to have the check you have so you don’t duplicate the setup of the Purchases object but the best option will be to have it setup earlier in the app lifecycle.

 

Happy Shipping and have a great week!

Reply