You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Flutter应用Alpha版本上架Play Store后IAP功能无法正常使用求助

Troubleshooting Flutter IAP Failure in Play Store Alpha (BillingClient Connection Issue)

Hey, let's dig into this IAP problem you're hitting with your Flutter app's Alpha release. That "Client is already in the process of connecting to billing service" log is a common clue, so here are actionable steps to fix it:

1. Fix Duplicate BillingClient Connections

That log message usually means your code is trying to initialize or connect the BillingClient multiple times—something that might not surface in local testing but triggers in the Play-signed build.

  • Implement a Singleton BillingClient: Wrap your BillingClient instance in a singleton class or use a state management solution (like Provider, Riverpod) to ensure only one instance exists across your app. Avoid creating new instances in initState of multiple widgets.
  • Check Connection Flow: Make sure you're not calling startConnection() again before the previous connection attempt completes. For example, don't trigger a reconnection inside onBillingSetupFinished unless you explicitly handle failure cases properly.

2. Verify App Bundle Signing & Permissions

Even if you're using your existing upload key, Play Store's App Signing can sometimes introduce subtle issues, and permissions might get stripped during build:

  • Confirm BILLING Permission: Double-check that <uses-permission android:name="com.android.vending.BILLING" /> is present in your AndroidManifest.xml, and not nested inside a <application> tag (it should be at the root level). You can verify the final APK's permissions by downloading the Alpha build and running:
    aapt dump permissions path/to/your/apk/file.apk
    
  • Validate Play App Signing: Ensure your upload key is correctly linked to Play App Signing in the Play Console. Since you've published previous versions, this is likely okay, but it's worth confirming no changes were accidentally made.

3. Rule Out Testing Environment Issues

Sometimes the problem isn't code-related but how your test users are accessing the Alpha build:

  • Confirm Test Account Setup: Make sure your licensed testers are properly added in the Play Console's "Licensing testing" section, and they're signed into the Play Store with that exact account.
  • Ensure Alpha Build Download: Testers need to opt into the Alpha test program (via the opt-in link you generated) and download the Alpha version directly from the Play Store. Old local builds or production versions won't work for IAP testing.

4. Add ProGuard/R8 Exceptions

If you're using code shrinking (enabled by default in release builds), R8 might obfuscate or strip critical BillingClient classes, breaking IAP functionality:

Add these rules to your android/app/proguard-rules.pro file to preserve the necessary classes:

-keep class com.android.billingclient.api.** { *; }
-keep class com.google.android.gms.wallet.** { *; }

Rebuild your App Bundle and re-upload to Alpha after making this change.

5. Update the In-App Purchase Package

Outdated versions of the in_app_purchase package might have compatibility issues with newer BillingClient versions or Play Store backend changes:

Check your pubspec.yaml and upgrade in_app_purchase to the latest stable version, then run flutter pub get and rebuild your app bundle.

Start with the BillingClient singleton fix first—it's the most likely culprit here. If that doesn't resolve it, work through the other steps one by one.

内容的提问来源于stack exchange,提问作者SheikCode

火山引擎 最新活动