React-native-iap: 购买`android.test.canceled`产品会使应用崩溃

创建于 2019-01-28  ·  5评论  ·  资料来源: dooboolab/react-native-iap

版本的react-native-iap

2.4.0-beta8

本机版本

0.55.4

您遇到错误的平台(IOS或Android还是两者兼而有之?)

安卓

预期行为

购买承诺被拒绝E_USER_CANCELLED, "Cancelled."

实际行为

应用程序崩溃:

01-28 11:21:58.177 2773-2919/ D/RNIapModule: buyItemByType (type: inapp, sku: android.test.canceled, oldSku: null, prorationMode: 0) responseCode: 0(OK)
01-28 11:22:03.509 2773-2919/ D/RNIapModule: Purchase Updated Listener
01-28 11:22:03.509 2773-2919/ D/RNIapModule: responseCode: 0

                                                                       --------- beginning of crash
01-28 11:22:03.510 2773-2919/ E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
                                                                          Process: , PID: 2773
                                                                          java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
                                                                              at com.dooboolab.RNIap.RNIapModule$11.onPurchasesUpdated(RNIapModule.java:436)
                                                                              at com.android.billingclient.api.BillingClientImpl$1.onReceiveResult(BillingClientImpl.java:151)
                                                                              at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:50)
                                                                              at android.os.Handler.handleCallback(Handler.java:789)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                              at android.os.Looper.loop(Looper.java:164)
                                                                              at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
                                                                              at java.lang.Thread.run(Thread.java:764)

经过测试的环境(仿真器?真实设备?)

真实设备

重现行为的步骤

  • 购买Android静态测试产品android.test.canceled
  • 调用onPurchasesUpdated ,在第436行Purchase purchase = purchases.get(0);处引发NPE,因为purchases@Nullable nullresponseCode为0。
🐛 bug 🚶🏻 stale 🤖 android

最有用的评论

@johnmartel是的。 我一直希望实现一些测试模块,但是目前,我总是没时间使用😿。 发布之前,我们必须自己检查运行时。

所有5条评论

感谢解决方案的问题。 @johnmartel如果您已经知道如何解决问题,希望您给我们PR

@hyochan我正在研究这个问题,我将尽快提交PR。 问题是lib严重缺乏测试,很难确定我没有破坏其他任何东西。

@johnmartel是的。 我一直希望实现一些测试模块,但是目前,我总是没时间使用😿。 发布之前,我们必须自己检查运行时。

像这样检查purchases是否null怎么样?

  PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
    <strong i="8">@Override</strong>
    public void onPurchasesUpdated(int responseCode, <strong i="9">@Nullable</strong> List<Purchase> purchases) {
      Log.d(TAG, "Purchase Updated Listener");
      Log.d(TAG, "responseCode: " + responseCode);

      if (responseCode != BillingClient.BillingResponse.OK) {
        rejectPromisesWithBillingError(PROMISE_BUY_ITEM, responseCode);
        return;
      }

+      if (purchases == null) {
+        rejectPromisesWithBillingError(PROMISE_BUY_ITEM , responseCode);
+       return;
+      }

      Purchase purchase = purchases.get(0);

     // ...

嘿,看来最近没有任何活动在此问题上。 问题是否已解决,还是仍然需要社区的关注? 如果没有其他活动,则可能已关闭此问题。 您也可以将此问题标记为“供讨论”或“良好的第一期”,我将其保留为开放状态。 感谢你的贡献。

此页面是否有帮助?
0 / 5 - 0 等级