RevenueCat / react-native-purchases

React Native in-app purchases and subscriptions made easy. Support for iOS and Android.
https://www.revenuecat.com
MIT License
745 stars 80 forks source link

[Android 14] Crash Exception - RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED is required #670

Closed MateoParodi closed 1 year ago

MateoParodi commented 1 year ago

Hello everyone!

Since last week, we updated our android sdk to 34, to support Android 14, and we are getting some crashes on firebase:

Fatal Exception: java.lang.SecurityException: com.my-test-app.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5668) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at com.android.billingclient.api.zzh.zzc(com.android.billingclient:billing@@4.1.0:1) at com.android.billingclient.api.zzi.zze(com.android.billingclient:billing@@4.1.0:1) at com.android.billingclient.api.BillingClientImpl.startConnection(com.android.billingclient:billing@@4.1.0:36) at com.revenuecat.purchases.google.BillingWrapper.startConnection(BillingWrapper.kt:120) at com.revenuecat.purchases.google.BillingWrapper.startConnectionOnMainThread$lambda-3(BillingWrapper.kt:106) at com.revenuecat.purchases.google.BillingWrapper.$r8$lambda$hLiSTu2HCHKyRrb-HVFlJFdt_lQ() at com.revenuecat.purchases.google.BillingWrapper$$ExternalSyntheticLambda9.run(:2) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8176) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

Any ideas on what could be happening? (usefull link maybe)

RCGitBot commented 1 year ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

tonidero commented 1 year ago

Hi @MateoParodi, thanks for reaching out!

Yes, we're able to reproduce this issue, this is a known issue in the billing library from Google: https://github.com/android/play-billing-samples/issues/618.

As it says in that issue, Google released an update last week that fixes the issue. We are going to update our libraries to include that fix, so expect a new release very soon. We will update this issue once the SDK has been updated to that billing library version.

tonidero commented 1 year ago

Hi @MateoParodi, we just released new versions of our SDKs including the fix in Google's billing library. Can you try version 6.2.1 of our react native SDK and let us know the results?

MateoParodi commented 1 year ago

Nice! Thanks for the catch up!

We are currently using "react-native-purchases": "^5.13.2" so, if I bump to v6 Im forced to do the migration to the New Google subscription model? or is not mandatory and I can still use the old subscription model?

tonidero commented 1 year ago

Hi @MateoParodi,

Unfortunately, we can't release a v5 patch release with this change, since Google only released the fix with billing client 5 and 6, but not with 4, which is what RN v5 is pointing to.

v6 of the RN SDK does introduce support for the new Google subscription model. This means that you will start seeing non-backwards compatible products (if you have any) once you migrate. Having said that, if all the products you're using in the Play console are backwards compatible, you should need minimal to no changes. In any case, please let us know if you run into issues during this migration and we would be happy to help!

MateoParodi commented 1 year ago

Hello again @tonidero,

Lucky for us, yes, all our products on Google Play are backwards compatible.

I updated to v6 and im already seeing that the response from Purchases.getOfferings() changed a lot.

In v5 we were able to get all the packages from the .availablePackages in the offering. from there we get the product and we know already if the product has an offer, for example I see the offer in the introPrice property. but since v6, with the new payload with all this subscriptionOptions, all my products comes with introPrice: null, so how can I identify if a product has an introPrice now? we need that because we need to show it in the paywall.

tonidero commented 1 year ago

Hi again @MateoParodi,

A few questions.

MateoParodi commented 1 year ago

Yes, my product has a freeTrial of 7 days.

I attach 2 screenshots: The first one with the packages of the v5 response: jsoncrack com (1)

And this one with the response of the v6. you can see that in the v6 I don't have anywhere the freeTrial of the package/product. Is this because im using a google account that already used the free trial? before it wasn't like that right? jsoncrack com (3)

MateoParodi commented 1 year ago

Alright, I have the answer, looks like now in the v6, in android at least, the introPrice comes only if the Google Account is eligible for it.

So that solves my questions.

Regarding the crashes, I'll do some testing and checking firebase after the release and I will post here so we can close the issue after.

Thank you very much for the support!

MateoParodi commented 1 year ago

Hello again @tonidero

Im doing some tests here in the android emulator and I can see in the adb logcat that my app is crashing for the same reason:

E AndroidRuntime: Caused by: java.lang.SecurityException: com.my-test.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

