RevenueCat / purchases-flutter

Flutter plugin for in-app purchases and subscriptions. Supports iOS, macOS and Android.
https://www.revenuecat.com/
MIT License
611 stars 170 forks source link

Paywalls not working at all on Android platform #1111

Closed arabnology closed 4 months ago

arabnology commented 4 months ago

‼️ Required data ‼️

Do not remove any of the steps from the template below. If a step is not applicable to your issue, please leave that step empty.

There are a lot of things that can contribute to things not working. Having a very basic understanding of your environment will help us understand your issue faster!

Environment

Describe the bug

This issues is always appear on android, my minSDK 26 and targetSDK is 34. Also this issue always shown: This declaration needs opt-in. Its usage must be marked with '@com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI' or '@OptIn(com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI::class)'

Additional context

Add any other context about the problem here.

RCGitBot commented 4 months ago

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

vegaro commented 4 months ago

As I/flutter ( 8475): Errrorrr: startPurchasing: PlatformException(0, Make sure your MainActivity inherits from FlutterFragmentActivity, null, null) says, you need to make sure your MainActivity in the android folder of your project inherits from FlutterFragmentActivity

Take a look at our tester app https://github.com/RevenueCat/purchases-flutter/blob/main/revenuecat_examples/purchase_tester/android/app/src/main/java/com/revenuecat/purchases_sample/MainActivity.kt where we are inheriting from FlutterFragmentActivity

arabnology commented 4 months ago

As I/flutter ( 8475): Errrorrr: startPurchasing: PlatformException(0, Make sure your MainActivity inherits from FlutterFragmentActivity, null, null) says, you need to make sure your MainActivity in the android folder of your project inherits from FlutterFragmentActivity

Take a look at our tester app https://github.com/RevenueCat/purchases-flutter/blob/main/revenuecat_examples/purchase_tester/android/app/src/main/java/com/revenuecat/purchases_sample/MainActivity.kt where we are inheriting from FlutterFragmentActivity

Thanks for response,

Is it having any bad side effects, or maybe creating bugs for other plugins? or is it okay to do that?

vegaro commented 4 months ago

We are not aware of any issues or incompatibilities so far. We require FlutterFragmentActivity because it provides some methods that are not available in FlutterActivity.

If you find any issues with another plugin please let us know so we are aware. Thank you!

arabnology commented 4 months ago

We are not aware of any issues or incompatibilities so far. We require FlutterFragmentActivity because it provides some methods that are not available in FlutterActivity.

If you find any issues with another plugin please let us know so we are aware. Thank you!

Thank you.

arabnology commented 4 months ago

We are not aware of any issues or incompatibilities so far. We require FlutterFragmentActivity because it provides some methods that are not available in FlutterActivity.

If you find any issues with another plugin please let us know so we are aware. Thank you!

I have found an issue when using FlutterFragmentActivity:

When you are using FlutterFragmentActivity, the PopScope widget, when pressing the device's back button, it takes you out of the app, which is incorrent.

When using FlutterActivity, the PopScope widget works as expected, when pressing the device's back button, it takes you to the previous screen, which is correct.

vegaro commented 4 months ago

Thanks for reporting that @arabnology

We do need to use a FlutterFragmentActivity, there's no way around that, so we can't rely on a FlutterActivity. I would suggest reporting to the creators of PopScope the issues you're seeing. In any case, I took a quick look and saw this issue that looks related https://github.com/flutter/flutter/issues/128690#issuecomment-1587403083 , so maybe this helps:

Since it was only happening in android 13, I figured it had something to do with the android:enableOnBackInvokedCallback="true/false" in the android manifest XML file. I set it previously to true because of something I don't exactly remember, and resetting it back to false seems to have, hopefully, fix it for now.