react-native-purchases: Calling Purchases.presentPaywall gives "method addObserver must be called on the main thread" on android

After adding react-native-date-picker to the project, we encountered a fatal crash when presenting the RevenueCat paywall on Android devices:

  1. Environment
    1. Platform: Android
    2. SDK version: 8.10.1
    3. OS version: 15
    4. React Native version: 0.76.9
    5. SDK installation (CocoaPods + version or manual): via Expo managed
    6. How widespread is the issue. Percentage of devices affected: 1 (showed up in testing)
  2. Debug logs that reproduce the issue:
          Fatal Exception: java.lang.IllegalStateException: Method addObserver must be called on the main thread
       at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.jvm.kt:302)
       at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.jvm.kt:180)
       at androidx.fragment.app.FragmentManager.setFragmentResultListener(FragmentManager.java:1006)
       at com.revenuecat.purchases.hybridcommon.ui.PaywallHelpersKt.presentPaywallFromFragment(PaywallHelpers.kt:40)
       at com.revenuecat.purchases.react.ui.RNPaywallsModule.presentPaywall(RNPaywallsModule.kt:92)
       at com.revenuecat.purchases.react.ui.RNPaywallsModule.presentPaywall(RNPaywallsModule.kt:45)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
       at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:146)
       at com.facebook.jni.NativeRunnable.run(NativeRunnable.java)
       at android.os.Handler.handleCallback(Handler.java:991)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
       at android.os.Looper.loopOnce(Looper.java:232)
       at android.os.Looper.loop(Looper.java:317)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass)
       at java.lang.Thread.run(Thread.java:1012)
  1. Steps to reproduce, with a description of expected vs. actual behavior
  • add react-native-date-picker
  • present paywall (specifically via an interaction event (e.g. tap a button))
  1. Other information same issue as #166 . Someone mentioned it could have something to do with the appcompat version being used.

The issue could be that RevenueCat’s paywall UI components are using Android lifecycle components that require a specific version of androidx.appcompat. When react-native-date-picker is added, it might be pulling in a different version of androidx.appcompat that conflicts with what RevenueCat expects.

Why It’s Not the Date Picker’s Fault

Date picker works fine - The crash only happens when presenting RevenueCat’s paywall Date picker doesn’t use lifecycle observers - The crash is about lifecycle observers, which RevenueCat uses for its paywall UI

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 19 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue here, I upgraded my app to 8.11.5 with this issue just on android On Expo 53 I downgraded to react-native-purchases@8.9.4 this version works for me

We are having the same issue since yesterday and it’s affecting all Android production users.

Hey all,

8.11.6 is released with the fix! This should not have happened and have been fixed sooner we will be working on processes to make sure things like this…

  1. For sure do not happen again
  2. Have a better way to escalate

Thanks again for everyone who reported this and are using paywalls 🫶

@thecaptainP are you also using a date picker package?

No, we are not.

It seems like bug in 8.11.5. Everything works well in 8.11.4.

No worries @joshdholtz ! Next time. At least we came up with the same solution.