بدء استخدام "خدمات ألعاب Play" لـ C++ على نظام Android
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
بعد إيقاف واجهة برمجة التطبيقات
Google Sign-In API
نهائيًا، سنزيل حزمة تطوير البرامج (SDK) لألعاب الإصدار 1 في عام 2026. بعد شباط (فبراير) 2025، لن تتمكّن من نشر
العناوين التي تم دمجها حديثًا مع حزمة تطوير البرامج (SDK) لإصدار 1 من "ألعاب Google Play" على Google Play. ننصحك باستخدام
حزمة تطوير البرامج (SDK) لإصدار 2 من "ألعاب Google Play" بدلاً من ذلك.
على الرغم من أنّ العناوين الحالية التي تم دمجها مع الإصدار 1 من الألعاب السابقة ستظل تعمل لعدة
سنوات، ننصحك بنقل بياناتها إلى الإصدار 2
اعتبارًا من حزيران (يونيو) 2025.
يتناول هذا الدليل استخدام حزمة تطوير البرامج (SDK) لإصدار 1 من "خدمات ألعاب Play". لا تتوفّر حزمة C++ SDK لإصدار
"خدمات ألعاب Play" 2 حتى الآن.
سيوضّح لك دليل المطوّرين هذا كيفية تجميع لعبة C++ وتشغيلها على Android باستخدام واجهة برمجة التطبيقات Google Play
Game services API. قبل البدء، عليك تنزيل المتطلبات التالية وضبطها:
يستخدم دليل المطوّرين هذا مجموعة تطوير البرامج الأصلية (NDK) من Android. إذا لم تكن معتادًا على استخدام حزمة NDK،
يُرجى الرجوع إلى مستندات حزمة NDK وعينات منها
قبل المتابعة.
الخطوة 1: إعداد البيئة
نزِّل حِزم SDK وNDK لنظام التشغيل Android وفُك ضغطها على جهازك. في
البيئة، اضبط SDK_ROOT على الموقع الجغرافي لمجلد حزمة تطوير البرامج (SDK) لنظام التشغيل Android وNDK_ROOT على
الموقع الجغرافي لمجلد Android NDK.
افتح Eclipse. إذا لم يسبق لك ذلك، حدِّد لبرنامج Eclipse مكان تثبيت حِزمة NDK من خلال
النقر على الإعدادات المفضّلة > Android > حِزمة NDK.
استورِد مشروع مكتبة "خدمات Google Play" إلى مساحة عمل Eclipse.
في Eclipse، انقر على ملف > استيراد > Android > رمز Android الحالي في مساحة العمل.
اختَر SDK_ROOT/extras/google/google_play_services/libproject/google-play-services_lib
حيث يكون SDK_ROOT هو موقع حزمة تطوير البرامج (SDK) لنظام التشغيل Android.
انقر على إنهاء.
استورِد نموذج المشروع البسيط إلى مساحة عمل Eclipse.
في Eclipse، انقر على ملف > استيراد > Android > رمز Android الحالي في مساحة العمل.
اختَر SAMPLES_DIR/samples-android/minimalist.
انقر على إنهاء.
انقر بزر الماوس الأيمن على مشروع MinimalistActivity وانقر على السمات. ضمن Android، انتقِل إلى أسفل الصفحة في قسم المكتبة وتأكَّد من أنّه تمت الإشارة إلى مشروع google-play-services_lib بشكلٍ سليم. إذا لم يكن الأمر كذلك، عليك إزالة المرجع وإضافته مرة أخرى من مساحة العمل.
سيُجمِّع Eclipse تلقائيًا مصادر Java وAndroid لمشروعك، ولكن يجب تجميع الرمز البرمجي
الأصلي في مجلد jni بشكل منفصل. لإجراء ذلك يدويًا، انتقِل إلى
المجلد jni وشغِّل ndk-build. احرص على إجراء ذلك بعد إجراء أي تغييرات داخل
المجلد jni.
من المفترض أن يتم الآن تجميع مشروعك، إلا أنّه لن يعمل بعد. عليك أولاً ضبط إعدادات لعبتك
في Google Play Console.
الخطوة 2: إعداد اللعبة في Google Play Console
أنشئ إدخالاً للعبة في Google Play Console. يؤدي ذلك إلى تفعيل "خدمات الألعاب" لتطبيقك، وإنشاء معرِّف عميل OAuth 2.0 إذا لم يكن لديك معرِّف.
في AndroidManifest.xml، غيِّر سمة package لعلامة <manifest> إلى اسم
الحزمة الذي اخترته عند إعداد Google Play Console. قد تحتاج إلى إصلاح بعض الإشارات
في جميع أنحاء المشروع بعد إجراء هذا التغيير (خاصةً إلى فئة R التي تم إنشاؤها).
افتح res/values/ids.xml وضع رقم تعريف التطبيق هناك. يُرجى العِلم أنّ رقم تعريف التطبيق ليس هو نفسه
رقم تعريف العميل، بل هو الرقم الظاهر بجانب اسم لعبتك في صفحة تفاصيل اللعبة في
Google Play Console.
الخطوة 3: تشغيل العيّنة
لتنفيذ العيّنة، ستحتاج إلى جهاز Android أصلي أو محاكي تم تثبيت
"خدمات Google Play" عليه:
شغِّل ndk-build لتجميع الرمز البرمجي الأصلي.
في Eclipse، انقر على Run (التشغيل) > Run As (التشغيل بصفتك) > Android Application (تطبيق Android) وشغِّل العيّنة على جهازك.
عند فتح العيّنة، انقر في أي مكان على الشاشة. من المفترض أن يظهر لك شعار "ألعاب Google Play".
إذا كنت قد أعددت تطبيقك بشكل صحيح، سيُطلب منك تسجيل الدخول.
اختياري: إنشاء التطبيق تلقائيًا باستخدام Eclipse
توضِّح لك الخطوات التالية كيفية ضبط Eclipse لتشغيل ndk-build تلقائيًا عند
إجراء تغييرات على الملفات في مجلد jni.
انقر بزر الماوس الأيمن على مشروع MinimalistActivity وانقر على السمات. في نافذة "الخصائص"،
اختَر لوحة المطوّرون.
انقر على جديد لإضافة أداة إنشاء جديدة، ثم اختَر برنامج، ثم انقر على حسنًا.
في حقل الاسم، أدخِل "أداة إنشاء حِزم NDK".
ضمن الموقع، انقر على تصفُّح نظام الملفات وانتقِل إلى الدليل NDK_ROOT و
اختَر الأمر ndk-build.
ضمن دليل العمل، انقر على تصفّح مساحة العمل واختَر مجلد مشروع MinimalistActivity.
انقر على علامة التبويب إعادة تحميل. تأكَّد من وضع علامة في المربّع Refresh resources upon completion (إعادة تحميل الموارد عند اكتمال العملية).
انقر على زر الاختيار موارد محدّدة، ثم انقر على تحديد الموارد. في
مربّع الحوار الناتج، اختَر المجلد jni ضمن MinimalActivity.
انقر على تطبيق ثم على حسنًا لإنهاء إنشاء "أداة الإنشاء".
في كل مرة تعدِّل فيها ملفًا ضمن المجلد jni، سيشغِّل Eclipse أداة ndk-build ويطبع المخرجات في وحدة تحكُّم Eclipse.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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."]]