Skip to main content
Question

Purchases.sharedInstance is null right after calling Purchases.configure

  • May 16, 2025
  • 1 reply
  • 16 views

Forum|alt.badge.img

I am getting logs that occasionally with some users Purchases.sharedInstance throws UninitializedPropertyAccessException even though Purchases.configure was called literally on the line before.

 

Our app is only available via Google Play Store, so there shouldn't be any issues connected with prerequisites not being met on that front.

 

Is Purchases.configure asynchronous in some sense? I skimmed through the code and I saw no indication that the configuration (and initialization of sharedInstance) should fail in any sense.

 

One thing I should also note is that I access Purchases.sharedInstance via DI using Hilt. It occurred to me that maybe there somehow exist two instances of Purchases (one configured, and one not), but I think if that was the case, this problem would be ubiquitous, and not impacting just some of the users some of the time.

 

I am using SDK v8.17.1

This post has been closed for comments

1 reply

guilherme
RevenueCat Staff
Forum|alt.badge.img+3
  • RevenueCat Staff
  • 49 replies
  • May 20, 2025

Hey ​@adam-bílek-d5de9a 

Thanks for those details, they are quite helpful in trying to understand what can be happening.

As to your questions and what could possibly be happening:

  • Purchases.configure() is synchronous on Android and is intended to immediately initialize Purchases.sharedInstance. However, what you're encountering can happen when sharedInstance is accessed before configure() has run, or if there's a race introduced by dependency injection or lifecycle timing.

Even if you're calling configure() "right before" in code, a few edge cases can cause this:

  • race condition from DI: if a class accessing sharedInstance is constructed before or concurrently with configure(), you may see this intermittently.

  • multiple Purchases initializations: accidental double calling configure or parallel instantiations can cause undefined state.

In order to validate the above, could you sanity check a few things please:

  1. Call Purchases.configure() in Application.onCreate(). This ensures it’s the very first thing initialized, avoiding lifecycle or DI conflicts;

  2. Avoid injecting Purchases.sharedInstance (for now!) via DI. Instead, access it after configure() has run or consider wrapping access in a helper that verifies it's been configured. As a temporary check on if this changes the behaviour;

  3. Enable debug logging (via this guide). By setting Purchases.debugLogsEnabled = true early in app startup to get more insight into when configure() is called and whether multiple initializations occur;

  4. Guard usage with Purchases.isConfigured. As of recent SDK versions, you can use Purchases.isConfigured to confirm whether sharedInstance is safe to access. This might help you isolate problem flows.

Let me know what you find, happy to dig deeper if the issue persists!

Best,

Gui


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings