Bu belgede, mevcut oyunların games v1 SDK'sından games v2 SDK'sına nasıl taşınacağı açıklanmaktadır.
Başlamadan önce
Oyununuzu taşımak için Android Studio gibi tercih ettiğiniz herhangi bir IDE'yi kullanabilirsiniz. Games v2'ye geçiş yapmadan önce aşağıdaki adımları tamamlayın:
- Android Studio'yu indirme ve yükleme
- Oyununuzda games v1 SDK'sı kullanılmalıdır.
- Oyununuzu, games v1 SDK'sını kullanacak şekilde yükselterek
com.google.android.gms:play-services-games:24.0.0. Games v1 API kaldırıldığı içincom.google.android.gms:play-services-games:25.0.0sürümüne yükseltme yapmamanız gerekir.
Bağımlılıkları güncelleme
Modülünüzün
build.gradledosyasında, modül düzeyindeki bağımlılıklarda bu satırı bulun.implementation "com.google.android.gms:play-services-games:+"Aşağıdaki kodla değiştirin:
implementation "com.google.android.gms:play-services-games-v2:version"version yerine Games SDK'nın en yeni sürümünü kullanın.
Bağımlılıkları güncelledikten sonra bu belgedeki tüm adımları tamamladığınızdan emin olun.
Proje kimliğini tanımlama
Play Games Hizmetleri SDK'sı proje kimliğini uygulamanıza eklemek için aşağıdaki adımları tamamlayın:
AndroidManifest.xmldosyasında,<application>öğesine aşağıdaki<meta-data>öğesini ve özelliklerini ekleyin:<manifest> <application> <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/game_services_project_id"/> </application> </manifest>Oyununuzun Oyun Hizmetleri proje kimliğini değer olarak kullanarak dize kaynağı referansını
@string/game_services_project_idtanımlayın. Google Play Games Hizmetleri proje kimliğinizi, Google Play Console'daki Yapılandırma sayfasında oyun adınızın altında bulabilirsiniz.res/values/strings.xmldosyasında bir dize kaynağı referansı ekleyin ve proje kimliğinizi değer olarak ayarlayın. Örneğin:<!-- res/values/strings.xml --> <resources> <!-- Replace 0000000000 with your game's project id. Example value shown above. --> <string translatable="false" name="game_services_project_id"> 0000000000 </string> </resources>
Taşıma yolları
Oyununuz için doğru taşıma yolu, Google Play Games Hizmetleri v1'i nasıl uyguladığına ve oyuncu kimliğini nasıl işlediğine bağlıdır. Sorunsuz bir geçiş sağlamak ve oyuncu verilerinin kaybolmasını önlemek için mevcut kurulumunuza en uygun senaryoyu belirleyin ve ilgili adımları uygulayın.
1. seçenek: IGA'nın Google Play Games Hizmetleri oyuncu kimliğine bağlı olduğu oyunlar için
Bu senaryo, oyuncunun oyun içi hesabının (IGA) tek tanımlayıcısı olarak Google Play Games Hizmetleri'ni Player ID kullanan ve daha önce OpenID istememiş veya depolamamış oyunlar için geçerlidir. Buradaki asıl zorluk, mevcut IGA'yı oyuncunun ilerleme durumuyla bağlantısını kaybetmeden birincil tanımlayıcıya (OpenID) bağlamaktır.
Taşıma akışı aşağıdaki adımları içerir:
- Oyun başlatıldığında Google Play Games Hizmetleri v2 SDK'sı, platformun kimliğini otomatik ve sessiz bir şekilde doğrular.
Google Play düğmesinin yerine Google ile oturum aç düğmesi içeren bir giriş ekranı gösterin. Örneğin, CredManBridge.java dosyasına bakın.
CredManBridge.java
package com.wickedcube.trivialkart; import android.accounts.Account; import android.content.Context; import android.util.Log; import android.os.CancellationSignal; import androidx.credentials.CredentialManager; import androidx.credentials.GetCredentialRequest; import androidx.credentials.GetCredentialResponse; import androidx.credentials.exceptions.GetCredentialException; import androidx.credentials.exceptions.NoCredentialException; import com.google.android.libraries.identity.googleid.GetGoogleIdOption; import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential; import com.google.android.gms.auth.api.identity.AuthorizationClient; import com.google.android.gms.auth.api.identity.AuthorizationRequest; import com.google.android.gms.auth.api.identity.AuthorizationResult; import com.google.android.gms.common.api.ApiException; import com.google.android.gms.auth.api.identity.Identity; import com.google.android.gms.common.api.Scope; import com.unity3d.player.UnityPlayer; import java.util.Collections; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors;public class CredManBridge {
// --- MODE 1: SILENT SIGN-IN (Called on Awake) --- // Tries to auto-select an authorized account. If it fails, it does NOT show UI. public static void signInSilent(Context context, String webClientId) { CredentialManager credentialManager = CredentialManager.create(context); CancellationSignal cancellationSignal = new CancellationSignal(); Executor executor = Executors.newSingleThreadExecutor();
Log.d("CredMan", "Attempting Silent Sign-In..."); GetGoogleIdOption silentOption = new GetGoogleIdOption.Builder() .setFilterByAuthorizedAccounts(true) // Strict: Only authorized accounts .setServerClientId(webClientId) .setAutoSelectEnabled(true) // Auto-select if possible .build(); GetCredentialRequest silentRequest = new GetCredentialRequest.Builder() .addCredentialOption(silentOption) .build(); credentialManager.getCredentialAsync( context, silentRequest, cancellationSignal, executor, new androidx.credentials.CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() { @Override public void onResult(GetCredentialResponse result) { Log.d("CredMan", "Silent Sign-In Successful!"); handleSignInResult(context, result, webClientId); } @Override public void onError(GetCredentialException e) { // Send a specific error code so Unity knows to just stay on the Start Screen Log.d("CredMan", "Silent sign-in failed. Keeping UI hidden."); UnityPlayer.UnitySendMessage("AuthManager", "OnSignInError", "SilentFailed"); } } );}
// --- MODE 2: INTERACTIVE SIGN-IN (Called on Button Click) --- // Forces the Account Selection / "Add Account" sheet to appear. public static void signInInteractive(Context context, String webClientId) { CredentialManager credentialManager = CredentialManager.create(context); CancellationSignal cancellationSignal = new CancellationSignal(); Executor executor = Executors.newSingleThreadExecutor();
Log.d("CredMan", "Starting Interactive Sign-In..."); GetGoogleIdOption interactiveOption = new GetGoogleIdOption.Builder() .setFilterByAuthorizedAccounts(false) // Show ALL accounts (and "Add Account") .setServerClientId(webClientId) .setAutoSelectEnabled(false) // Force the UI to show .build(); GetCredentialRequest interactiveRequest = new GetCredentialRequest.Builder() .addCredentialOption(interactiveOption) .build(); credentialManager.getCredentialAsync( context, interactiveRequest, cancellationSignal, executor, new androidx.credentials.CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() { @Override public void onResult(GetCredentialResponse result) { Log.d("CredMan", "Interactive Sign-In Successful!"); handleSignInResult(context, result, webClientId); } @Override public void onError(GetCredentialException e) { Log.e("CredMan", "Interactive Sign-In Canceled or Failed", e); UnityPlayer.UnitySendMessage("AuthManager", "OnSignInError", "Canceled"); } } );}
private static void handleSignInResult(Context context, GetCredentialResponse result, String webClientId) { try { GoogleIdTokenCredential credential = GoogleIdTokenCredential.createFrom(result.getCredential().getData()); String email = credential.getId();
Account account = new Account(email, "com.google"); // Requesting GAMES_LITE scope to check for pre-existing V1 grants List<Scope> requestedScopes = Collections.singletonList(new Scope("https://www.googleapis.com/auth/games_lite")); AuthorizationRequest authRequest = new AuthorizationRequest.Builder() .setRequestedScopes(requestedScopes) .setAccount(account) .requestOfflineAccess(webClientId) .build(); AuthorizationClient authClient = Identity.getAuthorizationClient(context); authClient.authorize(authRequest) .addOnSuccessListener(authorizationResult -> { if (authorizationResult.getServerAuthCode() != null) { // CASE 1: RETURNING USER (Success) // The user has already granted GAMES_LITE in the past. // We got the code directly without showing UI. Log.i("CredMan", "PGS v1: Existing grant found. Returning user detected. Auth Code retrieved."); UnityPlayer.UnitySendMessage("AuthManager", "OnSignInSuccess", authorizationResult.getServerAuthCode()); } else if (authorizationResult.hasResolution()) { // CASE 2: NEW USER (PendingIntent) // The user has NOT granted GAMES_LITE before. The API returned a PendingIntent // (authorizationResult.getPendingIntent()) to show the consent screen. // As per your flow, we DISCARD this intent and do not show UI. Log.i("CredMan", "PGS v1: No existing grant (PendingIntent returned). This is a NEW user or they revoked access."); Log.i("CredMan", "PGS v1: Discarding PendingIntent. Proceeding as New User."); // Notify Unity that this is a "New User" so it can trigger V2 logic instead of failing UnityPlayer.UnitySendMessage("AuthManager", "OnSignInError", "NewUser_NoGrant"); } else { // Edge Case: No code and no resolution? Log.e("CredMan", "PGS v1: Authorization success but no Auth Code or Resolution returned."); UnityPlayer.UnitySendMessage("AuthManager", "OnSignInError", "No Auth Code returned"); } }) .addOnFailureListener(e -> { // CASE 3: GENERIC FAILURE Log.e("CredMan", "PGS v1: Authorization failed completely.", e); UnityPlayer.UnitySendMessage("AuthManager", "OnSignInError", "Authorization Failed: " + e.getMessage()); }); } catch (Exception e) { UnityPlayer.UnitySendMessage("AuthManager", "OnSignInError", "Parsing Error: " + e.getMessage()); }} }
Oyuncu, Google ile oturum aç düğmesine dokunup bir Google Hesabı seçtiğinde iki farklı tanımlayıcı alınır:
- IGA'yı bağlamak için birincil tanımlayıcı olan
OpenID. - Arka uç sisteminizde oyuncunun IGA'sını aramak ve bağlama işlemini gerçekleştirmek için
GAMES_LITEkapsamı kullanılarak alınan Google Play Games HizmetleriPlayer ID. Daha fazla bilgi içinPlayer IDalma başlıklı makaleyi inceleyin.
- IGA'yı bağlamak için birincil tanımlayıcı olan
Oyunların birincil tanımlayıcı olarak
Player IDkullanmasına gerek kalmadan, sonraki oyun başlatma işlemlerinde Google ile oturum açma akışı üzerinden IGA'ya erişin.
Player ID öğesini alma
3. adımı oyunun istemci tarafı uygulamasını kullanarak gerçekleştirebilirsiniz.
- Kullanıcının Google Hesabı ile oturum açmasını sağlamak için Android Credential Manager API'yi çağırın.
- Kullanıcı, Google ile oturum açma akışını tamamlayıp bir Google Hesabı seçtikten sonra kimlik jetonunu ve e-posta adresini içeren bir sonuç nesnesi alın.
- E-posta adresinden bir Account nesnesi oluşturun.
- Authorization API'yi
GAMES_LITEkapsamı ve hesapla çağırın. - Hesabın
GAMES_LITEkapsamı için önceden verilmiş bir izni varsa Authorization API, doğrudan yanıt nesnesinde bir jeton döndürür:- Google Play Games Hizmetleri sunucularını çağırmak ve Google Play Games Hizmetleri
Player IDdeğerini almak için yanıt jetonunu kullanın. - Google Play Games Hizmetleri'nin (
Player ID) bir oyun içi hesaba bağlı olup olmadığını doğrulayın.- Bu, Google Play Games Hizmetleri v1'den geri gelen bir kullanıcı olduğunu gösterir.
- Yeni Google Hesabı kimliğini önceki Google Play Games Hizmetleri v1 hesabına bağlayın.
- Google Play Games Hizmetleri sunucularını çağırmak ve Google Play Games Hizmetleri
- Hesabın
GAMES_LITEkapsamında önceden verilmiş bir izni yoksa Authorization API,PendingIntentdöndürür:- Bu, kullanıcının Google Play Games Hizmetleri 1. sürümde hesabı olmadığını gösterir.
- Kullanıcı arayüzü göstermeden
PendingIntentöğesini güvenli bir şekilde silin.
2. seçenek: IGA'yı OpenID'ye bağlayan oyunlar için
Bu gruptaki geliştiriciler en basit taşıma yoluna sahiptir. Oyununuzun oyun içi hesabı zaten OpenID'ye bağlıysa adımlarda belirtildiği gibi yalnızca v1'den v2'ye standart teknik SDK taşıma işlemini gerçekleştirmeniz gerekir.
Desteği sonlandırılan Google ile Oturum Açma'dan geçiş yapma
GoogleSignInClient sınıfını GamesSignInClient sınıfıyla değiştirin.
Java
GoogleSignInClient sınıfına ait dosyaları bulun.
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
// ... existing code
@Override
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
// ... existing code
GoogleSignInOptions signInOption =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build();
// Client used to sign in to Google services
GoogleSignInClient googleSignInClient =
GoogleSignIn.getClient(this, signInOptions);
}
Şu şekilde güncelleyin:
import com.google.android.gms.games.PlayGamesSdk;
import com.google.android.gms.games.PlayGames;
import com.google.android.gms.games.GamesSignInClient;
// ... existing code
@Override
public void onCreate(){
super.onCreate();
PlayGamesSdk.initialize(this);
// Client used to sign in to Google services
GamesSignInClient gamesSignInClient =
PlayGames.getGamesSignInClient(getActivity());
}
Kotlin
GoogleSignInClient sınıfına ait dosyaları bulun.
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
// ... existing code
val signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
// ... existing code
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val googleSignInClient: GoogleSignInClient =
GoogleSignIn.getClient(this, signInOptions)
}
Şu şekilde güncelleyin:
import com.google.android.gms.games.PlayGames
import com.google.android.gms.games.PlayGamesSdk
import com.google.android.gms.games.GamesSignInClient
// ... existing code
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PlayGamesSdk.initialize(this)
// client used to sign in to Google services
val gamesSignInClient: GamesSignInClient =
PlayGames.getGamesSignInClient(this)
}
GoogleSignIn kodunu güncelleme
GoogleSignIn API, Games v2 SDK'da desteklenmez. Aşağıdaki örnekte gösterildiği gibi GoogleSignIn API kodunu GamesSignInClient API ile değiştirin.
Sunucu tarafı erişim jetonu istemek için GamesSignInClient.requestServerSideAccess() yöntemini kullanın.
Daha fazla bilgi için Sunucu tarafı erişim sınıflarını güncelleme başlıklı makaleyi inceleyin.
Java
GoogleSignIn sınıfına ait dosyaları bulun.
// Request code used when invoking an external activity.
private static final int RC_SIGN_IN = 9001;
private boolean isSignedIn() {
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
GoogleSignInOptions signInOptions =
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
return GoogleSignIn.hasPermissions(account, signInOptions.getScopeArray());
}
private void signInSilently() {
GoogleSignInOptions signInOptions =
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
GoogleSignInClient signInClient = GoogleSignIn.getClient(this, signInOptions);
signInClient
.silentSignIn()
.addOnCompleteListener(
this,
task -> {
if (task.isSuccessful()) {
// The signed-in account is stored in the task's result.
GoogleSignInAccount signedInAccount = task.getResult();
showSignInPopup();
} else {
// Perform interactive sign in.
startSignInIntent();
}
});
}
private void startSignInIntent() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
Intent intent = signInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result =
Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// The signed-in account is stored in the result.
GoogleSignInAccount signedInAccount = result.getSignInAccount();
showSignInPopup();
} else {
String message = result.getStatus().getStatusMessage();
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error);
}
new AlertDialog.Builder(this).setMessage(message)
.setNeutralButton(android.R.string.ok, null).show();
}
}
}
private void showSignInPopup() {
Games.getGamesClient(requireContext(), signedInAccount)
.setViewForPopups(contentView)
.addOnCompleteListener(
task -> {
if (task.isSuccessful()) {
logger.atInfo().log("SignIn successful");
} else {
logger.atInfo().log("SignIn failed");
}
});
}
Şu şekilde güncelleyin:
private void signInSilently() {
gamesSignInClient.isAuthenticated().addOnCompleteListener(isAuthenticatedTask -> {
boolean isAuthenticated =
(isAuthenticatedTask.isSuccessful() &&
isAuthenticatedTask.getResult().isAuthenticated());
if (isAuthenticated) {
// Continue with Play Games Services
} else {
// If authentication fails, either disable Play Games Services
// integration or
// display a login button to prompt players to sign in.
// Use`gamesSignInClient.signIn()` when the login button is clicked.
}
});
}
@Override
protected void onResume() {
super.onResume();
// When the activity is inactive, the signed-in user's state can change;
// therefore, silently sign in when the app resumes.
signInSilently();
}Kotlin
GoogleSignIn sınıfına ait dosyaları bulun.
// Request codes we use when invoking an external activity.
private val RC_SIGN_IN = 9001
// ... existing code
private fun isSignedIn(): Boolean {
val account = GoogleSignIn.getLastSignedInAccount(this)
val signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
return GoogleSignIn.hasPermissions(account, *signInOptions.scopeArray)
}
private fun signInSilently() {
val signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
val signInClient = GoogleSignIn.getClient(this, signInOptions)
signInClient.silentSignIn().addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// The signed-in account is stored in the task's result.
val signedInAccount = task.result
// Pass the account to showSignInPopup.
showSignInPopup(signedInAccount)
} else {
// Perform interactive sign in.
startSignInIntent()
}
}
}
private fun startSignInIntent() {
val signInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
val intent = signInClient.signInIntent
startActivityForResult(intent, RC_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data)
if (result.isSuccess) {
// The signed-in account is stored in the result.
val signedInAccount = result.signInAccount
showSignInPopup(signedInAccount) // Pass the account to showSignInPopup.
} else {
var message = result.status.statusMessage
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error)
}
AlertDialog.Builder(this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show()
}
}
}
private fun showSignInPopup(signedInAccount: GoogleSignInAccount) {
// Add signedInAccount parameter.
Games.getGamesClient(this, signedInAccount)
.setViewForPopups(contentView) // Assuming contentView is defined.
.addOnCompleteListener { task ->
if (task.isSuccessful) {
logger.atInfo().log("SignIn successful")
} else {
logger.atInfo().log("SignIn failed")
}
}
}Şu şekilde güncelleyin:
private fun signInSilently() {
gamesSignInClient.isAuthenticated.addOnCompleteListener { isAuthenticatedTask ->
val isAuthenticated = isAuthenticatedTask.isSuccessful &&
isAuthenticatedTask.result.isAuthenticated
if (isAuthenticated) {
// Continue with Play Games Services
} else {
// To handle a user who is not signed in, either disable Play Games Services integration
// or display a login button. Selecting this button calls `gamesSignInClient.signIn()`.
}
}
}
override fun onResume() {
super.onResume()
// Since the state of the signed in user can change when the activity is
// not active it is recommended to try and sign in silently from when the
// app resumes.
signInSilently()
}GamesSignInClient kodunu ekleyin
Oyuncunun kimliği başarıyla doğrulanırsa Google Play Games Hizmetleri oturum açma düğmesini oyununuzdan kaldırın. Kullanıcı oyun başladığında kimlik doğrulaması yapmamayı seçerse
Play Games Hizmetleri simgesinin bulunduğu düğmeyi göstermeye devam edin
ve GamesSignInClient.signIn() ile giriş işlemini başlatın.
Java
private void startSignInIntent() {
gamesSignInClient
.signIn()
.addOnCompleteListener( task -> {
if (task.isSuccessful() && task.getResult().isAuthenticated()) {
// sign in successful
} else {
// sign in failed
}
});
}Kotlin
private fun startSignInIntent() {
gamesSignInClient
.signIn()
.addOnCompleteListener { task ->
if (task.isSuccessful && task.result.isAuthenticated) {
// sign in successful
} else {
// sign in failed
}
}
}Oturum kapatma kodunu kaldırma
GoogleSignInClient.signOut kodunu kaldırın.
Aşağıdaki örnekte gösterilen kodu kaldırın:
Java
// ... existing code
private void signOut() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
signInClient.signOut().addOnCompleteListener(this,
new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
// At this point, the user is signed out.
}
});
} Kotlin
// ... existing code
private fun signOut() {
val signInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
signInClient.signOut().addOnCompleteListener(this) {
// At this point, the user is signed out.
}
}Kimlik doğrulamanın başarılı olup olmadığını kontrol etme
Otomatik olarak kimlik doğrulaması yapıp yapmadığınızı kontrol etmek için aşağıdaki kodu ekleyin ve varsa özel mantığı ekleyin.
Java
private void checkIfAutomaticallySignedIn() {
gamesSignInClient.isAuthenticated().addOnCompleteListener(isAuthenticatedTask -> {
boolean isAuthenticated =
(isAuthenticatedTask.isSuccessful() &&
isAuthenticatedTask.getResult().isAuthenticated());
if (isAuthenticated) {
// Continue with Play Games Services
// If your game requires specific actions upon successful sign-in,
// you can add your custom logic here.
// For example, fetching player data or updating UI elements.
} else {
// Show a login button to ask players to sign-in. Clicking it should
// call GamesSignInClient.signIn().
}
});
}
Kotlin
private fun checkIfAutomaticallySignedIn() {
gamesSignInClient.isAuthenticated()
.addOnCompleteListener { task ->
val isAuthenticated = task.isSuccessful && task.result?.isAuthenticated ?: false
if (isAuthenticated) {
// Continue with Play Games Services
} else {
// Disable your integration or show a login button
}
}
}
İstemci sınıfı adlarını ve yöntemlerini güncelleme
Games v2'ye geçiş yaptığınızda istemci sınıfı adlarını almak için kullanılan yöntemler farklıdır.
Games.getxxxClient()
yöntemleri yerine ilgili
PlayGames.getxxxClient()
yöntemlerini kullanın.
Örneğin, LeaderboardsClient için Games.getLeaderboardsClient() yöntemi yerine PlayGames.getLeaderboardsClient() yöntemini kullanın.
Games v2'de yeni sınıflar olmadığı için GamesClient ve GamesMetadataClient sınıflarıyla ilgili tüm kodları kaldırın.
Java
LeaderboardsClient kodunu bulun.
import com.google.android.gms.games.LeaderboardsClient;
import com.google.android.gms.games.Games;
@Override
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
// Get the leaderboards client using Play Games services.
LeaderboardsClient leaderboardsClient = Games.getLeaderboardsClient(this,
GoogleSignIn.getLastSignedInAccount(this));
}
Şu şekilde güncelleyin:
import com.google.android.gms.games.LeaderboardsClient;
import com.google.android.gms.games.PlayGames;
@Override
public void onCreate(@Nullable Bundle bundle) {
super.onCreate(bundle);
// Get the leaderboards client using Play Games services.
LeaderboardsClient leaderboardsClient = PlayGames.getLeaderboardsClient(getActivity());
}
Kotlin
LeaderboardsClient kodunu bulun.
import com.google.android.gms.games.LeaderboardsClient
import com.google.android.gms.games.Games
// Initialize the variables.
private lateinit var leaderboardsClient: LeaderboardsClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
leaderboardsClient = Games.getLeaderboardsClient(this,
GoogleSignIn.getLastSignedInAccount(this))
}Şu şekilde güncelleyin:
import com.google.android.gms.games.LeaderboardsClient
import com.google.android.gms.games.PlayGames
// Initialize the variables.
private lateinit var leaderboardsClient: LeaderboardsClient
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
leaderboardsClient = PlayGames.getLeaderboardsClient(this)
}Benzer şekilde, şu istemciler için ilgili yöntemleri kullanın:
AchievementsClient, EventsClient, GamesSignInClient,
PlayerStatsClient, RecallClient, SnapshotsClient veya PlayersClient.
Sunucu tarafı erişim sınıflarını güncelleme
Sunucu tarafı erişim jetonu istemek için
GoogleSignInAccount.getServerAuthCode()
yöntemi yerine
GamesSignInClient.requestServerSideAccess()
yöntemini kullanın.
Daha fazla bilgi için Sunucu yetkilendirme kodunu gönderme bölümüne bakın.
Aşağıdaki örnekte, sunucu tarafı erişim jetonunun nasıl isteneceğini gösterilmektedir.
Java
GoogleSignInOptions sınıfının kodunu bulun.
private static final int RC_SIGN_IN = 9001;
private GoogleSignInClient googleSignInClient;
private void startSignInForAuthCode() {
/** Client ID for your backend server. */
String webClientId = getString(R.string.webclient_id);
GoogleSignInOptions signInOption = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestServerAuthCode(webClientId)
.build();
GoogleSignInClient signInClient = GoogleSignIn.getClient(this, signInOption);
Intent intent = signInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
}
/** Auth code to send to backend server */
private String mServerAuthCode;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
mServerAuthCode = result.getSignInAccount().getServerAuthCode();
} else {
String message = result.getStatus().getStatusMessage();
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error);
}
new AlertDialog.Builder(this).setMessage(message)
.setNeutralButton(android.R.string.ok, null).show();
}
}
}
Şu şekilde güncelleyin:
private void startRequestServerSideAccess() {
GamesSignInClient gamesSignInClient = PlayGames.getGamesSignInClient(this);
gamesSignInClient
.requestServerSideAccess(OAUTH_2_WEB_CLIENT_ID,
/* forceRefreshToken= */ false, /* additional AuthScope */ scopes)
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
AuthResponse authresp = task.getResult();
// Send the authorization code as a string and a
// list of the granted AuthScopes that were granted by the
// user. Exchange for an access token.
// Verify the player with Play Games Services REST APIs.
} else {
// Authentication code retrieval failed.
}
});
}
Kotlin
GoogleSignInOptions sınıfının kodunu bulun.
// ... existing code
private val RC_SIGN_IN = 9001
private lateinit var googleSignInClient: GoogleSignInClient
// Auth code to send to backend server.
private var mServerAuthCode: String? = null
private fun startSignInForAuthCode() {
// Client ID for your backend server.
val webClientId = getString(R.string.webclient_id)
val signInOption = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestServerAuthCode(webClientId)
.build()
googleSignInClient = GoogleSignIn.getClient(this, signInOption)
val intent = googleSignInClient.signInIntent
startActivityForResult(intent, RC_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val result = Auth.GoogleSignInApi.getSignInResultFromIntent(data)
if (result.isSuccess) {
mServerAuthCode = result.signInAccount.serverAuthCode
} else {
var message = result.status.statusMessage
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error)
}
AlertDialog.Builder(this).setMessage(message)
.setNeutralButton(android.R.string.ok, null).show()
}
}
}
Şu şekilde güncelleyin:
private fun startRequestServerSideAccess() {
val gamesSignInClient = PlayGames.getGamesSignInClient(this)
gamesSignInClient
.requestServerSideAccess(
OAUTH_2_WEB_CLIENT_ID,
/* forceRefreshToken= */ false,
/* additional AuthScope */ scopes
)
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val authresp: AuthResponse = task.result
// Send the authorization code as a string and a
// list of the granted AuthScopes that were granted by the
// user. Exchange for an access token.
// Verify the player with Play Games Services REST APIs.
} else {
// Authentication code retrieval failed.
}
}
}
GoogleApiClient'tan taşıma
Daha önceki entegrasyonlarda oyununuz, Play Games Hizmetleri SDK'sının GoogleApiClient API varyasyonuna bağlı olabilir. Bu özellik 2017'nin sonlarında kullanımdan kaldırıldı ve yerini "bağlantısız" istemciler aldı. Geçiş yapmak için GoogleApiClient sınıfını "bağlantısız" bir eşdeğerle değiştirin.
Aşağıdaki tabloda, games v1'den games v2'ye yapılan yaygın sınıf eşlemeleri listelenmiştir:
| games v2 (Current) | games v1 (Eski) |
|---|---|
| com.google.android.gms.games.AchievementsClient | com.google.android.gms.games.achievement.Achievements |
| com.google.android.gms.games.LeaderboardsClient | com.google.android.gms.games.leaderboard.Leaderboard |
| com.google.android.gms.games.SnapshotsClient | com.google.android.gms.games.snapshot.Snapshots |
| com.google.android.gms.games.PlayerStatsClient | com.google.android.gms.games.stats.PlayerStats |
| com.google.android.gms.games.PlayersClient | com.google.android.gms.games.Players |
| com.google.android.gms.games.GamesClientStatusCodes | com.google.android.gms.games.GamesStatusCodes |
Oyunu derleme ve çalıştırma
Android Studio'da derleme ve çalıştırma için Uygulamanızı derleme ve çalıştırma başlıklı makaleyi inceleyin.
Oyununuzu test etme
Oyununuzu test ederek tasarlandığı gibi çalıştığından emin olun. Yaptığınız testler oyununuzun özelliklerine bağlıdır.
Aşağıda, çalıştırılacak yaygın testlerin listesi verilmiştir.
Başarılı oturum açma.
Otomatik oturum açma çalışıyor. Kullanıcı, oyunu başlattığında Google Play Games Hizmetleri'nde oturum açmış olmalıdır.
Karşılama pop-up'ı gösterilir.
Örnek karşılama pop-up'ı (büyütmek için tıklayın). Başarılı günlük mesajları gösterilir. Terminalde aşağıdaki komutu çalıştırın:
adb logcat | grep com.google.android.
Aşağıdaki örnekte başarılı bir günlük mesajı gösterilmektedir:
[
$PlaylogGamesSignInAction$SignInPerformerSource@e1cdecc number=1 name=GAMES_SERVICE_BROKER>], returning true for shouldShowWelcomePopup. [CONTEXT service_id=1 ]
Kullanıcı arayüzü bileşenlerinin tutarlı olmasını sağlama
Pop-up'lar, skor tabloları ve başarılar, Google Play Games Hizmetleri kullanıcı arayüzünde (UI) çeşitli ekran boyutlarında ve yönlerinde doğru ve tutarlı bir şekilde görüntülenir.
Oturumu kapatma seçeneği, Google Play Games Hizmetleri kullanıcı arayüzünde görünmüyor.
Oyuncu kimliğini başarıyla alabildiğinizden ve varsa sunucu tarafı özelliklerinin beklendiği gibi çalıştığından emin olun.
Oyun, sunucu tarafı kimlik doğrulaması kullanıyorsa
requestServerSideAccessakışını kapsamlı bir şekilde test edin. Sunucunun yetkilendirme kodunu aldığından ve bu kodu bir erişim jetonuyla değiştirebildiğinden emin olun. Ağ hataları ve geçersiz senaryolar için hem başarılı hem de başarısız senaryoları test edin.client ID
Oyununuzda aşağıdaki özelliklerden herhangi biri kullanılıyorsa bunları test ederek taşıma işleminden önceki gibi çalıştıklarından emin olun:
- Skor tabloları: Skorları gönderin ve skor tablolarını görüntüleyin. Oyuncu adlarının ve puanlarının doğru sıralanıp sıralanmadığını ve doğru gösterilip gösterilmediğini kontrol edin.
- Başarılar: Başarıların kilidini açın ve bunların doğru şekilde kaydedilip Google Play Games kullanıcı arayüzünde gösterildiğini doğrulayın.
- Kaydedilmiş Oyunlar: Oyun, kaydedilmiş oyunları kullanıyorsa oyun ilerleme durumunu kaydetme ve yükleme işlemlerinin sorunsuz çalıştığından emin olun. Bu, özellikle birden fazla cihazda ve uygulama güncellemelerinden sonra test edilmesi gereken kritik bir konudur.
Taşıma sonrası görevler
Games v2'ye geçiş yaptıktan sonra aşağıdaki adımları tamamlayın.
Oyunu yayınlama
APK'ları oluşturun ve oyunu Google Play Console'da yayınlayın.
- Android Studio menüsünde Derle > Paketleri/APK'ları Derle > APK'ları Derle'yi seçin.
- Oyununuzu yayınlayın. Daha fazla bilgi için Play Console'dan özel uygulama yayınlama başlıklı makaleyi inceleyin.