首页 > 解决方案 > 如何从 Android 应用登录 Google Play 游戏(错误 8)

问题描述

我正在尝试将保存游戏的 Google Play 游戏云服务添加到现有的 android 应用程序,但出现错误 8。

在 android guideCollect all the stars 2 sample app中使用了保存的游戏支持。

这是我到目前为止所尝试的:

控制台和安全设置

在游戏服务中创建游戏。已保存的游戏已打开,所有其他功能均已关闭。

使用“链接的应用程序”并使用调试 SHA1 指纹链接。

上面在 Google API 控制台中验证,所有在控制台中签出并匹配 SHA1 十六进制字符串并使用 keytool。

keytool -list -keystore "C:\Users\dejan\.android\debug.keystore" -storepass android

将自己添加为测试人员,并为所有环境启用测试。

SDK 管理器

在 Android Studio 中,使用 SDK 工具添加“Google Play 服务”

安卓清单

在 android 清单中添加了以下内容:

   <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"/>

在 Android 主活动中

添加

private static final int RC_SIGN_IN = 9001;
private GoogleSignInClient mGoogleSignInClient;
// The currently signed in account, used to check the account has changed outside of this activity when resuming.
private GoogleSignInAccount mSignedInAccount = null;

在 OnCreated 方法中添加:

   //initialize google play games
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
                // Since we are using SavedGames, we need to add the SCOPE_APPFOLDER to access Google Drive.
                .requestScopes(Drive.SCOPE_APPFOLDER)
                .build();
        mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

对于按钮单击添加:

startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);

最后,添加了onActivityResult

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (requestCode == RC_SIGN_IN) {

        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent);

        try {
            GoogleSignInAccount account = task.getResult(ApiException.class);
            onConnected(account);
        } catch (ApiException apiException) {
            String message = String.format("%s (%s)", getString(R.string.signin_other_error), apiException.getStatusCode());
            mGoogleSignInError = true;
            Snackbar snackbar = Snackbar.make(findViewById(R.id.mainContainerMenu), message, Snackbar.LENGTH_LONG);
            snackbar.show();

            onDisconnected();


        }
    }

    super.onActivityResult(requestCode, resultCode, intent);

}

测试

我尝试将应用程序从 Android Studio 运行到我以测试授权用户身份登录的物理设备。

此外,尝试通过 Android Studio 制作签名的 apk 并使用 adb 命令将其部署到设备。构建 apk 时,使用了调试密钥存储和密钥。

在这两种情况下,我都会收到错误 #8。Google Play 启动画面未显示,屏幕只是变暗一秒钟,然后我收到错误消息。

日志猫

2019-02-26 18:01:00.946 4892-7664/? E/Volley:[131] BasicNetwork.performRequest: https://www.googleapis.com/drive/v2beta/apps/self? prettyPrint=false&fields= id 的意外响应代码 404

2019-02-26 16:15:29.365 1517-18694/? I/ActivityManager:启动 u0 {act=com.google.android.gms.auth.GOOGLE_SIGN_IN pkg=com.google.android.gms cmp=com.google.android.gms/.auth.api.signin.ui.SignInActivity (有额外的)} 来自 uid 10351 显示 0

2019-02-26 16:15:29.378 1517-31079/? E/ActivityManager:从系统 4525 发送不受保护的广播 com.motorola.motocare.INTENT_TRIGGER:com.motorola.process.system/1000 pkg com.motorola.motgeofencesvc java.lang.Throwable at com.android.server.am.ActivityManagerService com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18826) 在 com.android.server 的 android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:512) 的 .broadcastIntentLocked(ActivityManagerService.java:18226)。 am.ActivityManagerService.onTransact(ActivityManagerService.java:2906) 在 android.os.Binder.execTransact(Binder.java:565)

我是否缺少清单中的某些权限?任何帮助表示赞赏。

标签: javaandroidgoogle-play-games

解决方案


推荐阅读