首页 > 其他分享 >Google Game Service 接入指南

Google Game Service 接入指南

时间:2022-11-04 22:11:12浏览次数:77  
标签:case Google return Service int final Game static public


前言

应用接入Game 登录,接入过程中遇到各种卡流程的问题,首次接入Game v2,发现Game v2版本的调用时机
无法自行控制,并且不能退出当前登录的账户。而旧版game v1的api提供了退出接口,sdk初始化也可以自由控制。
后面集成改为game v1.

官方文档入口:​​https://developer.android.google.cn/games/pgs/signin?hl=zh-cn​

1.接入环境

sdk版本:play-services-games-v1

接入文档:​​https://developers.google.cn/games/services/common/concepts/v1/sign-in?hl=zh-cn​

sdk版本:play-services-games-v2
接入文档:​​​https://developer.android.google.cn/games/preview/multiplatform/pgs-java-integration-guide?hl=zh-cn​

注意事项:

  1. 需要将待测试的未发布apk,上传到 ​​GoogleConsole​​ 测试轨道中
  2. 添加轨道测试人员邮箱,发送内测链接给测试人员
  3. 在Google Play 游戏服务-设置和管理-测试用户数量选项下,添加测试人员邮箱(Google play 账户邮箱)。[email protected]
  4. 按照 ​​官方文档​​,依次完成Play 游戏服务配置选项,如下图红框入口中。最后将Google Clould platform内创建的凭据,添加到凭据-Android 下。

Google Game Service 接入指南_android


Google Game Service 接入指南_测试人员_02

完成上面的配置就可以构建app进行Google Game登录测试了. ​​接入文档​

Games-v2对外提供的Api,只有登录signIn没有Logout,​​早期V1版本官方demo​​ 是有Logout功能。

Tips:

  1. 在Google play商店,下载​​Google play 游戏​​​。进入Google play 游戏的玩家资料里面–>设置里,进行账户管理。
    包括但不限于,更改游戏账号,退出当前登录账号,移除当前账号存档。

QA

Q.Game v2 如果无法调起 Game Service 弹窗,如何快速定位问题?
答:

  1. 将设备连接到安装了 Android SDK 的机器。
  2. 打开终端并运行以下命令:

adb shell setprop log.tag.Games VERBOSE

  1. 在设备上运行您的游戏并重现您尝试调试的问题。
  2. 查看日志:

adb logcat

会打印如下日志:

2022-10-10 17:15:10.628 11335-11335 PlayGamesS...enticator] com.codeview.miniparty               D  startWatching()
2022-10-10 17:15:11.072 11335-11335 PlayGamesS...enticator] com.codeview.miniparty D Automatic connection attempt triggered
2022-10-10 17:15:11.072 11335-11335 PlayGamesS...piManager] com.codeview.miniparty D startAuthenticationIfNecessary() signInType: 1
2022-10-10 17:15:11.073 11335-11335 PlayGamesS...piManager] com.codeview.miniparty D Attempting authentication: zzy{signInType=1, previousStepResolutionResult=null}
2022-10-10 17:15:11.871 11335-11335 PlayGamesS...piManager] com.codeview.miniparty D Successfully authenticated
2022-10-10 17:15:11.874 11335-11335 PlayGamesS...upManager] com.codeview.miniparty V Binding to: com.codeview.skycastle.ui.game.GameMainActivity@b00323d

Q:Game v2 如何禁用Game service Log日志?
答:

adb shell setprop log.tag.Games INFO

Q:清单文件中配置的是Oauth 2.0 web Client id,为什么不使用Android client Id ?
答:
这是使用web Client id,是为了登录google paly 同时,获取到service token。如果不需要获取service token,则不需要配置。

错误集合

1. ApiException = “12500”

Google Game Service 接入指南_Google Game_03

2. ApiException = “12501”

Google Game Service 接入指南_Google Game_04


如上图,异常code=12501表示用户主动取消或者sdk内部异常无法调起Game账户界面,具体逻辑可以查看依赖com.google.android.gms:play-services-auth包中的com.google.android.gms.auth.api.signin.internal.SignInHubActivity文件。

Google Game Service 接入指南_android_05


尝试解决方案

1.部分Redmi手机有12501情况,同时系统log中发现,有 一行play.games的异常

2022-10-23 12:18:14.271   PGASignInActivity       com.google.android.play.games        E  Non-first-party calling package [com.google.android.gms] attempting to use a different game package [com.xx.xxx]

手动检查系统是否有关于google service的补丁需要升级,升级补丁之后问题解决

2.发现个别机型google service 版本过旧,更新google service之后,正常调起了

3. apiException4:4

3.1 如果出现apiException = 4这种情况,检查下配置信息,本文结尾会附上检查清单。有一个例外情况就是访问的Scope未在Google Clould platform,凭据中声明,导致权限不足。
3.2 如果登录时,开启requestServerAuthCode的强制刷新,也会返回 apiException4:4

