支持 Google Play 游戏服务

所有免安装游戏都必须支持自动 使用 Google Play 游戏服务登录。使用 Google Play 游戏服务提供一致的玩家 ID,您可以使用该 ID 从云端恢复已保存的游戏进度。

库的大小影响

Google Play 游戏服务库的大小影响取决于游戏引擎是运行在 Unity、Java 还是原生平台。

Java

由于 ProGuard 已获知哪些类正在使用,因此大小影响极小。

Unity

您可以使用 官方 Google Play 游戏服务插件 将游戏保存功能集成到您的 Unity 游戏中。如果您使用 ProGuard 推荐配置,大小影响约为 200 KB。

原生

您可以使用 原生 Play 游戏服务 SDK 将游戏保存功能与基于 Android NDK 构建的游戏集成。

使用以下通用 ProGuard 配置来剥离库中包含的大部分 Java 代码。通过此配置,您可以实现 Play 游戏服务登录和游戏保存功能,同时仅向 APK 添加约 250 KB。

# The native PGS library wraps the Java PGS SDK using reflection.
-dontobfuscate
-keeppackagenames

# Needed for callbacks.
-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

# Needed for helper libraries.
-keep class com.google.example.games.juihelper.** {
  public protected *;
}
-keep class com.sample.helper.** {
  public protected *;
}

# Needed for GoogleApiClient and auth stuff.
-keep class com.google.android.gms.common.api.** {
  public protected *;
}

# Keep all of the "nearby" library, which is needed by the native PGS library
# at runtime (though deprecated).
-keep class com.google.android.gms.nearby.** {
  public protected *;
}

# Keep all of the public PGS APIs.
-keep class com.google.android.gms.games.** {
  public protected *;
}