支援 Google Play 遊戲服務

所有免安裝遊戲都必須支援使用 Google Play 遊戲服務自動登入的功能。使用 Google Play 遊戲服務提供一致的玩家 ID,以便從雲端還原已儲存的進度。

程式庫大小影響

Google Play 遊戲服務程式庫的大小影響取決於遊戲引擎是在 Unity、Java 或 Native 中執行。

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 *;
}