为什么我在连接 BillingClient 时收到 DEVELOPER_ERROR 响应代码?

Why am I getting DEVELOPER_ERROR response code when connecting my BillingClient?

/**
 * Invalid arguments provided to the API. This error can also indicate that the application was
 * not correctly signed or properly set up for In-app Billing in Google Play, or does not have
 * the necessary permissions in its manifest
 */
int DEVELOPER_ERROR = 5;

我正在使用 Google Play Signing - 所以我上传 App Bundle 以供发布。我想知道这是否会以某种方式相关? (因为 Google Play 在后端使用自己的签名密钥而不是本地密钥)

我在我的清单中拥有 com.android.vending.BILLING 权限,并且我能够成功地使用 "test cards" 进行调试构建。我只是通过记录失败事件的 Bugsnag 报告才注意到这个问题。

有人知道为什么会这样吗?

在 Google Cloud Console 中,您需要配置 API 凭据以将您的程序包名称和证书列入白名单。该证书是在 Play 管理中心的 "App Signing" 页面中列为 "App Signing certificate" 的证书。

Modded/tampered APK 将由于不同的签名而触发此错误。

我在使用 BillingClient.queryPurchasesAsnyc() 时遇到了同样的错误,我得到了一个空的 BillingResult 调试消息和 DEVELOPER_ERROR 作为 ResponseCode。

原来我将 BillingClient.FeatureType.SUBSCRIPTION 而不是 BillingClient.SkuType.SUBS 传递给了 documentation 中指定的函数。

所以一定要仔细检查你的函数参数

billingClient.startConnection() is performed multiple times in a short period of time, the value of billingResult.responseCode becomes DEVELOPER_ERROR.