所有免安装游戏都必须支持使用 Google Play 游戏服务自动登录。使用 Google Play 游戏服务可确保用户能够无缝登录,并可提供一致的玩家 ID,供您从云端恢复保存的游戏进度。
库对应用程序大小的影响
Google Play 游戏服务库对应用程序大小的影响取决于游戏引擎的运行环境是 Java、Native 或 Unity。
Java
ProGuard 可以很好地了解实际使用了哪些类,因此几乎不会影响应用程序的大小。
Unity
如果您想将游戏存档集成到 Unity 游戏中,可以使用官方 Google Play 游戏服务插件。 如果采用 ProGuard 建议,则对应用程序大小的影响微乎其微,约为 200kb。
Native
如果您想将游戏存档集成到用 NDK 构建的游戏中,请使用 Native Play 游戏服务 SDK。
使用下面的常规 ProGuard 配置可删除该库所包含的大多数 Java 代码。使用此配置,您可以实现 Play 游戏服务登录和游戏存档功能,而 APK 大小仅需增加约 250KB。
# 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 *;
}