react-native-purchases: Calling Purchases.presentPaywall gives "method addObserver must be called on the main thread" on android
- I have updated Purchases SDK to the latest version (folks report seeing this on 8.11.5)
- I have read the Contribution Guidelines
- I have searched the Community
- I have read docs.revenuecat.com
- I have searched for existing Github issues
After adding react-native-date-picker to the project, we encountered a fatal crash when presenting the RevenueCat paywall on Android devices:
- Environment
- Platform: Android
- SDK version: 8.10.1
- OS version: 15
- React Native version: 0.76.9
- SDK installation (CocoaPods + version or manual): via Expo managed
- How widespread is the issue. Percentage of devices affected: 1 (showed up in testing)
- 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)
- 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))
- 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)
Same issue here, I upgraded my app to
8.11.5with this issue just on android On Expo 53 I downgraded toreact-native-purchases@8.9.4this version works for meWe 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…
Thanks again for everyone who reported this and are using paywalls 🫶
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.