이 가이드에서는 Play 게임즈 서비스 v2 네이티브 SDK를 사용하고 로그인 서비스를 통합하도록 네이티브 C 또는 C++ 게임 프로젝트를 설정하는 방법을 설명합니다. 다른 Play 게임즈 서비스 기능을 게임에 통합하고 Play 게임즈 서비스를 백엔드 게임 서버에 통합하려면 로그인 통합이 필요합니다.
지원되는 기능
Play 게임즈 서비스 v2 네이티브 SDK는 베타 버전이며 로그인 서비스만 지원합니다. 다른 Play 게임즈 서비스 기능은 아직 지원하지 않습니다.
API 참조 문서
SDK의 헤더 파일에는 API에 관한 참조 문서가 포함되어 있습니다. 헤더 파일은 SDK 파일의 include 폴더에 있으며 프로젝트를 SDK 저장소와 동기화한 후 사용할 수 있습니다.
find_package(com.google.android.gms.games.v2.cREQUIREDCONFIG)// link games_static for -DANDROID_STL=c++_static or default// link games_shared for -DANDROID_STL=c++_sharedtarget_link_libraries(appPUBLICcom.google.android.gms.games.v2.c::games_static)
게임을 빌드하고 테스트합니다. 성공하는 경우 게임 실행 시 로그인 메시지 또는 로그인 성공 배너가 표시됩니다.
플레이어 ID 가져오기
게임에서 플레이어 ID를 검색하여 로그인한 플레이어의 플레이어 정보에 액세스할 수 있습니다. 다음 예와 같이 GetPlayerID 함수를 호출하여 플레이어 ID를 검색할 수 있습니다.
#include <assert.h>#include"gni/gni.h"#include"gni/gni_task.h"#include"pgs/pgs_play_games.h"#include"pgs/pgs_players_client.h"// A callback for a GniTask returned from PgsPlayersClient_getCurrentPlayerId.voidOnGetCurrentPlayerIdCompleteCallback(GniTask*task,void*user_data){if(!GniTask_isSuccessful(task)){constchar*error_message=nullptr;GniTask_getErrorMessage(task,&error_message);// Log error message here.GniString_destroy(error_message);GniTask_destroy(task);return;}constchar*result=nullptr;PgsPlayersClient_getCurrentPlayerId_getResult(task,&result);// Log player id here.GniString_destroy(result);GniTask_destroy(task);}// Gets the player ID.voidGetPlayerId(jobjectmain_activity){staticconstPgsPlayersClient*players_client=PgsPlayGames_getPlayersClient(main_activity);GniTask*get_current_player_id_task=PgsPlayersClient_getCurrentPlayerId(players_client);assert(get_current_player_id_task!=nullptr);GniTask_addOnCompleteCallback(get_current_player_id_task,OnGetCurrentPlayerIdCompleteCallback,nullptr);}// Entry point for our test appvoidTestPGSNative(JNIEnv*env,jobjectmain_activity){JavaVM*java_vm;env->GetJavaVM(&java_vm);GniCore_init(java_vm,main_activity);GetPlayerId(main_activity);}
로그인 메시지 다시 실행
플레이어가 게임 실행 시 자동으로 표시되는 Play 게임즈 서비스 초기 로그인 메시지를 거부했다가 게임 세션 중에 마음이 바뀔 수도 있습니다. 현재 로그인한 플레이어가 없는 경우 PgsGamesSignInClient_signIn을 호출하여 로그인 메시지를 다시 실행할 수 있습니다.
게임 서버 승인
플레이어가 Play 게임즈 서비스에 로그인하면 게임 클라이언트는 백엔드 게임 서버가 Play 게임즈 서비스와 안전하게 통신하는 데 사용할 수 있는 서버 승인 코드를 요청할 수 있습니다. 그러면 게임 서버가 로그인한 플레이어의 데이터를 검색하고 업데이트 및 저장할 수 있습니다. PgsGamesSignInClient_requestServerSideAccess 함수를 호출하여 서버 승인 코드를 검색할 수 있습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Get started with Play Games Services for C and C++\n\nThis guide describes how to set up a native C or C++ game project to use the\nPlay Games Services v2 Native SDK and integrate the\n[Sign-in service](/games/pgs/signin). Sign-in integration is required in order\nto integrate other Play Games Services [features](/games/pgs/overview#features)\ninto your game and to integrate Play Games Services into your\n[backend game server](/games/pgs/android/server-access).\n\nSupported features\n------------------\n\nThe Play Games Services v2 Native SDK is in beta and only supports\nthe Sign-in service. It doesn't yet support other Play Games Services\n[features](/games/pgs/overview#features).\n\nAPI reference documentation\n---------------------------\n\nThe header files for the SDK contain reference documentation for the APIs. The\nheader files are located in the `include` folder in the SDK files, which are\navailable after you sync your project with SDK repository.\n\nRequirements\n------------\n\n- A game project that uses native C or C++ as the primary programming language.\n\n- Your game project and development environment must have the\n [Gradle](https://docs.gradle.org/current/userguide/userguide.html)\n build system set up.\n\nBefore you start\n----------------\n\nYou must [set up Play Games Services](/games/pgs/console/setup) in\nGoogle Play Console.\n\nSet up your game project\n------------------------\n\nComplete the following steps to set up your game project.\n\n### Update CMakeLists.txt\n\nIn your `CMakeLists.txt` file, add the following code: \n\n find_package(com.google.android.gms.games.v2.c REQUIRED CONFIG)\n\n // link games_static for -DANDROID_STL=c++_static or default\n // link games_shared for -DANDROID_STL=c++_shared\n target_link_libraries(\n app PUBLIC com.google.android.gms.games.v2.c::games_static)\n\n### Update build.gradle\n\nIn your app-level `build.gradle` file do the following:\n\n- Make sure the [prefab](/reference/tools/gradle-api/4.1/com/android/build/api/dsl/BuildFeatures#prefab) build feature is enabled.\n\n- Add the dependency for the Play Games Services v2 Native SDK:\n\n - `com.google.android.gms:play-services-games-v2-native-c:17.0.0-beta1`\n\nHere's an example: \n\n android {\n ...\n buildFeatures {\n prefab true\n }\n ...\n }\n dependencies {\n ...\n implementation \"com.google.android.gms:play-services-games-v2-native-c:17.0.0-beta1\"\n }\n\n### Update AndroidManifest.xml\n\n1. In your `AndroidManifest.xml` file, define your Play Games Services project\n ID. You can do so by adding the following lines to the file:\n\n \u003cmanifest\u003e\n \u003capplication\u003e\n \u003cmeta-data android:name=\"com.google.android.gms.games.APP_ID\"\n android:value=\"@string/game_services_project_id\"/\u003e\n \u003c/application\u003e\n \u003c/manifest\u003e\n\n2. Create a [string resource](/guide/topics/resources/string-resource#String)\n for your project ID. This allows your game to access the ID at build time.\n To create the resource, create the file\n \u003cvar translate=\"no\"\u003eproject_root\u003c/var\u003e`/app/src/main/res/values/games-ids.xml`,\n and add the following:\n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cresources\u003e\n \u003cstring name=\"game_services_project_id\"\n translatable=\"false\"\u003e\u003cvar translate=\"no\"\u003eadd\u003cspan class=\"devsite-syntax-w\"\u003e \u003c/span\u003eyour\u003cspan class=\"devsite-syntax-w\"\u003e \u003c/span\u003eProject\u003cspan class=\"devsite-syntax-w\"\u003e \u003c/span\u003eID\u003cspan class=\"devsite-syntax-w\"\u003e \u003c/span\u003ehere\u003c/var\u003e\u003c/string\u003e\n \u003c/resources\u003e\n\n3. Build and test your game. If successful, when you launch your game it\n displays a sign-in prompt or a successful sign-in banner.\n\nGet the player ID\n-----------------\n\nYour game can access player information for a signed in player by retrieving\ntheir player ID. You can retrieve a player ID by calling the `GetPlayerID`\nfunction, which is demonstrated in the following example.\n| **Note:** For more information about how Player IDs work, visit the topic [here on\nnext generation Player IDs](/games/pgs/next-gen-player-ids) \n\n #include \u003cassert.h\u003e\n #include \"gni/gni.h\"\n #include \"gni/gni_task.h\"\n #include \"pgs/pgs_play_games.h\"\n #include \"pgs/pgs_players_client.h\"\n\n // A callback for a GniTask returned from PgsPlayersClient_getCurrentPlayerId.\n void OnGetCurrentPlayerIdCompleteCallback(GniTask *task, void *user_data) {\n\n if (!GniTask_isSuccessful(task)) {\n const char *error_message = nullptr;\n GniTask_getErrorMessage(task, &error_message);\n\n // Log error message here.\n\n GniString_destroy(error_message);\n GniTask_destroy(task);\n return;\n }\n\n const char *result = nullptr;\n PgsPlayersClient_getCurrentPlayerId_getResult(task, &result);\n\n // Log player id here.\n\n GniString_destroy(result);\n GniTask_destroy(task);\n }\n\n // Gets the player ID.\n void GetPlayerId(jobject main_activity) {\n static const PgsPlayersClient *players_client =\n PgsPlayGames_getPlayersClient(main_activity);\n\n GniTask *get_current_player_id_task =\n PgsPlayersClient_getCurrentPlayerId(players_client);\n assert(get_current_player_id_task != nullptr);\n GniTask_addOnCompleteCallback(get_current_player_id_task,\n OnGetCurrentPlayerIdCompleteCallback,\n nullptr);\n }\n\n // Entry point for our test app\n void TestPGSNative(JNIEnv *env, jobject main_activity) {\n JavaVM *java_vm;\n env-\u003eGetJavaVM(&java_vm);\n\n GniCore_init(java_vm, main_activity);\n\n GetPlayerId(main_activity);\n }\n\nRe-launch the sign-in prompt\n----------------------------\n\nIf a player declines the initial Play Games Services sign-in prompt that is\nautomatically displayed when your game launches, they may change their mind\nduring the game session. You can re-launch the sign-in prompt by calling\n`PgsGamesSignInClient_signIn` as long as no players are currently signed in.\n\nGame server authorization\n-------------------------\n\nOnce a player successfully signs into to Play Games Services, your game client\ncan request a server authorization code that your backend game server can use to\nsecurely communicate with Play Games Services. This allows your game server to\nretrieve, update, and store data for the signed in player. You can retrieve the\nserver authorization code by calling the\n`PgsGamesSignInClient_requestServerSideAccess` function.\n\nFor more information, see the\n[server access guide](/games/pgs/android/server-access)."]]