Copyright (C) 2013 Google Inc.
These are the Android samples for Google Play game services.
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.
CollectAllTheStars: Demonstrates a typical use of cloud save. In this challenging game, there are 20 worlds of 12 levels each. When you click on a level, it will ask you how many stars you think you deserve on it. Honesty required! This sample demonstrates how to deal with cloud save conflicts (for example, if you play some levels on your phone and a different set of levels on your tablet).
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).
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.
-
Set up the project in Developer Console. For more info:
http://developers.google.com/games/services
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)
Pick a set of instructions below depending on whether you're using Eclipse or Android Studio.
- Start Eclipse
- Import the desired sample (Project | Import | Android | Existing Android Source)
- Import the Google Play Services library project (available for download through the SDK manager). Make sure that the sample is REFERENCING the library project (Project Properties | Android | References)
- Import libraries/BaseGameUtils AS A LIBRARY Make sure that the sample is REFERENCING the library project (Project Properties | Android | References)
Now jump to the Modify IDs, compile and run section and continue to follow the instructions there.
- Open Android Studio and launch the Android SDK manager from it (Tools | Android | SDK Manager)
- Check that these two components are installed. Install them if they are not installed yet.
- Google Play Services
- Google Play Services Repository
- Go to the
build_scripts
directory and run thecopy_gradle_to_prj.sh
to copy the Gradle build files to the appropriate places in the directory tree. - Launch Android Studio
- Select Open Project (do not select "Import Project").
- Select the top-level directory (the one that contains
README.md
).
If this process does not work, you can also try importing the sources manually as described below.
Note: If you already have some experience with Android Studio, please forgive the verbosity of these instructions... since Android Studio is relatively new at the time of this writing, these instructions assume you're a newbie and try to be as specific as possible.
- Open Android Studio
- Make sure you're running the latest version of Android Studio. As of this writing, Android Studio is in alpha and evolving rapidly, which means that updating it to the latest version might just fix that mysterious bug that's blocking you :-)
- Select File | Import project
- Select the Google Play Services library project. It's usually a directory called
google-play-services_lib
in your SDK'sextras/google
directory. - Select the Create project from existing sources option, when asked.
- When asked which source directories to use, leave all of them selected (
/
,/gen
and/src
). - When asked which library to use, select only the ones in the
libs
directory. - Finish the import process.
- Click on the newly created module and press
F4
to bring up the module properties. - Select google-play-services_lib in the middle pane, expand it and go its Android sub-item
- Check the Library Module checkbox (very important!)
- Next, click File | Import Module (don't confuse with Import Project)
- Select the
libraries/BaseGameUtils
directory from the samples. - Import it exactly the same way you imported the other project just now (steps 5 to 11). Did you remember to check the Library Module checkbox?
- Now you should have two modules:
google-play-services_lib
andBaseGameUtils
- Click File | Import Module one more time.
- Select the directory of the sample you wish to import. For example,
TrivialQuest
. - Import it as in steps 5 to 11, but don't check the Library Module checkbox.
- Select the
BaseGameUtils
module, and pressF4
- In the Dependencies tab, click the green plus icon to add a new dependency. Select Module Dependency in the popup menu.
- Select google-play-services_lib in the box that appears.
- Now you are back to the Dependencies tab. Now, check the Export checkbox to the left of the newly added google-play-services_lib item.
- Look at the leftmost list in this window, under Project Settings. Click on the Libraries item.
- Make sure you see google-play-services and android-support-v4 in the middle pane. If not, something went wrong.
- Now, go back to the Modules pane (click on the Modules item in the leftmost list box).
- Select BaseGameUtils in the middle pane.
- Click the green plus icon to add a library. Select Library in the popup menu.
- Select the google-play-services library in the box that appears.
- Click the green plus icon to add a library. Select Library in the popup menu.
- Select the android-support-v4 library in the box that appears.
- Check the Export checkbox next to android-support-v4
- Check the Export checkbox next to google-play-services_lib
- Check the Export checkbox next to google-play-services
- Select TrivialQuest in the middle pane.
- Click the green plus icon to add a dependency. Select Module dependency in the popup menu.
- Select the BaseGameUtils module.
- Don't check the Export* checkbox.
- Close this window.
Continue below.
- Change the package name from com.google.example.games.* to your own package name (the same one you registered in Developer Console!). To do that, open AndroidManifest.xml and put your package name in the "package" attribute of the tag. You will need to fix some of the references (particularly to the generated R class) because of the package name change. Ctrl+Shift+O in Eclipse (and Alt+Enter in Android Studio) should take care of most of the work.
- 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). Remember that the App ID is only the numerical portion
of your client ID, so use
123456789012
and not123456789012.apps.gooogleusercontent.com
. - 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 you're signing in with an account that's listed as a tester in the project on Developer Console, otherwise the server will act as though your project did not exist.
If you are using your own build system, here is a summary of what you have to 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)
First of all, take a look at our (hopefully) thorough troubleshooting guide. In our experience, 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 stuff that's broken or answer a question on stackoverflow :-)