我尝试从Android应用程序进行测试购买时遇到了一些问题。我尝试在官方教程之后实施应用内结算,然后选择使用checkout库让自己更轻松。不幸的是,我在两种情况下都遇到了完全相同的问题。
当我尝试购买时,Android购买弹出窗口会短暂出现,加载片刻,然后应用程序将崩溃。我可以在logcat中看到以下错误:
06-24 13:42:05.485 1558-2697/? E/Parcel: Class not found when unmarshalling: com.google.android.finsky.billing.common.PurchaseParams
java.lang.ClassNotFoundException: com.google.android.finsky.billing.common.PurchaseParams
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at android.os.Parcel.readParcelableCreator(Parcel.java:2517)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2374)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.BaseBundle.getString(BaseBundle.java:992)
at android.content.Intent.getStringExtra(Intent.java:6702)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:336)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1097)
at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:6275)
at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:339)
at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:6019)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:298)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3573)
at android.os.Binder.execTransact(Binder.java:573)
Caused by: java.lang.ClassNotFoundException: com.google.android.finsky.billing.common.PurchaseParams
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:1346)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:1406)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:400)
at android.os.Parcel.readParcelableCreator(Parcel.java:2517)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2374)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.BaseBundle.getString(BaseBundle.java:992)
at android.content.Intent.getStringExtra(Intent.java:6702)
at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:336)
at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:1097)
at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:6275)
at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:339)
at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:6019)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:298)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3573)
at android.os.Binder.execTransact(Binder.java:573)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
06-24 13:42:05.504 614-4655/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
06-24 13:42:05.661 28655-28655/? E/Zygote: v2
06-24 13:42:05.663 28655-28655/? E/Zygote: accessInfo : 0
06-24 13:42:05.707 1148-1329/? E/QC-NETMGR-LIB: Unsupported attribute type, ignoring 0x8
06-24 13:42:05.707 1148-1329/? E/QC-NETMGR-LIB: unrecognized ifindex 6
06-24 13:42:05.708 1148-1329/? E/QC-NETMGR-LIB: Unsupported attribute type, ignoring 0x8
06-24 13:42:05.708 1148-1329/? E/QC-NETMGR-LIB: unrecognized ifindex 6
06-24 13:42:05.742 4563-4677/? E/ContactsProvider_EventLog: Flush buffer to file cnt : 1 size : 0Kb duration : 7ms lastUpdatedAfter : 4014 ms mFlush_time_threasold : 2000 mCurrentSize : 487
06-24 13:42:05.938 21138-28711/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: com.android.vending, PID: 21138
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.NullPointerException: Attempt to read from field 'long com.google.wireless.android.finsky.dfe.nano.an.b' on a null object reference
at com.google.android.finsky.billing.lightpurchase.s.a(SourceFile:5)
at com.google.android.finsky.billing.lightpurchase.h.doInBackground(SourceFile:27)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
使用结帐库,购买的实际代码非常简单:
//SKU_PREMIUM is set to "android.test.purchased" and PURCHASE_DEVPAYLOAD is set to a random string of characters "T?ate755S,26B361Ml2nXxWW31H8Ex"
private final ActivityCheckout mCheckout = Checkout.forActivity(this, StethoApplication.getInstance().getBilling());
private Inventory mInventory;
private void configBilling() {
mCheckout.start();
mCheckout.createPurchaseFlow(new PurchaseListener());
mInventory = mCheckout.makeInventory();
mInventory.load(Inventory.Request.create()
.loadAllPurchases()
.loadSkus(ProductTypes.IN_APP, PremiumFragment.SKU_PREMIUM), new InventoryCallback());
}
public void purchasePremium() {
mCheckout.whenReady(new Checkout.EmptyListener() {
@Override
public void onReady(BillingRequests requests) {
requests.purchase(ProductTypes.IN_APP, PremiumFragment.SKU_PREMIUM, PremiumFragment.PURCHASE_DEVPAYLOAD, mCheckout.getPurchaseFlow());
}
});
}
This堆栈溢出帖有同样的问题,但该帖子正在处理实际的" live"测试购买而不是静态测试购买。我还看到一些帖子说你必须登录到不同于你的开发者帐户的谷歌帐户,但是再一次用于测试" live"购买。
由于我的自定义帐单代码以及结帐库存在同样的问题,我认为这是某种配置问题。我将该应用的alpha版本上传到Google Play,然后使用开发者控制台中的公钥初始化该库。我认为这可能会导致问题,但我不确定。
如果有人能指出我正确的方向,我会非常感激。