Cómo comenzar a usar los Servicios de juego de Play para C++ en Android
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Después de la baja de la API de Acceso a Google, quitaremos el SDK de juegos v1 en 2026. Después de febrero de 2025, no podrás publicar títulos que se hayan integrado recientemente con el SDK de juegos v1 en Google Play. Te recomendamos que uses el SDK de juegos v2.
Si bien los títulos existentes con las integraciones de la versión 1 de los juegos anteriores seguirán funcionando durante un
par de años, te recomendamos que
migres a la versión 2
a partir de junio de 2025.
Esta guía se aplica al uso del SDK de la versión 1 de los Servicios de juego de Play. El SDK de C++ para la versión 2 de los Servicios de juego de Play aún no está disponible.
En esta guía para desarrolladores, se muestra cómo compilar y ejecutar un juego en C++ en Android que usa la API de los Servicios de juego de Google Play. Antes de comenzar, descarga y configura los siguientes requisitos:
En esta guía para desarrolladores, se usa el kit de desarrollo nativo (NDK) de Android. Si no conoces el NDK, consulta la documentación y los ejemplos del NDK antes de continuar.
Paso 1: Configura tu entorno
Descarga el SDK y el NDK de Android, y extráelos en tu máquina. En tu
entorno, establece SDK_ROOT en la ubicación de la carpeta del SDK de Android y NDK_ROOT en la
ubicación de la carpeta del NDK de Android.
Descarga los juegos de muestra de C++. En esta guía para desarrolladores, se hace referencia a la ubicación de las muestras en tu máquina como SAMPLES_DIR.
Descarga el SDK de C++ para los servicios de juego de Google Play. Extrae el SDK en tu máquina de desarrollo. En tu entorno, establece la variable NDK_MODULE_PATH para que apunte al directorio anterior al directorio gpg-cpp-sdk. Debes tener la siguiente estructura de directorios:
NDK_MODULE_PATH/
gpg-cpp-sdk/
Abre Eclipse. Si aún no lo hiciste, dile a Eclipse dónde instalaste el NDK. Para ello, haz clic en Preferences > Android > NDK.
Importa el proyecto de la biblioteca de los Servicios de Google Play a tu lugar de trabajo de Eclipse.
En Eclipse, haz clic en File > Import > Android > Existing Android Code into Workspace.
Selecciona SDK_ROOT/extras/google/google_play_services/libproject/google-play-services_lib, donde SDK_ROOT es la ubicación de tu SDK de Android.
Haz clic en Finish.
Importa el proyecto de ejemplo minimalista a tu lugar de trabajo de Eclipse.
En Eclipse, haz clic en File > Import > Android > Existing Android Code into Workspace.
Haz clic con el botón derecho en el proyecto MinimalistActivity y, luego, en Properties. En Android, desplázate hacia abajo hasta la sección Library y asegúrate de que se haga referencia correctamente al proyecto google-play-services_lib. De lo contrario, quita la referencia y vuelve a agregarla desde tu lugar de trabajo.
Eclipse compilará automáticamente los orígenes de Java y Android de tu proyecto. Sin embargo, el código nativo de la carpeta jni se debe compilar por separado. Para hacerlo de forma manual, navega a la carpeta jni y ejecuta ndk-build. Recuerda hacerlo después de realizar cualquier cambio en la carpeta jni.
Ahora, tu proyecto debería compilarse, aunque aún no funcionará. Primero, debes configurar tu juego en Google Play Console.
Paso 2: Configura el juego en Google Play Console
Crea una entrada para tu juego en Google Play Console. De esta manera, se habilitarán los servicios de juegos para tu aplicación y se creará un ID de cliente de OAuth 2.0, si aún no tienes uno.
En AndroidManifest.xml, cambia el atributo package de la etiqueta <manifest> al nombre del paquete que elegiste cuando configuraste Google Play Console. Es posible que debas corregir algunas referencias en todo el proyecto después de realizar este cambio (en particular, en la clase R generada).
Abre res/values/ids.xml y coloca tu ID de app allí. Ten en cuenta que el ID de app no es el mismo que el ID de cliente; es el número que aparece junto al nombre de tu juego en la página Detalles del juego de Google Play Console.
Paso 3: Ejecuta la muestra
Para ejecutar la muestra, necesitarás un dispositivo Android físico o un emulador con los Servicios de Google Play instalados:
Ejecuta ndk-build para compilar el código nativo.
En Eclipse, haz clic en Run > Run As > Android Application y ejecuta la muestra en tu dispositivo.
Cuando se abra el feed de Samples, presiona cualquier parte de la pantalla. Deberías ver el logotipo de Google Play Juegos. Si configuraste correctamente la app, se te pedirá que accedas.
Opcional: Compila automáticamente con Eclipse
En los siguientes pasos, se muestra cómo configurar Eclipse para que ejecute ndk-build automáticamente cuando realices cambios en los archivos de la carpeta jni.
Haz clic con el botón derecho en el proyecto MinimalistActivity y, luego, en Properties. En la ventana Properties, selecciona el panel Builders.
Haz clic en New para agregar un compilador nuevo, selecciona Program y, luego, haz clic en OK.
En el campo Nombre, ingresa "NDK Builder".
En Ubicación, haz clic en Explorar el sistema de archivos y navega al directorio NDK_ROOT y selecciona el comando ndk-build.
En Working Directory, haz clic en Browse Workspace y selecciona la carpeta del proyecto MinimalistActivity.
Haz clic en la pestaña Actualizar. Asegúrate de que la casilla Actualizar recursos al finalizar esté marcada.
Selecciona el botón de selección Recursos específicos y, luego, haz clic en Especificar recursos. En el diálogo resultante, selecciona la carpeta jni en MinimalActivity.
Haz clic en Apply y, luego, en OK para terminar de crear el compilador.
Ahora, cada vez que edites un archivo dentro de la carpeta jni, Eclipse ejecutará ndk-build e imprimirá el resultado en Eclipse Console.
El contenido y las muestras de código que aparecen en esta página están sujetas a las licencias que se describen en la Licencia de Contenido. Java y OpenJDK son marcas registradas de Oracle o sus afiliados.
Última actualización: 2025-07-27 (UTC)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-07-27 (UTC)"],[],[],null,["# Get Started with Play Games Services for C++ on Android\n\nFollowing the deprecation of the\n[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)\nAPI, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish\ntitles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the\ngames v2 SDK instead. \n\nWhile existing titles with the previous games v1 integrations continue to function for a\ncouple of years, you are encouraged to\n[migrate to v2](/games/pgs/android/migrate-to-v2)\nstarting June 2025. \n\nThis guide is for using the Play Games Services v1 SDK. The C++ SDK for\nPlay Games Services v2 is not yet available.\n\nThis developer guide will show you how to compile and run a C++ game on Android that uses the Google Play\nGame services API. Before you begin, download and configure the following requirements:\n\n- [Android NDK](/ndk), Revision 14 or higher.\n- [Android SDK v10 or higher and latest version of the Eclipse ADT](/studio/tools/sdk/eclipse-adt).\n- Device must be running Android 4.0 (API level 14) or higher.\n- [The latest version of the Google Play services SDK.](https://developers.google.com/android/guides/setup)\n\nThis developer guide uses the Android Native Development Kit (NDK). If you are unfamiliar with the NDK,\nrefer to the [NDK documentation and samples](/ndk)\nbefore continuing.\n\nStep 1: Set up your environment\n-------------------------------\n\n1. Download the Android SDK and the Android NDK and extract them to your machine. In your environment, set `SDK_ROOT` to the location of your Android SDK folder and `NDK_ROOT` to the location of your Android NDK folder.\n2. Download the [C++ sample games](//github.com/playgameservices/cpp-android-basic-samples). This developer guide refers to the location of the samples on your machine as `SAMPLES_DIR`.\n3. Download the [Google Play Games services C++ SDK](/games/pgs/downloads#sdk). Extract the SDK onto your development machine. In your environment, set the variable `NDK_MODULE_PATH` to point to the directory **above** the `gpg-cpp-sdk` directory. You should have the following directory structure: \n\n ```\n NDK_MODULE_PATH/\n gpg-cpp-sdk/\n ```\n4. Open Eclipse. If you have not already done so, tell Eclipse where you installed the NDK by clicking **Preferences \\\u003e Android \\\u003e NDK**.\n5. Import the Google Play services library project into your Eclipse workspace.\n\n 1. In Eclipse, click **File \\\u003e Import \\\u003e Android \\\u003e Existing Android Code into Workspace**.\n 2. Select `SDK_ROOT/extras/google/google_play_services/libproject/google-play-services_lib` where `SDK_ROOT` is the location of your Android SDK.\n 3. Click **Finish**.\n6. Import the minimalist sample project into your Eclipse workspace.\n\n 1. In Eclipse, click **File \\\u003e Import \\\u003e Android \\\u003e Existing Android Code into Workspace**.\n 2. Select `SAMPLES_DIR/samples-android/minimalist`.\n 3. Click **Finish**.\n7. Right click the MinimalistActivity project and click **Properties** . Under **Android** , scroll\n down to the **Library** section and make sure the google-play-services_lib project is correctly\n referenced. If not, remove the reference and add it again from your workspace.\n\nEclipse will automatically compile the Java and Android sources of your project; however, the\nnative code in the `jni` folder needs to be compiled separately. To do this manually, navigate to\nthe `jni` folder and run `ndk-build`. Remember to do this after you make any changes inside\nthe `jni` folder.\n\nYour project should now compile, though it will not work yet. You must first configure your game\nin the Google Play Console.\n\nStep 2: Set up the game in the Google Play Console\n--------------------------------------------------\n\nCreate an entry for your game in the Google Play Console. This enables Games services for your\napplication, and creates an OAuth 2.0 client ID, if you don't already have one.\n\n1. Create an entry for your game by following the steps described in [Setting Up Google Play Games Services](/games/pgs/console/setup).\n2. In `AndroidManifest.xml`, change the `package` attribute of the `\u003cmanifest\u003e` tag to the package name you chose when setting up the Google Play Console. You may have to fix some references throughout the project after making this change (particularly to the generated `R` class).\n3. Open `res/values/ids.xml` and place your App ID there. Note that the App ID is not the same as the client ID; it is the number next to the name of your game in the **Game Details** page of the Google Play Console.\n\nStep 3: Run the sample\n----------------------\n\nIn order to run the sample you will need a physical Android device or an emulator with\nGoogle Play services installed:\n\n1. Run `ndk-build` to compile the native code.\n2. In Eclipse, click **Run \\\u003e Run As \\\u003e Android Application** and run the sample on your device.\n3. When the sample opens, tap anywhere on the screen. You should see a Google Play Games logo appear. If you have correctly configured your app, you will be prompted to sign in.\n\n| **Important:** Make sure to sign your APK with the same certificate as the one whose fingerprint you configured on Google Play Console. Failure to do so will produce errors.\n| **Important:** If you are testing an unpublished game, make sure that the account with which you intend to sign in (usually, the account on the test device) is listed as a tester in the project. Open the **Testing** page, in the **Game services** subtab of the Google Play Console, to check or perform whitelisting. Failure to perform this step causes the server to act as though your project does not exist, and return errors.\n\nOptional: Build automatically with Eclipse\n------------------------------------------\n\nThe following steps show you how to configure Eclipse to automatically run `ndk-build` when you\nmake changes to files in the `jni` folder.\n\n1. Right-click the MinimalistActivity project and click **Properties** . In the Properties window, select the **Builders** pane.\n2. Click **New** to add a new Builder and select **Program** then click **OK**.\n3. In the **Name** field, enter 'NDK Builder'.\n4. Under **Location** click **Browse File System** and navigate to the `NDK_ROOT` directory and select the `ndk-build` command.\n5. Under **Working Directory** click **Browse Workspace** and select the MinimalistActivity project folder.\n6. Click the **Refresh** tab. Make sure the **Refresh resources upon completion** box is checked.\n7. Select the **Specific resources** radio button and then click **Specify Resources** . In the resulting dialog, select the `jni` folder under MinimalActivity.\n8. Click **Apply** and then **OK** to finish creating your Builder.\n\nNow every time you edit a file within the `jni` folder, Eclipse will run `ndk-build` and print the\noutput to the Eclipse Console.\n| **Note:** If you see errors when editing C or C++ files in Eclipse that prevent you from building the project, you may want to disable C/C++ error reporting in Eclipse. In your project properties, navigate to **C/C++ General \\\u003e Code Analysis \\\u003e Launching** and make sure that both boxes are unchecked. Then click **Apply** and **OK** . This is a workaround to prevent Eclipse from checking your native code, it does **not** fix any real underlying errors you may have."]]