Google Play game services - Android Samples
Copyright (C) 2014 Google Inc.
These are the Android samples for Google Play game services.
BasicSamples - a set of basic samples, including a convenience library (BaseGameUtils):
BaseGameUtils. Utilities used on all samples, which you can use in your projects too. This is not a stand-alone sample, it's a library project.
ButtonClicker2000. Represents the new generation in modern button-clicking excitement. A simple multiplayer game sample that shows how to set up the Google Play real-time multiplayer API, invite friends, automatch, accept invitations, use the waiting room UI, send and receive messages and other multiplayer topics.
CollectAllTheStars2. Demonstrates how to use the Snapshots feature to save game data. The sample signs the user in, synchronizes their data from a named Snapshot, then updates the UI to reflect the game state saved in the Snapshot.
TrivialQuest2. Demonstrates how to use the Events and Quests features of Google Play Services. The sample presents a sign in button and four buttons to simulate killing monsters in-game. When you click the buttons, an event is created and sent to Google Play Games to track what the player is doing in game.
TrivialQuest. The simplest possible single-player game. Shows how to sign in and how to unlock one achievement. Sign-in and click the button to win the game. Are you ready for this epic adventure?
TypeANumber. Shows leaderboards and achievements. In this exciting game, you type the score you think you deserve. But wait! There is a twist. If you are playing in easy mode, you get the score you requested. However, if you are playing in hard mode, you only get half! (tough game, we know).
SkeletonTbmp A trivial turn-based-multiplayer game. In this thrilling game, you can invite many friends, then send a shared gamestate string back and forth until someone finishes, cancels, or the second-to-last player leaves.
BeGenerous Send gifts and game requests to other players of BeGenerous.
SavedGames. Demonstrates the used of Saved Games (Snapshots) feature and how to migrate data from the older Cloud Save (AppState) service to the newer service. The sample allows the user to save/load data from both Cloud Save and Saved Games.
Note: the samples that have corresponding counterparts for iOS and web (particularly, CollectAllTheStars and TypeANumber) are compatible across the platforms. This means that you can play some levels on CollectAllTheStars on your Android device, and then pick up your iOS device and continue where you left off! For TypeANumber, you will see your achievements and leaderboards on all platforms, and progress obtained on one will be reflected on the others.
Frequently Asked Questions
If you have questions about the samples (particularly, about BaseGameActivity and GameHelper), please take a look at our FAQ.
How to run a sample
Set up the project in Developer Console. For more info:
Note your package name and the APP ID of the project.
Create leaderboards/achievements as appropriate for the sample (see the ones that the sample needs in its res/values/ids.xml). You can do this automatically by clicking the link below for the sample you want to configure:
Building using Android Studio...
- Open Android Studio and launch the Android SDK manager from it (Tools | Android | SDK Manager)
- Check that these two components are installed and updated to the latest version. Install or upgrade
them if necessary.
- Android SDK Platform Tools
- Android Support Library
- Google Play Services
- Google Repository
- Return to Android Studio and select Import Project
- Select the BasicSamples directory
- Select "Import from existing model - Gradle"
Modify IDs, compile and run
To set up a sample:
- Change the application id in the build.gradle file to your own package name (the same one you registered in Developer Console!). You will have to update the build.gradle file for each sample you want to run. There is no need to edit the AndroidManifest.xml file.
- Modify res/values/ids.xml and place your IDs there, as given by the Developer Console (create the leaderboards and achievements necessary for the sample, if any). In the Developer console, select a resource type (Achievements, Events, Leaderboards) and click "Get Resources". Copy the contents from the console and replace the contents of res/values/ids.xml.
- Compile and run.
IMPORTANT: make sure to sign your apk with the same certificate as the one whose fingerprint you configured on Developer Console, otherwise you will see errors.
IMPORTANT: if you are testing an unpublished game, make sure that the account you intend to sign in with (the account on the test device) is listed as a tester in the project on your Developer Console setup (check the list in the "Testing" section), otherwise the server will act as though your project did not exist and return errors.
If you're using another build system...
If you are using your own build system, here is a summary of what you must do:
- Configure it to treat google-play-services_lib and BaseGameUtils as library projects, which means that not only their code but also their resources will also get added to the final build.
- Make sure TrivialQuest depends on BaseGameUtils
- Make sure BaseGameUtils depends on google-play-services_lib.
- Make sure the build system is signing the APK with the right certificate (the one whose fingerprint you provided in the Developer Console when creating your client ID)
To build the samples after you have applied the changes above, you can use the build/run option in Eclipse or Android Studio, or build directly from the command line if you prefer:
cd /path/to/BasicSamples ./gradlew build
First of all, take a look at our troubleshooting guide. Most setup issues can be solved by following this guide.
If your question is not answered by the troubleshooting guide, we encourage you to post your question to stackoverflow.com. Our team answers questions there reguarly.
Samples written by Bruno Oliveira. Feel free to add me to your circles on Google Plus and pester me to fix anything that's broken or answer a question on stackoverflow!