Also, I see that you guys updated the billing library to 5.2.1, but the fix I think is in the 6.0.1 https://developer.android.com/google/play/billing/release-notes#6-0-1

See comment here: https://github.com/android/play-billing-samples/issues/618

tonidero commented 1 year ago

Hi @MateoParodi,

Hmm that's strange... We were able to reproduce the issue and it got fixed after upgrading to 5.2.1. Also, Google's billing library 5.2.1 was released together with 6.0.1 with the same release notes.

Just to confirm, is this exception also coming from the billing client?

MateoParodi commented 1 year ago

any ideas or help on how can I know if the exception is comming from the billing client? Im not seeing it in my logs

tonidero commented 1 year ago

Are you able to see the full stack trace @MateoParodi? In your original stacktrace, it was clear that the issue was coming from the billing client: com.android.billingclient.api.zzh.zzc(com.android.billingclient:billing@@4.1.0:1) at.

Another way to confirm whether this comes from the RevenueCat SDK (more concretely from the billing client we depend on), is to put some breakpoints/prints before/after the SDK is configured and make sure the crash is happening there.

MateoParodi commented 1 year ago

hI @tonidero, Im pretty sure the crash is still coming from RC.

I have the version 6.2.2 and if I comment everything related to react-native-purchases on the javascript side, the crash disappears and the app builds and runs normally. As soon as I try to fetch the offerings for example, the crash is happening.

Im testing on the emulator Pixel_4_API_34(AVD) - Android 14 with --mode release

tonidero commented 1 year ago

Hi @MateoParodi I tried our sample app:

I did run into issues in debug mode, where it was crashing with this stacktrace:

Caused by: java.lang.SecurityException: com.revenuecat.purchases_sample: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5668)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
at com.facebook.react.devsupport.DevSupportManagerBase.reload(DevSupportManagerBase.java:1101)
at com.facebook.react.devsupport.DevSupportManagerBase.reloadSettings(DevSupportManagerBase.java:721)
at com.facebook.react.devsupport.DevSupportManagerBase.setDevSupportEnabled(DevSupportManagerBase.java:593)
at com.facebook.react.devsupport.DevSupportManagerBase.<init>(DevSupportManagerBase.java:206)
at com.facebook.react.devsupport.BridgeDevSupportManager.<init>(BridgeDevSupportManager.java:78)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at com.facebook.react.devsupport.DefaultDevSupportManagerFactory.create(DefaultDevSupportManagerFactory.java:86)
at com.facebook.react.ReactInstanceManager.<init>(ReactInstanceManager.java:255)
at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:330)
at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:94)
at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:41)
at com.revenuecat.purchases_sample.MainApplication.onCreate(MainApplication.java:60)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1316)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6997)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

In this case, it would seem that react-native debug systems are crashing in Android 14, but it seems unrelated to RevenueCat. Also, seems like this might be an issue in react native: https://github.com/facebook/react-native/issues/37769

One thought that comes to mind, do you maybe have cached an older version of the SDK? Still trying to figure out if there is something else wrong.

ThushalIntervest commented 1 year ago

Hi, @tonidero did you find any fix for this RN issue?

tonidero commented 1 year ago

Hi @ThushalIntervest, I haven't tried it recently, but looks like RN released 0.72.4 last week which seems to have included the fix. Have you tried that out?

ThushalIntervest commented 1 year ago

java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)

Yes, I upgraded new RN version. still occurred this issue. 😔

tonidero commented 1 year ago

I suggest asking in the RN issue then (I see you already did). I will retry this myself when I have time but this issue doesn't seem related to RevenueCat. I'm going to close this issue since the original issue seems to have been fixed.

ThushalIntervest commented 1 year ago

@tonidero I just figured this happen because I used react-native-blob-util library. They did not add a fix for that. Sorry for my misunderstood.

ZouZLong commented 11 months ago

@ThushalIntervest I also encountered the same problem, how did you solve it?

Prathap38 commented 8 months ago

Add ContextCompat.registerReceiver( this, mMessageReceiver, filter, ContextCompat.RECEIVER_EXPORTED )

GSSPawanKumarSingh commented 7 months ago

@ThushalIntervest I also encountered the same problem, while saving a file to a device how did you solve it?

ZouZLong commented 7 months ago

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

shayanfarshad commented 4 months ago

Add ContextCompat.registerReceiver( this, mMessageReceiver, filter, ContextCompat.RECEIVER_EXPORTED )

where should we add this line ?

ZouZLong commented 4 months ago

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。