首页 > 解决方案 > Flutter in_app_purchase 1.0.6 在 Android 设备上失败并显示错误消息:“W/BillingClient(15440): getSkuDetails() failed. Response code: 2”

问题描述

我已经设置了一个应用内项目,并在 Google Play 控制台上激活了它。

当我flutter run在我的 android 设备上时,应用程序运行但它给出了以下错误日志。

W/BillingClient(15440): getSkuDetails() failed. Response code: 2
W/BillingClient(15440): getSkuDetails() failed. Response code: 2

根据下面的链接,这Response code: 2意味着网络连接已断开或BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE.

https://developer.android.com/google/play/billing/billing_reference

据我所知,我的网络连接工作正常。如果有人能指出此错误的可能原因和解决方案,将不胜感激。

下面是我的代码:

import 'package:flutter/material.dart';
import 'package:in_app_purchase/in_app_purchase.dart';

const Set<String> _kProductIds = <String>{
  'item_id',
};

class InAppItems with ChangeNotifier {
  final InAppPurchase _inAppPurchase = InAppPurchase.instance;

  InAppItems() {
    setup();
  }

  void setup() async {
    initStoreInfo();
  }

  Future<void> initStoreInfo() async {
    final bool isAvailable = await _inAppPurchase.isAvailable();
    if (!isAvailable) {
      print('Store is not available!');
      return;
    }
    print('Store is available!');

    ProductDetailsResponse productDetailResponse = await _inAppPurchase.queryProductDetails(_kProductIds); // The failure occurs here

    print('productDetailResponse error: ${productDetailResponse.error}');
    print('product details is empty: ${productDetailResponse.productDetails.isEmpty}');
    // other operations...
  }
}

围绕错误的日志如下所示:

I/flutter (15440): Store is available!
W/BillingClient(15440): getSkuDetails() failed. Response code: 2
W/BillingClient(15440): getSkuDetails() failed. Response code: 2
I/flutter (15440): productDetailResponse error: null
I/flutter (15440): product details is empty: true

如果需要更多信息,请告诉我。

标签: androidflutterin-app-purchase

解决方案


推荐阅读