Skip to main content

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:

 

ePurchases] - 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!

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.

 

 


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.


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!


FYI, I am experiencing this exact same issue (though initializing for Android in my case, working in VS Code).

Upon Hot Restart (not reload), I get this console message every time:

I/[Purchases] - INFO(13168): Purchases instance already set. Did you mean to configure two Purchases objects?

On fresh compile/run of the app, this message does not appear.

It seems that the Purchases instance somehow survives restarting the app.


I have the same issue.

Here is the only place where i call configure().


In my code then i call this init method once above the Material App.


Reply