I've been struggling with Android IAB v3 for a while now. I have it working consistently on my test devices. However, my crash reporting service shows two recurring crashes: one for null pointer exception and one for illegal state exception. I've tried updating the Google sample code w/ numerous suggestions from Stackoverflow users facing similar problems. I've gone through the "read crash reports, do research, attempt to fix crashes, submit update, see same crash reports again" cycle a few times. I think it's time for a different approach.
If you were starting with Android IAB today, what would you choose as the most up-to-date, correct resource for code samples, fixes, documentation, etc?
This doesn't have to be a single resource. Any combination of sample code, patches from SO posts, blog posts, or even "update with Android SDK Manager" will be helpful. Ideally, we can create a resource for folks new to IAB that prevents them from the headache and struggle of trying to integrate the service.
edit 1: More info on crashes
java.lang.IllegalStateException: Can't start async operation (refresh inventory) because another async operation(launchPurchaseFlow) is in progress.
at com.android.vending.billing.IabHelper.flagStartAsync(IabHelper.java:832)
at com.android.vending.billing.IabHelper.queryInventoryAsync(IabHelper.java:623)
at com.android.vending.billing.IabHelper.queryInventoryAsync(IabHelper.java:651)
...
java.lang.NullPointerException
at com.android.vending.billing.IabHelper.launchPurchaseFlow(IabHelper.java:398)
at com.android.vending.billing.IabHelper.launchPurchaseFlow(IabHelper.java:350)
...
Those are the two exceptions. They don't always happen in the same places in IabHelper. I could probably just patch them, but that doesn't seem like the right way to solve this problem. Also, it doesn't help anyone else.
It's possible that I'm using out-dated sample code form Google. However, I've searched quite a bit and couldn't find anything more recent.
Hey I'm also working on InApp Purchase since 10 days and I've successfully integrated in my existing app and ready to make it live. Initially when i had started doing this I've downloaded google InApp Billing Example called "Trivial Drive" from here.
But it didn't help me much as it has lots of issues and bugs, So I've decided do it on my own from scratch using new v3 api which you can find here. This tutorial has clear explanation that would help you and also if you have time see this youtube video where google employee had explained clearly how to integrate it.
Also if you want quick example, I've a sample app which you can download from here. Feel free to ask if you have any questions.
The first IllegalStateException
is occurring because the previously launched operation using IAB Helper is yet to complete.
Probable causes:
mHelper.dispose()
in onDestroy()
of activity.In your case you are trying to query inventory when already a launchPurchase is progress.
Solution:
The status of async operation is reflected in variable mAsyncInProgress
in IabHelper
. You will have to change the scope of the variable to public
, it package by default. You can then take either of the two approaches after querying the variable:
Make sure you have called mHelper.dispose()
in onDestroy()
of activity.
or
The exception is thrown in flagStartAsync
function.
To figure our the root cause of the NullPointerException
you will have to provide the code for launchPurchasFlow with line numbers.
Other precautions you should take:
To avoid "IAB helper is not set up. Can't perform operation:launchPurchaseFlow which is caused when you call launchPurchaseFlow
before IabHelper setup is complete.
You can disable the buy button by default. Enable the button on onIabSetupFinished
callback of the IabHelper. Therefore the button will work only when the IabHelper setup is complete.
You are probably using async operations. The current IabHelper is not safe in case you use the ...async methods. The problem is that in any moment an async operation is running dispose can be called on the main thread. In this case you will get NullPointerExceptions and IllegalStateExceptions.
Try with this clone studiozanandroid
With ref this Ans , download the patch here to avoid async errors.
other than this checkout the signature validation issues like in this pay me lib,try to use OpenIAB libs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With