private val signInOptions =
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestScopes(Drive.SCOPE_APPFOLDER)
.requestServerAuthCode(
Utils.getApp().getString(R.string.game_services_web_client_id),true
).build()
4. 系统公共状态码
4.1 GoogleSignInStatusCodes
public final class GoogleSignInStatusCodes extends CommonStatusCodes {
public static final int SIGN_IN_FAILED = 12500;
public static final int SIGN_IN_CANCELLED = 12501;
public static final int SIGN_IN_CURRENTLY_IN_PROGRESS = 12502;

@NonNull
public static String getStatusCodeString(int statusCode) {
switch (statusCode) {
case 12500:
return "A non-recoverable sign in failure occurred";
case 12501:
return "Sign in action cancelled";
case 12502:
return "Sign-in in progress";
default:
return CommonStatusCodes.getStatusCodeString(statusCode);
}
}

private GoogleSignInStatusCodes() {
}
}
4.2 CommonStatusCodes
public class CommonStatusCodes {
public static final int SUCCESS_CACHE = -1;
public static final int SUCCESS = 0;
/** @deprecated */
@Deprecated
public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
/** @deprecated */
@Deprecated
public static final int SERVICE_DISABLED = 3;
public static final int SIGN_IN_REQUIRED = 4;
public static final int INVALID_ACCOUNT = 5;
public static final int RESOLUTION_REQUIRED = 6;
public static final int NETWORK_ERROR = 7;
public static final int INTERNAL_ERROR = 8;
public static final int DEVELOPER_ERROR = 10;
public static final int ERROR = 13;
public static final int INTERRUPTED = 14;
public static final int TIMEOUT = 15;
public static final int CANCELED = 16;
public static final int API_NOT_CONNECTED = 17;

@NonNull
public static String getStatusCodeString(int var0) {
switch (var0) {
case -1:
return "SUCCESS_CACHE";
case 0:
return "SUCCESS";
case 1:
case 9:
case 11:
case 12:
default:
return (new StringBuilder(32)).append("unknown status code: ").append(var0).toString();
case 2:
return "SERVICE_VERSION_UPDATE_REQUIRED";
case 3:
return "SERVICE_DISABLED";
case 4:
return "SIGN_IN_REQUIRED";
case 5:
return "INVALID_ACCOUNT";
case 6:
return "RESOLUTION_REQUIRED";
case 7:
return "NETWORK_ERROR";
case 8:
return "INTERNAL_ERROR";
case 10:
return "DEVELOPER_ERROR";
case 13:
return "ERROR";
case 14:
return "INTERRUPTED";
case 15:
return "TIMEOUT";
case 16:
return "CANCELED";
case 17:
return "API_NOT_CONNECTED";
case 18:
return "DEAD_CLIENT";
}
}

@KeepForSdk
protected CommonStatusCodes() {
}
}

Game无法登录自检清单

  1. 是否接受测试邀请链接
  2. 是否是内测测试人员
  3. 当前登录google 邮箱,是否已加入游戏测试人员列表
  4. 是否已经安装了google服务,服务框架
  5. 检查Google console 创建的游戏项目的游戏id,ClientId,是否在清单文件中声明了,是否正确
<string name="game_services_project_id" translatable="false">xxxxxxxx</string>
<string name="game_services_web_client_id" translatable="false">xxxxxxx-vvvvvvvvvvvvli762078r.apps.googleusercontent.com</string>
  1. 调用Game 登录时是否开启了auth Token强制刷新,会报apiException=4:4异常
上线前注意

如果线上apk、aab使用google 签名。本地使用自签名。那么通过google play下载的应用就无法使用Game Service 登录,原因就是签名问题。

解决:新建一个对应线上签名sha1的凭据。然后在游戏配置,选择刚新建的线上使用的凭据。就可以正常调用了

Google Game Service 接入指南_测试人员_06

总结:

接入google Game 登录,前期主要是配置问题,配置正常之后调试阶段需要做一些错误兼容。具体接入Game v1 还是Game v2主要看需求了。(v1,v2指的是sdk的版本)。v1版本可以自己控制何时初始化,退出。v2接入更简单,但是失去了灵活性,未提供退出方法。初始化时机,默认使用ContentProvider进行初始化。v2部分机型,错误时缺少必要的回调,会卡正常的 流程。

引用地址

​1.排查 Android 游戏中与 Play 游戏服务相关的问题​​​​2.调试log输出​​​​3.apiException4:4​​​​4. Google Services Framework​​​​5. Google Play Service​​​​6. Google Play Store​


标签:case,Google,return,Service,int,final,Game,static,public
From: https://blog.51cto.com/u_15861646/5824776

相关文章