Successful purchase but has "Class not found" when unmarshalling: com.google.android.finsky.billing.lightpurchase.PurchaseParams

I have an app with In-App Billing in its Adapter (list of items to buy). I am having a problem during testing of the in-App Billing.

Everything works fine - The user is able to go through the whole purchase process. "Successful Purchase" is shown at the end of the Purchase Flow and there is an email being sent to the user confirming their purchase.

However, the item does not seem to be consumed and my server call to add the item to the user is not being called. Upon checking the logs, I see this error

12-02 13:04:47.701 29663 29663 D IabHelper: Launching buy intent for xxxxxxxxxxx. Request code: 10001
12-02 13:04:47.701  2450  3128 D EnterpriseDeviceManager: ContainerId: 0
12-02 13:04:47.711  2450  3128 E Parcel  : Class not found when unmarshalling: com.google.android.finsky.billing.lightpurchase.PurchaseParams
12-02 13:04:47.711  2450  3128 E Parcel  : java.lang.ClassNotFoundException: com.google.android.finsky.billing.lightpurchase.PurchaseParams
12-02 13:04:47.711  2450  3128 E Parcel  :  at java.lang.Class.classForName(Native Method)
12-02 13:04:47.711  2450  3128 E Parcel  :  at java.lang.Class.forName(Class.java:251)
12-02 13:04:47.711  2450  3128 E Parcel  :  at java.lang.Class.forName(Class.java:216)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Parcel.readParcelable(Parcel.java:2097)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Parcel.readValue(Parcel.java:2013)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Bundle.unparcel(Bundle.java:249)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Bundle.getString(Bundle.java:1118)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.content.Intent.getStringExtra(Intent.java:5145)
12-02 13:04:47.711  2450  3128 E Parcel  :  at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1467)
12-02 13:04:47.711  2450  3128 E Parcel  :  at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1063)
12-02 13:04:47.711  2450  3128 E Parcel  :  at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:4313)
12-02 13:04:47.711  2450  3128 E Parcel  :  at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:254)
12-02 13:04:47.711  2450  3128 E Parcel  :  at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:4194)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:260)
12-02 13:04:47.711  2450  3128 E Parcel  :  at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2645)
12-02 13:04:47.711  2450  3128 E Parcel  :  at android.os.Binder.execTransact(Binder.java:404)
12-02 13:04:47.711  2450  3128 E Parcel  :  at dalvik.system.NativeStart.run(Native Method)
12-02 13:04:47.711  2450  3128 E Parcel  : Caused by: java.lang.NoClassDefFoundError: com/google/android/finsky/billing/lightpurchase/PurchaseParams
12-02 13:04:47.711  2450  3128 E Parcel  :  ... 19 more
12-02 13:04:47.711  2450  3128 E Parcel  : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.finsky.billing.lightpurchase.PurchaseParams" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
12-02 13:04:47.711  2450  3128 E Parcel  :  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
12-02 13:04:47.711  2450  3128 E Parcel  :  at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
12-02 13:04:47.711  2450  3128 E Parcel  :  at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
12-02 13:04:47.711  2450  3128 E Parcel  :  ... 19 more
12-02 13:04:47.711  2450  3128 V ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname com.android.vending
3318 次浏览

This problem has been making the rounds in stackoverflow, if this issue is correct it is related with some wrong reflection that tries to load a class that is not present when a parameter is null in your code

It looks like there may be a race condition between PurchaseAsync and the HandleActivityResult callback. tcsPurchase is being set after the call to serviceConnection.Service.GetBuyIntent which I think allows the HandleActivityResult call happen while tcsPurchase is still null. When I pass an empty string for the "payload", it gets deserialized as null, causing the comparison to fail when checking for success.

So make sure the payload is not null before calling that method.