Google 玩游戏服务和 Google 驱动器 API 已弃用

Google Play Game Service and Google drive API deprecated

我正在为 Godot Engine 开发一个模块,它叫做 godot-android。您可以找到 this module here。此模块通过 SnapshotClient 使用 Google 驱动器 API 将游戏保存在 google 驱动器上。

由于我将此模块用于我今年早些时候发布的 android 游戏之一,我收到了一封来自 google 的电子邮件,内容是 Google Drive Android API 说我的应用程序正在使用 google 驱动器已弃用 API.

所以,我又开始阅读 Google Play Games Services documentation for android, but they did not update their documentation. Then, after several hours spent on /github migration guide 以了解如何迁移 SnapshotClient,但我碰壁了。

我的第一步是将我的模块的所有依赖项升级到最新版本,编译并查看有什么问题:

  com.google.firebase:firebase-core:16.0.6
  com.google.firebase:firebase-auth:16.1.0
  com.google.firebase:firebase-invites:16.0.6
  com.google.firebase:firebase-messaging:17.3.4
  com.google.firebase:firebase-appindexing:17.1.0
  com.google.android.gms:play-services-auth:16.0.1
  com.google.android.gms:play-services-games:16.0.0
  com.google.android.gms:play-services-drive:16.0.0
  com.google.apis:google-api-services-drive:v3-rev136-1.25.0

我很高兴看到一切正常。第 2 步,更改用于访问 google 驱动器的代码 API:

  public GoogleAuthentication(Activity p_activity) {
    activity = p_activity;

    String webclientId = activity.getString(R.string.default_web_client_id);
    GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
    .requestIdToken(webclientId)
    // Since we are using SavedGames, we need to add the SCOPE_APPFOLDER to access Google Drive.
    .requestScopes(new Scope(DriveScopes.DRIVE))
    .requestScopes(new Scope(DriveScopes.DRIVE_FILE))
    .requestScopes(new Scope(DriveScopes.DRIVE_APPDATA))
    .build();

    mGoogleApiClient = new GoogleApiClient.Builder(activity)
    .addApi(Games.API)
    .addScope(Games.SCOPE_GAMES)
    .addApi(Auth.GOOGLE_SIGN_IN_API, options)
    .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
    .setViewForPopups(activity.getWindow().getDecorView().findViewById(android.R.id.content))
    .build();

    mAuth = FirebaseAuth.getInstance();
  }

所以,游戏开始了,我有一个登录弹出窗口要求范围(正确的范围),我点击授权,然后我无法访问我的游戏存档。亚行 logcat:

    E/Parcel  (  820): Class not found when unmarshalling: com.google.android.gms.common.api.Scope
    E/Parcel  (  820): java.lang.ClassNotFoundException: com.google.android.gms.common.api.Scope
    E/Parcel  (  820): Class not found when unmarshalling: com.google.android.gms.auth.firstparty.shared.ScopeData
    E/Parcel  (  820): java.lang.ClassNotFoundException: com.google.android.gms.auth.firstparty.shared.ScopeData
    E/Parcel  (  820): Class not found when unmarshalling: com.google.android.gms.auth.api.signin.internal.SignInConfiguration
    E/Parcel  (  820): java.lang.ClassNotFoundException: com.google.android.gms.auth.api.signin.internal.SignInConfiguration
    E/Parcel  (  820):  at java.lang.Class.classForName(Native Method)
    E/Parcel  (  820):  at java.lang.Class.forName(Class.java:251)
    E/Parcel  (  820):  at java.lang.Class.forName(Class.java:216)
    E/Parcel  (  820):  at android.os.Parcel.readParcelableCreator(Parcel.java:2140)
    E/Parcel  (  820):  at android.os.Parcel.readParcelable(Parcel.java:2104)
    E/Parcel  (  820):  at android.os.Parcel.readValue(Parcel.java:2020)
    E/Parcel  (  820):  at android.os.Parcel.readArrayMapInternal(Parcel.java:2321)
    E/Parcel  (  820):  at android.os.Bundle.unparcel(Bundle.java:249)
    E/Parcel  (  820):  at android.os.Bundle.getString(Bundle.java:1118)
    E/Parcel  (  820):  at android.content.Intent.getStringExtra(Intent.java:5261)
    E/Parcel  (  820):  at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1591)
    E/Parcel  (  820):  at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1169)
    E/Parcel  (  820):  at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4359)
    E/Parcel  (  820):  at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4241)
    E/Parcel  (  820):  at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:164)
    E/Parcel  (  820):  at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2878)
    E/Parcel  (  820):  at android.os.Binder.execTransact(Binder.java:404)
    E/Parcel  (  820):  at dalvik.system.NativeStart.run(Native Method)
    E/Parcel  (  820): Caused by: java.lang.NoClassDefFoundError: com/google/android/gms/auth/api/signin/internal/SignInConfiguration
    E/Parcel  (  820):  ... 18 more
    E/Parcel  (  820): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.signin.internal.SignInConfiguration" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

找到根本问题,范围不正确:

public GoogleAuthentication(Activity p_activity) {
activity = p_activity;

String webclientId = activity.getString(R.string.default_web_client_id);
GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestIdToken(webclientId)
// Since we are using SavedGames, we need to add the SCOPE_APPFOLDER to access Google Drive.
.requestScopes(new Scope(DriveScopes.DRIVE_FILE))
.requestScopes(new Scope(DriveScopes.DRIVE_APPDATA))
.build();

mGoogleApiClient = new GoogleApiClient.Builder(activity)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addApi(Auth.GOOGLE_SIGN_IN_API, options)
.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
.setViewForPopups(activity.getWindow().getDecorView().findViewById(android.R.id.content))
.build();

mAuth = FirebaseAuth.getInstance();
}

这段代码效果很好,我更新了github模块,你可以看看at the commit