Skip to content

AaronH88/android-samples

 
 

Repository files navigation

Google Play game services - Android Samples

Copyright (C) 2013 Google Inc.

Contents

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.

    • 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).

    • EndlessTunnel - a more complex sample that shows how to integrate Google Play Games into an NDK game written in C++.

    • 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.

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

  1. Set up the project in Developer Console. For more info:

    https://developers.google.com/games/services/console/enabling

    Note your package name and the APP ID of the project.

  2. 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.

If you're using Eclipse...

  1. Start Eclipse
  2. Import the Google Play Services library project (available for download through the SDK manager):
    1. Click File | Import | Android | Existing Android Code into Workspace
    2. Select SDK/extras/google/google_play_services/google_play_services_lib (where SDK stands for the path where you installed your Android SDK)
    3. Click Finish
  3. Import eclipse_compat/libraries/BaseGameUtils as a library
    1. Click File | Import | Android | Existing Android Code into Workspace
    2. Select the eclipse_compat/libraries/BaseGameUtils project
    3. Click Finish
    4. Right-click on BaseGameUtils, then click Properties
    5. In the project properties window, click the Android section
    6. Check the Is Library checkbox
    7. Add a reference to the google_play_services_lib project (click Remove to remove any broken references, then click Add to add the correct one)
  4. Import the desired sample from the eclipse_compat directory (Project | Import | Android | Existing Android Source)
  5. Go into the project properties window for that project (right-click, Properties) and check that this project has a reference to the BaseGameUtils project.

Your project should now compile. However, don't run it yet, since you still need to adjust your game's IDs in order for the sample(s) to work.

Now jump to the Modify IDs, compile and run section and continue to follow the instructions there.

If you're using Android Studio...

  1. Open Android Studio and launch the Android SDK manager from it (Tools | Android | SDK Manager)
  2. Check that these two components are installed and updated to the latest version. Install or upgrade them if necessary.
    1. Google Play Services
    2. Google Repository
  3. Return to Android Studio and select Import Project
  4. Select the BasicSamples directory
  5. Select "Import from existing model - Gradle"

Modify IDs, compile and run

To set up a sample:

  1. 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 manifest 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.
  2. 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 not 123456789012.apps.gooogleusercontent.com.
  3. 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:

  1. 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.
  2. Make sure TrivialQuest depends on BaseGameUtils
  3. Make sure BaseGameUtils depends on google-play-services_lib.
  4. 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)

Building

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

Support

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 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 :-)

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!

Special Thanks

  • To ligi for contributing the initial Gradle build files
  • To grantkemp for fixing the Eclipse compat build when we migrated to Gradle
  • To bechhansen for fixing a bug in GameHelper where the turn-based match was being lost when a non-Games client connected.

About

Google Play game services - Android samples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published