Can't sign in Goolge Play Game Services: Must have a game ID to sign in

雨燕双飞 提交于 2020-06-27 12:43:30

问题


I am trying to integrate Google Play Game Services but can't sign in. I know some developers ask about this problem before but the problem is nobody asked about the error I am encountering.

The log is this.

Must have a game ID to sign in!

Status{statusCode=unknown status code: 12501, resolution=null}

Invalid (empty) game ID found in the EXTRA_GAME_ID extra.

I was just following the tutorial on the official doc. What is the cause of this error possibly? Seems like no one asked about this error and it's weird. Everyone got some status code but mine is just unknown Anyone have encountered this error?

Code

Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="...">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:roundIcon="@mipmap/ic_launcher"
    android:theme="@style/AppTheme">

    <meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>
    ...

Activity

private void startSignInIntent() {
    GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
            GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // The signed in account is stored in the result.
            GoogleSignInAccount signedInAccount = result.getSignInAccount();
        } else {
            String message = result.getStatus().getStatusMessage();
            if (message == null || message.isEmpty()) {
                Log.e("e", result.getStatus());
                message = "Something wrong happened. Please try again.";
            }
            new AlertDialog.Builder(this, R.style.CustomAlertDialogTheme).setMessage(message)
                    .setNeutralButton(android.R.string.ok, null).show();
        }
    }
}

res/values/ids.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="app_id" type="string">digits here...</item>
</resources>

I am sure I linked my app to Play Game Services. I added myself to tester on Play Console (Game Services section as well as Release management). I tried with both actual device and emulator. I didn't create OAuth2 client ID manually on API Console. I created it from Play Console. SHA-1 is correct (If this is incorrect I am supposed to get other error message.) Never worked.


回答1:


I came across problem with same output - I downgraded version of com.google.android.gms:play-services-(base/games/auth) to 16.0.0 and got better error log:

019-10-24 11:52:03.266 25880-12410/? E/ValidateServiceOp: ****
**** APP ID IS NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES
**** Specify it using @string resources value or \u003 followed by an app_id value.
**** For example:
****   meta-data android:name="com.google.android.gms.games.APP_ID"
****             android:value="@string/app_id" />
**** or
****   meta-data android:name="com.google.android.gms.games.APP_ID"
****             android:value="\u003123456789" />

My manifest was like this:

android:name="com.google.android.gms.games.APP_ID"
****             android:value="3123456789" />

I had missing \u003 symbol. After replacing this with @string/app_id and putting value to strings.xml it started working. You added this string to ids.xml, which may be wrong.

After doing that I upgraded version of Google Play Services and everything works!



来源:https://stackoverflow.com/questions/57535377/cant-sign-in-goolge-play-game-services-must-have-a-game-id-to-sign-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!