You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GoogleSignInClient仅在应用从谷歌商店安装时可正常连接

Troubleshooting Google Play Game Services Login Issues in Local Development

Hey there! It sounds like you're stuck in that super common, frustrating spot—your login works flawlessly when deployed to Google Play's internal test track, but you're hitting walls during local development. Let's break down why this happens and how to fix it:

1. Mismatched Signing Keys

This is the #1 culprit here. When you upload your app to Google Play's internal test track, Google re-signs it with their own official signing key. But when you run the app directly from Android Studio, you're using your local debug keystore (or a custom debug key you set up). These two keys have different SHA-1 fingerprints, and Google Play Game Services only allows access from apps with registered, trusted fingerprints.

Fix:

  • Grab the SHA-1 fingerprint of your debug keystore using this command:
    # For macOS/Linux
    keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
    
    # For Windows
    keytool -list -v -keystore C:\Users\<YourUsername>\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android
    
  • Head to your Google Cloud Console project, find the OAuth 2.0 client ID tied to your game, and add this debug SHA-1 fingerprint to it.

2. Outdated or Misconfigured google-services.json

If you only downloaded your google-services.json after setting up your release signing key, it won't include the debug client ID needed for local testing. This file needs to cover all signing configurations you use.

Fix:

  • Re-download the google-services.json from Google Cloud Console (it will automatically include all registered fingerprints) and replace the one in your project's app/ directory.
  • Double-check that your AndroidManifest.xml has the correct APP_ID meta-data:
    <meta-data
        android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />
    
    The app_id string must match the exact ID listed in your Google Play Console game project.

3. Test Account Permissions

Even if your test account is added to the internal test track, it might not have access to your game's OAuth setup if you're using an "External" consent screen (the default for most projects).

Fix:

  • In Google Cloud Console, navigate to the OAuth consent screen section and add your test account as a "Test user". This bypasses the app verification process for local testing.
  • Confirm the same account is listed in your Google Play Console's internal test track tester list.

4. Switch to the Modern Activity Result API

While you mentioned the deprecated startActivityForResult works in the test track, it can cause inconsistent callback behavior in local development (especially with newer Android SDK versions). Upgrading to the ActivityResultContracts API might resolve hidden issues.

Example Code:

// Register the launcher in your Activity/Fragment
private val signInLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
    if (result.resultCode == Activity.RESULT_OK) {
        val signInTask = GoogleSignIn.getSignedInAccountFromIntent(result.data)
        handleSignInResult(signInTask)
    }
}

// Trigger sign-in
fun launchSignIn() {
    val signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
    val signInClient = GoogleSignIn.getClient(this, signInOptions)
    signInLauncher.launch(signInClient.signInIntent)
}

5. Check Logcat for Specific Errors

Don't overlook Logcat! When your local login fails, filter logs for keywords like GoogleSignIn, Games, or SIGN_IN_FAILED. You'll often get specific error codes (like INVALID_CLIENT for fingerprint mismatches) that point directly to the root problem.

Since your test track build works perfectly, your core setup is solid—this is almost definitely a local environment mismatch. Work through these steps one by one, and you should have your local login up and running in no time.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:03:06