Search code examples
javakotlinin-app-purchasein-app-billing

IabHelper no longer imports android.vending.billing.IInAppBillingService after upgrading to billingclient:billing:2.1.0


On upgrading the billingclient to 2.1.0:

implementation 'com.android.billingclient:billing:2.1.0'//from 2.0.1

I suddenly got a cannot resolve symbol 'vending' error in my IabHelper class:

enter image description here

I've had to go back to billing:2.0.1 to prevent this. I notice the link to Trivial Drive 2 from the inapp billing docs https://github.com/android/play-billing-samples/tree/master/TrivialDrive_v2 now gives a '404' can't find error. Digging through githup I see Trivail Drive 2 is archived, a new Kotlin example is now featured, 'TrivialDriveKotlin'.

Is the Trivial Drive 2 implementation of inapp billing no longer supported by the latest billing code? Is there an java version of the TrivialDriveKotlin code somewhere?

I could and will do a translation if there isn't, but there should be a java version of this up front. Getting the original trivial drive 2 code working and debugged in the first place was such a pain.


Solution

  • My solution ended up being not to bother with the Trivial Drive example at all. The current implementation is simple enough to implement directly starting here https://developer.android.com/google/play/billing/billing_library_overview.

    The tricky part right from the start is this line:

    billingClient = BillingClient.newBuilder(activity).setListener(this).build();
    

    It's odd to see both 'activity' and 'this' used in the same line as you would typically substitute 'this' for 'activity'. You will get compile or runtime errors if these aren't set correctly. Better would be:

    billingClient = BillingClient.newBuilder(this).setListener(new PurchasesUpdatedListener() {...}).build();
    

    or

    PurchasesUpdatedListener puchaselistener;
    puchaselistener = new PurchasesUpdatedListener() {...}
    billingClient = BillingClient.newBuilder(this).setListener(purchaselistener).build();