适用于 Android 游戏的 Play 游戏服务使用入门
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南介绍了如何设置 Android Studio 项目,以使用 Play 游戏服务 SDK。您必须先完成以下步骤,然后才能设置 Play 游戏服务登录功能,并为游戏添加 Play 游戏服务功能。
准备工作
为了让您的应用做好准备,请完成以下部分中的步骤。
应用要满足的前提条件
确保您应用的 build 文件使用以下值:
minSdkVersion
为 19
或更高版本
compileSdkVersion
为 28
或更高版本
在 Google Play 管理中心内设置游戏
您可以在 Google Play 管理中心内管理游戏的 Google Play 游戏服务,以及配置用于对游戏进行授权和身份验证的元数据。如需了解详情,请参阅设置 Google Play 游戏服务。
在项目级 build.gradle
文件中,同时在 buildscript
和 allprojects
两个部分中添加 Google 的 Maven 代码库和 Maven 中央代码库:
buildscript {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
将 Play 游戏 SDK 的 Google Play 服务依赖项添加到模块的 Gradle build 文件
(通常为 app/build.gradle
)中:
dependencies {
implementation "com.google.android.gms:play-services-games-v2:+"
}
完成上述步骤后,您必须设置登录功能,游戏才能使用 Play 游戏服务功能。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Get started with Play Games Services for Android games\n\n| **Note:** This guide is for the Play Games Services v2 SDK. For information on the previous version of this SDK, see the [Play Games Services v1\n| documentation](/games/pgs/v1/android).\n\nThis guide describes how to set up an Android Studio project to use the\nPlay Games Services SDK. You must complete these steps before you\nset up Play Games Services [sign-in](/games/pgs/android/android-signin) and add\nPlay Games Services features to your game.\n\nBefore you begin\n----------------\n\nTo prepare your app, complete the steps in the following sections.\n\n### App prerequisites\n\nMake sure that your app's build file uses the following values:\n\n- A `minSdkVersion` of `19` of higher\n- A `compileSdkVersion` of `28` or higher\n\n### Set up your game in Google Play Console\n\nThe Google Play Console is where you manage Google Play games services for your\ngame, and configure metadata for authorizing and authenticating your game. For\nmore information, see\n[Set Up Google Play Games Services](/games/pgs/console/setup).\n\nConfigure your app\n------------------\n\nIn your project-level `build.gradle` file, include\n[Google's Maven repository](https://maven.google.com/web/index.html)\nand [Maven central repository](https://search.maven.org/artifact)\nin both your `buildscript` and `allprojects` sections: \n\n buildscript {\n repositories {\n google()\n mavenCentral()\n }\n }\n\n allprojects {\n repositories {\n google()\n mavenCentral()\n }\n }\n\nAdd the [Google Play services](https://developers.google.com/android)\ndependency for the Play Games SDK to your\n[module's Gradle build file](/studio/build#module-level), which is commonly\n\n`app/build.gradle`: \n\n dependencies {\n implementation \"com.google.android.gms:play-services-games-v2:+\"\n }\n\nAfter completing these steps you must set up\n[sign-in](/games/pgs/android/android-signin)\nin order for the game to access Play Games Services features."]]