Copyright (C) 2014 Google Inc.
These are the Android samples for Google Play game services.
-
ButtonClicker. 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.
-
TypeANumber. Demonstrates how to use leaderboards, achievements, events, and friends. 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). You can also check how your friends perform in this game by checking out social leaderboards.
-
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.
Warning: Real-time and turn-based multiplayer services are deprecated as of September 16th, 2019. These services are unavailable for new games. For more information, see Ending support for multiplayer APIs in Play Games Services.
-
Set up the project in the Developer Console by following these instructions. Note your package name and the application ID of the project!
-
For the Type a Number sample, you need to create leaderboards/achievements. (You can see the ones that the sample needs in its res/values/ids.xml file.) You can create them two ways:
- Add them via the Developer console.
- Use this utility, which will automatically create them for you.
- Open Android Studio and launch the Android SDK manager from it (Tools | Android | SDK Manager)
- Ensure the following components are installed and updated to the latest version.
- Android SDK Platform-Tools
- Android Support Repository
- Google Repository
- Return to Android Studio and select Open an existing Android Studio project
- Select the android-basic-samples directory.
To set up a sample:
- Change the applicationId in the build.gradle file to your own package name (ie - com.example.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.
- 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.
- If you are running Android Studio, check the TODO window to see if there are any remaining tasks.
- 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 like 'Failed to sign in. Please check your network connection and try again.'
To build the samples after you have applied the changes above, you can use the build/run option in Android Studio, or build directly from the command line if you prefer.IMPORTANT Ensure you have set the ANDROID_HOME environment variable.
cd /path/to/android-basic-samples
export ANDROID_HOME = /path/to/android/sdk
./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 regularly.
Samples written by Bruno Oliveira with contributions from Wolff.* Feel free to add us to your circles on Google Plus and pester us to fix stuff that's broken or answer a question on stackoverflow :-)
- To ligi for contributing the initial Gradle build files
- To bechhansen for fixing a bug in GameHelper where the turn-based match was being lost when a non-Games client connected.