Flutter/Android: How to fix "Billing service disconnected."?
Asked Answered
C

5

8

Some time ago, I've added in app purchases to a Flutter app (Android and iOS) by happily copy&pasting the code from the code lab. It's working in production. However, all out of a sudden, running the Android build from VS Code, prints the following two messages in rapid succession:

W/BillingClient(25973): Billing service disconnected.
D/InAppPurchasePlugin(25973): Tried to call onBillingSetupFinished multiple times.

After the messages are logged hundreds of times, the following DeadObjectException occasionally joins in:

W/BillingClient(25973): Exception while checking if billing is supported; try to reconnect
W/BillingClient(25973): android.os.DeadObjectException
W/BillingClient(25973):     at android.os.BinderProxy.transactNative(Native Method)
W/BillingClient(25973):     at android.os.BinderProxy.transact(BinderProxy.java:595)
W/BillingClient(25973):     at com.google.android.gms.internal.play_billing.zzh.zzo(com.android.billingclient:billing@@6.0.1:2)
W/BillingClient(25973):     at com.google.android.gms.internal.play_billing.zzc.zzq(com.android.billingclient:billing@@6.0.1:5)
W/BillingClient(25973):     at com.android.billingclient.api.zzaf.zza(com.android.billingclient:billing@@6.0.1:13)
W/BillingClient(25973):     at com.android.billingclient.api.zzac.call(Unknown Source:2)
W/BillingClient(25973):     at java.util.concurrent.FutureTask.run(FutureTask.java:264)
W/BillingClient(25973):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
W/BillingClient(25973):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
W/BillingClient(25973):     at java.lang.Thread.run(Thread.java:1012)

Problem with these messages is that the device runs hot and the animations become jerky, indicating that either BillingClient or InAppPurchasePlugin is busy in an endless loop.

Now the short question is, what's causing this? And how can it be fixed?

Where it happens:

The code lab recommends to create an IAPConnection class looking like:

// Gives the option to override in tests.
class IAPConnection {
  static InAppPurchase? _instance;
  static set instance(InAppPurchase value) {
    _instance = value;
  }

  static InAppPurchase get instance {
    _instance ??= InAppPurchase.instance;
    return _instance!;
  }
}

Shortly after InAppPurchase.instance; is accessed for the first time, the messages start to show up. Even if in_app_purchase's api is otherwise unused.

What's also interesting is that IAPConnection.instance.purchaseStream's onError() callback isn't called.

Beside that, in app purchases are working just fine in production and even in debug mode, purchases are properly restored before the messages start to show up.

It happens on a physical Android 13 device with in_app_purchase package 3.1.5 to 3.1.10 and Flutter 3.13.6.

Any ideas on what causes this or how to workaround or fix it are very much appreciated. Thank you.

Comical answered 3/10, 2023 at 13:0 Comment(2)
Are trying to run in emulator?Millennial
Happens on a physical device - haven't tried on the emulator. Thanks for pointing this out. Question was updated.Ember
G
4

You should open a record on issue tracker, this is Google's problem 100%. By the way you can trigger this by running your app and then changing the system language a couple of times.

I tried to open an issue myself, twice, but it just won't appear.

Galvin answered 5/10, 2023 at 9:50 Comment(7)
Thank you very much for sharing this! Especially the detail about changing the system language. Unfortunately the problem disappeared after deleting data/cache of Google Play services and Google Play Store. Being able to reproduce it will help a lot. So gain, thank you. BTW. between which languages are you switching?Ember
BTW. should the issue appear at the tracker, please post a link, I'll add my share then.Ember
Any languages, in my case. I tried to open an issue 2 weeks ago, so I guess it won't apear. Probably some account problems.Galvin
I am facing the same issue at in_app_purchase: ^3.1.8. I switched the locale English to French @ComicalVivien
@Galvin Same issue here since upgrade billing service to v3. Is there a link for the issue you reported to Google? I would like to reply my case to the trackerStreit
@AlanLu, no, the issue doesn't appear. You should try to open one yourself.Galvin
@AlanLu did open one, it is here. issuetracker.google.com/issues/309541595 However, in my years and years of development I haven't seen them fix one issue. :(Hellbender
S
2

I have reported this issue to Google: Issue Tracker and got the reply "Won't fix" in #6

Here are the recommendation from them:

It is possible that the language update triggered by a system locale change can fail, which can prevent the service from being available. In this case, I recommend that users wait for 1-2 minutes after changing the locale to see if they can make a purchase. If not, the user will need to manually go to the Play Store to finish the installation process in order to continue the purchase.

Streit answered 20/11, 2023 at 8:20 Comment(0)
B
0

Suddenly, I encountered a similar error on my test phone. I haven't cleared the cache of Google Play.

 W/BillingClient: Exception while checking if billing is supported; try to reconnect
android.os.DeadObjectException
    at android.os.BinderProxy.transactNative(Native Method)
    at android.os.BinderProxy.transact(BinderProxy.java:605)
    at com.google.android.gms.internal.play_billing.zzp.zzs(com.android.billingclient:billing@@6.1.0:2)
    at com.google.android.gms.internal.play_billing.zzk.zzv(com.android.billingclient:billing@@6.1.0:5)
    at com.android.billingclient.api.zzao.zza(com.android.billingclient:billing@@6.1.0:7)
    at com.android.billingclient.api.zzal.call(Unknown Source:2)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)

After clearing the data from Google Play, the problem disappeared. I think the issue arose when switching the language from English to Bulgarian.

Boxhaul answered 18/11, 2023 at 17:54 Comment(1)
Yup, this seems to be connected to a language change, see @Alan Lu 's answer above. issuetracker.google.com/issues/309541595Hellbender
S
0

happened for me too on a physical device when I changed the Language / Region (tried changing from English (US) to Francais (France)).

Just opening the Google Play app fixed it. As did clearing cache for the Google Play app.

Swipple answered 2/1, 2024 at 11:31 Comment(0)
A
-1

I'm in the same boat, out of the blue suddenly this error occurs on a physical Android device using flutter in_app_purchase: ^3.1.10.

Strangely it used to work before some time...

EDIT: So I found the source of the problem in my case was that I added code to restore purchases in the initialization phase

Future<bool?> initialize(PlatformManager platformManager) async {
final Stream purchaseUpdated =
    InAppPurchase.instance.purchaseStream;
_subscription = purchaseUpdated.listen((purchaseDetailsList) {
  _listenToPurchaseUpdated(purchaseDetailsList);
  }, onDone: () {
    _subscription.cancel();
  }, onError: (error) {
    // handle error here.
  });
await _loadProducts();
//await InAppPurchase.instance.restorePurchases();
}

The last line that is commented out caused the problem.

Adjoint answered 3/10, 2023 at 22:23 Comment(2)
Thank you very much for sharing this! I'll take a closer look at it. My app is doing something similar, so it could be related. Strange thing is, once the issue happens, simply accessing InAppPurchase.instance; is already enough to trigger the bug. Again, thanks for your help!Ember
Yesterday the bug got reintroduced, despite no code changes. BTW l left the call to restorePurchases() in the initalization, just moved it at first position and removed the blocking await. Now even if I comment it out I get the error, so its probably something else.Adjoint

© 2022 - 2025 — McMap. All rights reserved.