集成应用内订阅时出现“D/GoogleBillingService: buy. Google billing service is not ready yet.”错误求助
解决Google Billing Service未就绪的错误
针对你遇到的"D/GoogleBillingService: buy. Google billing service is not ready yet."错误,以下是几个关键排查方向:
检查BillingClient的初始化流程
必须确保BillingClient完成连接后再发起购买请求。正确的流程是:- 初始化BillingClient实例并设置
BillingClientStateListener - 调用
startConnection()触发服务连接 - 在
onBillingSetupFinished回调中,确认responseCode为BillingResponseCode.OK后,再执行查询商品、发起购买等操作
示例代码片段:
val billingClient = BillingClient.newBuilder(context) .setListener(purchasesUpdatedListener) .enablePendingPurchases() .build() billingClient.startConnection(object : BillingClientStateListener { override fun onBillingSetupFinished(billingResult: BillingResult) { if (billingResult.responseCode == BillingResponseCode.OK) { // 服务已就绪,可执行购买/查询操作 querySkuDetails() } } override fun onBillingServiceDisconnected() { // 断开连接后重新尝试连接 billingClient.startConnection(this) } })- 初始化BillingClient实例并设置
验证Google Play服务版本
Google Billing Library对设备上的Play服务版本有最低要求(例如Billing Library 5.x需要Play服务19.0.0及以上)。前往设备的Google Play商店,检查并更新Google Play服务到最新版本;如果使用模拟器,确保选择包含完整Google Play服务的系统镜像。确认测试环境配置
- 确保在Google Play控制台的「测试」页面添加了你的测试账号,且测试设备登录的是该账号
- 检查控制台中订阅产品的状态为「激活」,且应用内使用的产品ID与控制台中的完全一致(注意大小写、拼写)
检查应用签名与权限
- 测试APK的签名必须与Google Play控制台中配置的签名一致:如果使用debug包,需将debug keystore的SHA1指纹添加到控制台的应用签名设置中
- 确保AndroidManifest.xml中添加了必要权限:
<uses-permission android:name="com.android.vending.BILLING" />
处理服务断开重连
BillingClient可能因系统原因断开连接,需在onBillingServiceDisconnected回调中主动调用startConnection()重新建立连接,避免后续操作时服务未就绪。
内容的提问来源于stack exchange,提问作者Budding Developer
相关产品推荐
相关产品推荐

