I recently integrated RevenueCat into my Android (Java) app and I’m facing both:
-
Crash:
UninitializedPropertyAccessException– singleton not initialized -
ANR: Slow operations on the main thread during
Purchases.configure()
RevenueCat Initialization
I initialize RevenueCat in my Application class:
@Override public void onCreate() { super.onCreate(); Purchases.setLogLevel(LogLevel.DEBUG); Purchases.configure( new PurchasesConfiguration.Builder( getApplicationContext(), "goog_PtfrQdxywvuyHZAeNNLzJalKKIt" ).build() ); }
Usage in Premium Screen
In my PremiumScreen Activity onCreate():
Purchases.getSharedInstance().getOfferings(new ReceiveOfferingsCallback() { @Override public void onReceived(@NonNull Offerings offerings) { // Handle offerings } @Override public void onError(@NonNull PurchasesError error) { // Handle error } });
Crash Details
kotlin.UninitializedPropertyAccessException: 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 Caused by: com.revenuecat.purchases.Purchases$Companion.getSharedInstance com.revenuecat.purchases.Purchases.getSharedInstance com.faceswap.ai.art.avatar.generator.activities.PremiumScreenCat.onCreate
This happens even though Purchases.configure() is called in Application.onCreate() and navigation to the Premium screen only happens after initialization.
ANR Details (Main Thread Blocked)
Initial ANR stack trace:
ANR triggered by slow operations in main thread com.revenuecat.purchases.PurchasesFactory.createPurchases com.revenuecat.purchases.Purchases.configure com.faceswap.ai.art.avatar.generator.AppopenAD.MyAppOpen.onCreate
Attempted Fix
I tried moving the initialization logic out of onCreate() and running it after app startup (background flow), but I still get ANRs.
Updated ANR stack trace:
ANR triggered by slow operations in main thread com.revenuecat.purchases.subscriberattributes.caching.SubscriberAttributesCache.cleanUpSubscriberAttributeCache com.revenuecat.purchases.identity.IdentityManager.configure com.revenuecat.purchases.PurchasesOrchestrator.<init> com.revenuecat.purchases.PurchasesFactory.createPurchases com.revenuecat.purchases.Purchases.configure com.faceswap.ai.art.avatar.generator.AppopenAD.MyAppOpen.initAfterStartup
Key Points
-
App is Java-based
-
RevenueCat SDK is initialized once
-
Premium screen is opened after initialization
-
Still seeing:
-
getSharedInstance()crash -
ANR caused by
Purchases.configure()and subscriber attributes cleanup
-
-
Moving initialization off
onCreate()did not resolve ANR
Questions
-
Is
Purchases.configure()expected to perform heavy operations on the main thread? -
Is there a recommended best practice to avoid ANR during SDK initialization?
-
Can
getSharedInstance()be called safely if initialization is still in progress? -
Should initialization be done in a specific lifecycle point or with a specific threading model?
Any guidance or best practices would be greatly appreciated.
