flutter_inapp_purchase icon indicating copy to clipboard operation
flutter_inapp_purchase copied to clipboard

Fatal Exception: java.lang.IllegalStateException: Reply already submitted (Is not fixed)

Open soarescaique opened this issue 2 years ago • 14 comments

According to PR #360 this bug was fixed, but in fact it's still happening. I have updated to the last version yesterday, and released to production. Today I got this error from Firebase Crashlytics several times, which I was not getting before on version (^5.1.2) ( I got it a few times, but this time is worse).

Error from Firebase Crashlytics:

Fatal Exception: java.lang.IllegalStateException: Reply already submitted
       at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:430)
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:267)
       at com.dooboolab.flutterinapppurchase.MethodResultWrapper$1.run(MethodResultWrapper.java:27)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7955)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Crash on: Android (real device) flutter_inapp_purchase: ^5.2.0 flutter stable channel: ">=2.12.0 <3.0.0"

Actual Behaviour:

My app has a (weekly/monthly) subscription feature, which I deliver to the user if the payment is successful. Every time the user access a premium content, I get his purchase history, and I check if he has an active subscription, if he does not have, I suspend the premium feature in the app. But when I use the .getAvailablePurchases() method, I get an error and the app crashes.

@valterh4ck3r @offline-first Tried to fix this error on the PR #360, but it's still happening. Maybe @hyochan should downgrade this version.

soarescaique avatar May 18 '22 02:05 soarescaique

I have this error on 5.1.2

meowofficial avatar May 18 '22 16:05 meowofficial

@meowofficial , please update your package to 5.2.0 and test again.

valterh4ck3r avatar May 18 '22 16:05 valterh4ck3r

@meowofficial Do you still have the same bug on version 5.2.0? Because I do.

soarescaique avatar May 18 '22 21:05 soarescaique

@valterh4ck3r @soarescaique Yes I tested 5.2.0 on last beta and stable channels. App crashes because of getProducts() and getSubscriptions() (getAvailablePurchases() works as expected). When I call this methods with open connection app crashes. When I call this methods without open connection I get PlatformException(getItemsByType, IAP not prepared. Check if Google Play service is available., , null)

meowofficial avatar May 19 '22 04:05 meowofficial

@meowofficial We are talking about a different error. We are trying to find out if people on version 5.2.0 are still getting the error Fatal Exception: java.lang.IllegalStateException: Reply already submitted after calling the getAvailablePurchases() or requestPurchase(). Which is not a normal bug, but it happens sometimes on production.

The error PlatformException(getItemsByType, IAP not prepared. Check if Google Play service is available., , null) is a normal behaviour of the package if you try to call getProducts() or getSubscriptions() before initialize() the inAppPurchase instance

soarescaique avatar May 19 '22 13:05 soarescaique

@soarescaique I'm getting exact same error when call getProducts() and getSubscriptions() within open connection

meowofficial avatar May 19 '22 14:05 meowofficial

@meowofficial That's weird. Were you able to run the example code of the package successfully? I never got this error after calling getProducts() or getSubscriptions(). If you could provide more code details of the bug, we could try to find a solution. Are you having it on iOS or Android?

soarescaique avatar May 19 '22 14:05 soarescaique

@soarescaique I didn't test example code. getAvailablePurchases() doesn't crash the app for me at least when it returns empty list. It crash the app when I try to fetch products or subscriptions on Android.

meowofficial avatar May 19 '22 14:05 meowofficial

@meowofficial I would suggest you to try the example code and see if it works as expected. Cause I use this package for a few months on production and I never had this error when trying to fetch products ou subscriptions. But anything is possible. Check the example code and let me know.

soarescaique avatar May 19 '22 14:05 soarescaique

@soarescaique can you test with this example on real devices?

void test()async{
    await FlutterInappPurchase.instance.initialize();
    _testItems();
    _testPurchases();
    _testHistory();
  }

  void _testItems()async{
    final subscriptions = FlutterInappPurchase.instance.getSubscriptions(["1_month", "12_month"]);
    final products = FlutterInappPurchase.instance.getProducts(["plus_lifetime"]);
    final itemsFutures = await Future.wait([subscriptions, products]);
    final items = itemsFutures.expand((it) => it).toList();
    items.forEach((it) { debugPrint("TEST items:${it.toDebugString()}");});
  }

  void _testPurchases()async{
    final purchases = await FlutterInappPurchase.instance.getAvailablePurchases();
    if(purchases == null || purchases.isEmpty)debugPrint("no purchases");
    purchases?.forEach((it) { debugPrint("TEST getAvailablePurchases:${it.toDebugString()}");});
  }

  void _testHistory()async{
    final history = await FlutterInappPurchase.instance.getPurchaseHistory();
    if(history == null || history.isEmpty)debugPrint("TEST no history");
    history?.forEach((it) { debugPrint("TEST getPurchaseHistory:${it.toDebugString()}");});
  }

If you have any issues, please test with this PR #365

offline-first avatar May 21 '22 19:05 offline-first

@offline-first I will do it and let you know the tests result. Hope it works.

soarescaique avatar May 21 '22 21:05 soarescaique

@offline-first Sorry for the late response. I just tried your example above and got the same error.

I am running on version 5.2.0.

Tested on a Real Android Device.

Got the error after calling .getAvailablePurchases()

Fatal Exception: java.lang.IllegalStateException: Reply already submitted
       at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:430)
       at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:267)
       at com.dooboolab.flutterinapppurchase.MethodResultWrapper$1.run(MethodResultWrapper.java:27)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7955)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

I have tested your PR #365 and it seems to be working. I did not get the issue above testing your fork.

soarescaique avatar May 23 '22 01:05 soarescaique

Thank you! I will fix other issues with the android plugin in the next days and add more features. Hopefully the author of this plugin check #365

offline-first avatar May 23 '22 07:05 offline-first

@offline-first Thank you for your time and contribution. Feel free to contact me to help testing your changes or anything. I was making some changes on the .java files of the package to make it work, and then submit a PR. But since you have refactored the .java files to .kotlin I will be waiting for @hyochan to approve it, and then add some features too.

soarescaique avatar May 23 '22 13:05 soarescaique

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 22 '22 02:08 github-actions[bot]