New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash with null pointer exception after Billing Service gets disconnected #45
Comments
Hi @dec1 The disconnection, in general, happens due to background operations performed by Play Store app. I'll address this problem internally, and get back to you when we have an ETA about the fix. Thanks |
Hi @netomarin Any news about this issue? It impacts buyers to sometimes crash on their purchase. |
I'm seeing the same issue. Any fix coming or recommended workaround? |
@pox822 @afehners do you have a stacktrace or any log to help? We are investigating this bug now: No response code in PURCHASES_UPDATED Bundle This error is generating a NullPointerException when checking the result and maybe it's disconnecting the client. I'll get back with some news ASAP. Thanks |
java.lang.NullPointerException: |
I'm not sure my stack trace will help since I've made a few fixes to the sample IabHelper to make it more robust. Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.a.a.a.a.a(int, java.lang.String, java.lang.String, java.lang.String)' on a null object reference The failing line of code is the last line of this block
The logs show the billing service gets disconnected after a while and the crash comes when trying to query inventory:
To fix it in my copy I simply added to checkNotDisposed() a check that if mService is null and mSetupDone is true it throws an illegal state exception. I catch this in my code and setup IabHelper again and retry. |
I'm getting the same crash as @aliafshar (with a slightly modified @aliafshar: A few questions about your fix. Don't you have to call Overall, I think that your fix will solve my crash. Thank you so much for mentioning it here! |
This is my error message.
Hope it get fixed soon. |
I have exactly the same problem as @afehners (mService is null on line 945). And based on Crashlytics, the problems occurs a lot. Unfortunately I haven't been able to reproduce it on my test devices. Almost all the time, the problem occurs while the app is not in focus (running as a foreground service). |
If you want to reproduce this use case:
Once you return back to your app, service should be disconnected from the Play Store. So any operation on it will throw NPE. And the best way to solve this issue is by implementing retry-policy specific to your needs as Neto mentioned above. |
Hi, may I know any ETA for this issues fixed? Time-to-time, we will get crash report from developer console. We find it is difficult to fix the problem, without guidance from Google team. Thanks. |
Hi @yccheok and all developers in this thread This problem is caused because your BillingClient is not maintaining the connection status. Override the onBillingServiceDisconnected() callback method and implement your own retry policy to handle lost connections to Google Play in the event the client loses connection. The Play Billing Library client must call the startConnection() method to restart the connection before making further requests. As mentioned by @gorgon, you can check the open-sourced sample Trivial Drive v2 and use the same approach. I'm closing this issue, since it's not an issue related to the sample. Thanks, |
Thanks. I didn't notice that TrivialDrive had been updated using recent https://developer.android.com/google/play/billing/billing_library.html Guess we need to refactor our previous code which is using old |
The "bug" @gorgon and @netomarin missed and failed to mention directly is: |
Does it say this somewhere clearly? Presumably it should. billing_integrate.html still describes using the old IabHelper and IInAppBillingService.aidl Whereas for example The github example both reference, contains both a "TrivialDrive" and "TrivialDrive_v2" subdir, each of which simply describe themselves as
Even though billing/versions.html shows version 5 to be current since Feb 2015 And this on top of how hard it is to get the sample working anyways (setting up your own in-app products in developer console, modifying the app to reflect this, only working with signed release etc). A bit more clarity here could save many 1000s of developers many frustrating hours |
billling_library.html feels unfinished as well. Why does the chapter 'Retrieve existing purchases' describe and show 'Google Play calls the onPurchasesUpdated() method to deliver the result of the purchase operation'? How is this relevant? Is it called on service connect? Three chapters down we learn you should use I tried to re-implement billing because of the NPEs. I hate trial and error, and not just the annoying, impossible to really test billing. The docs suck. I'm irritated. |
@netomarin why do you close the issue when there still is a big problem with non reproducible NPEs to production builds? Following the documentation for using IABHelper to a tee still cause these problems, but you think its is OK to close the issue? Can I at least get an answer to if IABHelper is valid to use? Is the BillingClient approach what we are supposed to use now? If so why do you not give that info anywhere? The only thing I can do now is catch the internal exceptions to prevent crashes, getting the purchase flow to work... just forget it, at least using IABHelper. |
@dec1 the page billing_integrate.html is a "generic" guide, provided for developers that doesn't want to use Play Billing Library, or can't use due to a platform incompatibility (like developing using NDK or C++). So, we decided to keep this page with generic instructions about how to use AIDL interface. "Note: This guide provides general instructions to help you implement the In-app Billing API in your app. The Play Billing Library provides a wrapper around the In-app Billing API and is designed to help you when integrating the API. To see a complete implementation using the library, visit the Play Billing Library training class. The training class provides a complete sample In-app Billing app, which demonstrates how to start a purchase flow, handle purchase result, list your products, consume an item, and much more." @dec1 about the samples descriptions, you are right, we will improve it ASAP. Thanks. @d-schmidt Play Billing Library guide is finished and up-to-date to our current development state. If the documentation is missing something or you feel that is not correct, please open a bug in our public bug tracker. This channel is for issues related to the TrivialDrive samples. @d-schmidt we mention the onPurchasesUpdated method because it's called when a purchase is updated, even it's not started from the current device, so it's important to know how to handle it to keep you inventory up to date. @d-schmidt Google Play's cache has it owns update policy, but it happens on a very short amount of time and it's totally safe. And other difference between queryPurchases() and queryPurchaseHistoryAsync() is that queryPurchasesHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed, and queryPurchases() only the valid managed purchases. "Use the queryPurchases() method whenever possible as it uses the local cache, in preference to the queryPurchaseHistoryAsync() method." @Aperico-com The issue is closed because it's not a issue caused by the sample code. The samples are fine and running, and if you are facing a NPE in your modified code, as we mentioned earlier, you need to check the connection status and implement your own retry policy. Hope I could address all open questions. |
|
@netomarin I implemented a reconnect policy. But my question and the original question was about IABHelper and your online docs for it, you keep referencing to Billing Client, that is why I ask again, should devs not use IABHelper anymore, is it obsolete and if so why does the docs not say that? |
If by "generic" you mean a "low level confusing and buggy example", then I suppose you're right. I didn't know there was an api NDK/C++ developers could use for in-app billing? Can you point me to the documentation? And if a developer did want to do so using C++, did they could just use JNI to call the corresponding methods of the newer less buggy JAVA classes, just as easily as the could the older JAVA example. |
@Aperico-com Our recommendation is to use the Play Billing Library. We have no more plans to update the Trivial Drive v1, that uses the IABHelper. @dec1 I'm sorry if you feel that way, but the Trivial Drive v2 covers how to use Play Billing Library, including how to list products, retrieve purchases and start flows for in-app purchases and subscriptions. For C/C++ you can use the AIDL interface to communicate with the Google Play service, similar to what you can do for any service. For all methods on AIDL service, please check In-app Billing Reference. If you want to see the AIDL file, please check IInAppBillingService.aidl. And for a better support for C++ developers, we are already working on a C++ library and sample, and I hope we will have news soon. Also, we are working on a Kotlin version for Trivial Drive v2. |
Recently, we refactor our code, from The outcome is that, we see much less crash report related to billing. Thank you for providing |
@netomarin "please could you point a bug that still blocking you to use Google Play Billing?" - Sure, how about the bug where queryPurchases() returns an empty list, but any attempt to purchase an IAP returns an error code 7 - item already in inventory. That is a pretty big bug with billing library. Sure, it only seems to happen for my users who had already purchased items with the old IabHelper system before I upgraded to billing library, but because of this bug I had to go back to the old IabHelper system. Worst, there are many people who have been having this bug for months according to your issue tracker. Do you even look at the issue tracker that you have pointed us to? "We want to help all developers to implement in-app billing easily." - You're joking, right? Google's actions seem to indicate the exact opposite of this. |
After successful setup and the establishment of a connection to the Billing Service in
IabHelper.startSetup()
The user tries to make an in-app purchase.
IabHelper.launchPurchaseFlow()
gets called which in turn calls methods on
mService
. But sometimesIabHelper.onServiceDisconnected()
has been called in the meantime which sets
IabHelper.mService = null
This causes a null pointer exception.
It seems unpredictable when/why this disconnection happens. But I have some pre-launch reports in my developer console as examples.
Would be resolved by:
#46
The text was updated successfully, but these errors were encountered: