支持 Google Play 游戏服务

所有免安装 Play 游戏都必须支持使用 Google Play 游戏服务自动登录。使用 Google Play 游戏服务提供一致的玩家 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 *;
}