Saturday 19 October 2013

LibGDX Google Play Game Services Tutorial


Google Play Game Services offers cross platform social leaderboards, achievements, and much more (realtime multiplayer, cloud saves, anti-piracy...). I've started implementing google play game services leaderboards and achievements in my LibGDX Android Games, and the purpose of this blog article is to walk through the process so you can do the same!

  • I've published an example project on Google Play check it out!
  • The example project is freely available on GitHub check that out too!
  • You can also get the complete (free) version of Super Jump a Doodle here!

Continue reading after the jump to find out how to add these features to your own games!



Google Play Developer Console Setup


Before we can start making any changes to our app, we first need to work our way through the required developer console setup.

Go to https://play.google.com/apps/publish, and click the Game Services menu option (gamepad icon)


Click 'Add New Game', fill in the required name and category details, then continue


Fill in the required game details, upload the required graphic assets, then continue to linked apps


Link an android app, add your package name (must match your app), then save and continue


Click authorise your app, fill in the package and SHA1, then create client. Note that the SHA1 is presented in eclipse when building your release apk if you are using an up to date version of the eclipse adt plugin. If using an older version of the adt plugin, you can find your certificates SHA1 by running the following shell command “keytool -list -v -keystore ReleaseKey.keystore -keypass android” (note that 'ReleaseKey.keystore' needs to be the full path to your certificate keystore file)


You have to create a minimum of 5 achievements, so go ahead and do so...


Make a note of the IDs, we'll be needing them later


A leaderboard is usually a nice touch, so let's create one of those too


Again, make a note of the ID, we'll need it later


Provided all required fields have been completed, and the required graphic assets uploaded, we can finally publish the Google Play Game Services settings. Do this, and make a note of the App ID, this will be needed later too!



LibGDX App Setup in Eclipse


Copy the BaseGameUtils and google-play-services_lib directories from the example project on GitHub and save them somewhere locally. Now import both these existing projects into Eclipse, right click the project folders in package explorer, properties > android, then tick the “Is Library” box. The libraries should now be available to the other projects in your workspace. Finally, import your LibGDX projects (core, android and desktop).

Right click the android project in package explorer:

  • Android, in the Library section Add > BaseGameUtils > OK, Add > google-play-services_lib > OK, Apply.
  • Properties > Java Build Path, Projects tab, add both BaseGameUtils and play-game-services_lib projects, then ok twice to save and close.

Open AndroidManifest.xml, and add two permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

You will also need to add the following element as a child to application:
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id" />

Edit your android project's res/values/strings.xml, add the following element as a child to resources:
<string name="app_id">796047314795</string> 

Note you will need to change the app_id value to whatever your app_id is... The number will have been presented to you in the Google Play Developer Console.

You most likely already have an ActionResolver interface in your core project, if you do, add the Google Play Game Services related methods below. If you don't already use an ActionResolver interface, now's a good time to add one:

package com.theinvader360.tutorial.libgdx.gameservices;

public interface ActionResolver {
  public boolean getSignedInGPGS();
  public void loginGPGS();
  public void submitScoreGPGS(int score);
  public void unlockAchievementGPGS(String achievementId);
  public void getLeaderboardGPGS();
  public void getAchievementsGPGS();
}

Edit your android project's MainActivity. Have it implement GameHelperListener and ActionResolver, and add the unimplemented methods. Add a GameHelper field to the class, and a default constructor that instantiates it. For full detail, take a look at the example project. Note if you're copying this implementation you need to remember to swap the leaderboard ID to the ID in your Google Play Developer Console, personally I prefer to shift all the ID's to a single Constants class, but didn't do that in the example project as I tried keeping it as simple as possible, and with the minimum of change from the standard Super Jumper Demo.

You will also need to add the relevant methods to your Desktop projects ActionResolver mock implementation, again for an example see the example project.

Now all that's left to do is call the relevant ActionResolver methods from your game at appropriate times...

At gameover, for example, you might call the following (remember to swap the ID's to match those in your Google Play Developer Console!):

if (game.actionResolver.getSignedInGPGS()) {
 game.actionResolver.submitScoreGPGS(world.score);
 if (world.score >= 100) game.actionResolver.unlockAchievementGPGS("CgkI6574wJUXEAIQAQ");
 if (world.score >= 200) game.actionResolver.unlockAchievementGPGS("CgkI6574wJUXEAIQAg");
 if (world.score >= 300) game.actionResolver.unlockAchievementGPGS("CgkI6574wJUXEAIQBA");
 if (world.score >= 400) game.actionResolver.unlockAchievementGPGS("CgkI6574wJUXEAIQBQ");
 if (world.score >= 500) game.actionResolver.unlockAchievementGPGS("CgkI6574wJUXEAIQBg");
}

Or on the menu screen you might call:

if (game.actionResolver.getSignedInGPGS()) game.actionResolver.getLeaderboardGPGS();
else game.actionResolver.loginGPGS();

or

if (game.actionResolver.getSignedInGPGS()) game.actionResolver.getAchievementsGPGS();
else game.actionResolver.loginGPGS();


That's all there is to it! Now all you need to do is build your apk (note Google Play Game Services will only work correctly if you build using the same certificate as the one you set in the Developer Console, so do a full release build and manually deploy to your device, don't just right click > run as > android application), drop the apk on your device, install, and play :)

----------

Note it is possible that I may have skipped a little detail in this article. If you have any problems, I would suggest that you follow the first section (Google Play Developer Console Setup), git clone https://github.com/TheInvader360/libgdx-gameservices-tutorial.git, build a release apk, drop it on your device, and have a play. The example project is wide open and should be pretty self explanatory, feel free to use and abuse it in any way you see fit!

----------

Update: If you want to work with the latest version of googleplay game services...
  • Using the Android SDK Manager, download the latest API version (API19)
  • Replace the old google-play-services_lib directory in workspace root with the new version (available at <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib).
  • Replace the old BaseGameUtils directory in workspace root with the new version from my github project - https://github.com/TheInvader360/libgdx-gameservices-tutorial/tree/master/BaseGameUtils. Alternatively, you can grab the latest version from the eclipse_compat/libraries/BaseGameUtils/ dir of the playgameservices android-samples repository (git clone https://github.com/playgameservices/android-samples.git) but please keep in mind that things change over time so the latest and greatest version might need some code changes on your part to get things working again. Probably easier to stick with the version in my github project if you are following this walkthrough and want an easy life :)
  • Delete google-play-services_lib and BaseGameUtils projects from eclipse package explorer, then import existing android code to add the new versions.
  • Right click the BaseGameUtils project and on the Android tab tick Is Library, and add reference to google-play-services_lib, apply.
  • Right click the libgdx android project and correct the Java Build Path if there is a problem (remove and re-add BaseGameUtils), and again on the Android tab if there is a broken reference to BaseGameUtils, apply.
  • Set AndroidManifest minSdkVersion to 9 targetSdkVersion to 19
  • Add <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> as a child of application in AndroidManifest.xml
  • Refresh and clean.
  • Make these changes to the android project's MainActivity class - https://github.com/TheInvader360/libgdx-gameservices-tutorial/commit/a5c36953b3b51c4f0dd9ea3f8606061cf2ec3fc4



117 comments:

  1. Thanks . I have followed your example but I just installed the application service game but not publish to Google Play Store. Does this cause problems for my application?

    ReplyDelete
    Replies
    1. Hi Bang,

      You need a google play account to access the google play game services console and carry out the setup as described in this article.

      You do not however have to publish your game on the google play market. During testing for example, I will build the apk (release version) and simply transfer to my device over usb and install. This allows me to confirm all the gpgs functionality before actually releasing the game on google play.

      Hope this helps! :)

      Delete
  2. Can you help me with my problem?

    I added BaseGameUtils and lay-game-services_lib as you told but when I want to deploy the app on my phone, Eclipse shows me an error after installing the app:

    [2014-01-22 13:03:06 - BaseGameUtils] Could not find BaseGameUtils.apk!
    [2014-01-22 13:03:06 - google-play-services_lib] Could not find google-play-services_lib.apk!

    These lines are red in Eclipse. And as I said, the app is actually installed on my phone.

    ReplyDelete
    Replies
    1. When importing, did you tick the “Is Library” box? Is your build path set correctly? Can you try refreshing project, cleaning workspace, then building a fresh apk and try again on your device? How about deleting from your worspace, reimporting, and going from there? If all that fails, can you grab my example project from github and successfully build and run that for your device?

      I don't really have enough free time to offer proper 'support' for my tutorials, but hopefully something here might help you solve your problem. If not, a good place to look for solutions would be http://stackoverflow.com. Good luck :)

      Delete
    2. Thanks! Your're right, I forgot to uncheck the "Is library" box, stupid me :) So now I can install my app with the refernced projects. But there is the next problem: As soon I implement GameHelperListener and the methods onSignInFailed() and onSignInSucceeded() the game crashes before starting and logCat shows the following:

      01-22 17:56:22.529: E/AndroidRuntime(4388): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.theinvader360.tutorial.libgdx.gameservices/com.theinvader360.tutorial.libgdx.gameservices.MainActivity}: java.lang.01-22 17:56:22.529: E/AndroidRuntime(4388): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.theinvader360.tutorial.libgdx.gameservices/com.theinvader360.tutorial.libgdx.gameservices.MainActivity}: java.lang.ClassNotFoundException: com.theinvader360.tutorial.libgdx.gameservices.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.theinvader360.tutorial.libgdx.gameservices-1.apk]
      : com.theinvader360.tutorial.libgdx.gameservices.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.theinvader360.tutorial.libgdx.gameservices-1.apk]

      So a ClassNotFoundException. But why? It doesn't make sense to me. Would be cool if you had some ideas.

      And thanks again!

      Delete
    3. Hi, git doesn't track empty directories (I learnt something new today!) I've added a .keep file to the BaseGameUtils/res directory, and that should solve the problem you were experiencing. Sorry for the headache caused by this, and thanks for pointing out the issue. It had gone unnoticed as I'd not done a fresh clone of my own and had always retained my res directory locally. You can either add the empty res dir to your BaseGameUtils project, do a git pull, or clone again from scratch. Cheers :)

      Delete
  3. Hi, thanks for the tutorial!

    How can I add the utton that links the leaderoard ?

    ReplyDelete
    Replies
    1. Request the leaderboard through the ActionResolver:

      if (game.actionResolver.getSignedInGPGS()) game.actionResolver.getLeaderboardGPGS();

      See here:
      https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices/src/com/theinvader360/tutorial/libgdx/gameservices/MainMenuScreen.java

      If your question is actually how to use real buttons, not the quick and dirty touch bounds in my example, you should look into Scene2D UI, it's great.

      Delete
  4. Hi I have imported the projects but i am getting an error on the Android project, It states that there is missing basegameutil.jar from the buildpath.. I have checked the libs folder and it isn't there.. Sorry newbie to this.. Where can i locate the jar file Thanks
    Daniel

    ReplyDelete
    Replies
    1. Hi Dan

      It's in the bin directory of the BaseGameUtils project.

      Since I have very little free time I can't offer 1-to-1 support. My suggestion would be to clone the example app I've put on github and see if you can spot the difference between that and your app to see what's causing the problem :)

      https://github.com/TheInvader360/libgdx-gameservices-tutorial

      Hope this helps :)

      Delete
  5. Hi, I am getting the same issue as above.. the app keeps crashing out and can't find the main activity.. any ideas as to why this happens?

    Thanks

    ReplyDelete
    Replies
    1. Hi, git doesn't track empty directories (I learnt something new today!) I've added a .keep file to the BaseGameUtils/res directory, and that should solve the problem you were experiencing. Sorry for the headache caused by this, and thanks for pointing out the issue. It had gone unnoticed as I'd not done a fresh clone of my own and had always retained my res directory locally. You can either add the empty res dir to your BaseGameUtils project, do a git pull, or clone again from scratch. Cheers :)

      Delete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. Hi Invader,
    Sorry to but you even though you stated you have no time.. please excuse me..
    I have created a new project from libGDX setup-ui and done a complete new install on this simple project. I am still getting the same error. It can't locate the mainActivity.. have you left any vital steps off the tutorial by mistake by any chance? sorry to bother you about this, i am just really looking to get this to work.. Best

    Daniel

    ReplyDelete
    Replies
    1. Hi Daniel

      Please forget about new projects using setup-ui for now. I've just done the following on a new machine, and the example app runs on my device without issue...

      terminal:
      cd ~/Workspaces/android/tutorial
      git clone https://github.com/TheInvader360/libgdx-gameservices-tutorial.git

      eclipse:
      file > import
      existing projects into workspace > next
      root directory > ~/Workspaces/android/tutorial > finish
      project > clean > all > ok
      right-click android project > run as > android application

      I get an error when trying to load google play game services (tap highscores/achievements in menu or start a new game), but that's to be expected as I've not signed the apk. The app does not crash, no error locating mainActivity.

      Can you please try running through this process and confirm whether or not it works for you as a first step? Then we can move on to a new app using setup-ui.

      Thanks :)

      Delete
  8. Hi Invader thanks for taking the time to reply,

    I have run your app from within eclipse on a vitual machine and all is good as described which is great, I did however notice that it could not locate the BaseGameUtils.apk, it did launch though and stated it could not launch Google game services. So yeah i have no ideas as to why it was not previously working like this and apologise for the harassment ;) .

    So i am guessing that if i follow your tutorial now it will work.. :)

    Best

    Daniel

    ReplyDelete
  9. Ha I think i have cracked it! Thank you for your time on this.. there is one part i would recommend adding which resolved this issue for me. Right click on your Android project - Properties>Android> click 'add', then add BaseGameUtils and GoogleGameServices.

    Many Thanks for the great tutorial and keep up the good work. All the best for the future. Daniel

    ReplyDelete
    Replies
    1. Ha I was investigating same time as you and was just about to get in touch to let you know! We spotted the same omission, article has been updated :)

      Delete
  10. Hi I have managed to get it to launch and to ask one to sign in, but it then give 'Unknown error'
    Don't suppose you have any suggestion as to why this is?

    thanks

    ReplyDelete
  11. Replies
    1. Fantastic I'm glad to hear it :) Looking forward to checking out your finished app!

      Delete
    2. Hi Dan, I am getting the "Unknown error" in mine and the test project. The desktop project works fine with the message "loginGPGS".
      What change did you make for this. Thanks for the help.

      Delete
    3. Got it sorted, I had not added the user for alpha testing on play store. You have to add the user in alpha testing mode only then it logs in.

      Delete
    4. Thanks for the update Ranvijay, this info could help others that might experience the same issue :)

      Delete
  12. All I can suggest is that you double check all your id's and package name etc match those in google play api console and that you build a signed apk using the same certificate (don't just right-click run as android application).

    ReplyDelete
  13. When I import the BaseGameUtils I have a whole bunch of errors. Why is that?

    ReplyDelete
    Replies
    1. Sorry, but with so little information "why" is impossible to answer.

      Try this: Download and extract https://github.com/TheInvader360/libgdx-gameservices-tutorial/archive/master.zip, in an empty/new workspace in eclipse file > import> general, existing > next > *extracted zip dir*, ok, finish... Wait for the workspace to build. There should be zero errors. If there are, it's likely an environmental issue your end that I can't help with. Check the problems tab in eclipse for clues, also it never hurts to refresh and clean regularly, that often fixes phantom errors for me (eclipse sometimes reports errors when there are none!)

      Good luck, I hope you get your issue sorted :)

      Delete
  14. can you show us how to add admob ads thanks
    caleb

    ReplyDelete
    Replies
    1. Sure...https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx
      :-)

      Delete
    2. I recently blogged about this subject - http://theinvader360.blogspot.co.uk/2014/04/libgdx-google-mobile-ads-sdk-tutorial.html

      It's pretty similar to my previous link, but uses the new Google Mobile Ads SDK. The old way of doing things is deprecated now.

      Delete
    3. So invader .. when you say deprecated. Does that mean you cannot use the old admob way of doing things anymore?

      Delete
    4. Its not recommended, shutting down 1st august so the clock is ticking! https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#android I've got another blog post on here that walks through the switch to Google mobile ads sdk, just need to find the time to do so in my live apps now!! http://theinvader360.blogspot.co.uk/2014/04/libgdx-google-mobile-ads-sdk-tutorial.html

      Delete
    5. Thanks invader. Problem is i tried using the updated google play game sercices and it doesnt work. So can you use the old game services and use the new google ads sdk?

      Delete
    6. Could you show how to use the new google play game services?

      Delete
    7. I've not had the time to look into it yet, real life is chaos. Sébastien Laoût has added comments to this article explaining how he moved to the new google play game services. I plan to write a blog post soonish on upgrading to LibGDX 1.0 and the latest Google Play Game Services and the Google Mobile Ads SDK, but that'll be after I've run through the process myself, probably a few weeks away. Hopefully in the meantime Sébastien Laoût's comments will be enough for you to get it worked out.

      Delete
  15. Same as Magnus Beck, when i imported BaseGameUtils, "GameHelper" class has 20934893849errors, cleaning up and refreshing wont fix it, i just imported BaseGameUtils,i didnt import the whole project and everything, wtf is going on?

    ReplyDelete
    Replies
    1. 20934893849 errors? :-/

      If I import BaseGameUtils I have two errors listed in the problems perspective, first missing required project google-play-services_lib, and second cannot build until errors are resolved.

      Import google-play-services_lib, wait form workspace to refresh and rebuild, all problems disappear.

      If you are having problems, and others are not, that suggests the problem lies your end and I can't help any further. Read some of the error messages and see if you can get a hint as to what is wrong. There are sources of support out there that will help more than I can. Try stackoverflow, android developers, libgdx forums/irc, etc. Good luck!

      Delete
  16. I just copied your versions into my game and it worked perfectly. Thank you for the Google play services help. You rock man.

    ReplyDelete
  17. Thanks for the tutorial.
    I followed the example project and incorporated the code into mine but i have errors.

    In the following snippet, Eclipse tells me that GameHelper(MainActivity) is undefined and suggest to add an argument to match GameHelper(Activity, int)...
    public MainActivity() {
    gameHelper = new GameHelper(this);
    gameHelper.enableDebugLog(true, "GPGS");
    }

    In this snippet, Eclipse tells me that the method getGamesClient() is undefined for the type GameHelper...
    @Override
    public void unlockAchievementGPGS(String achievementId) {
    gameHelper.getGamesClient().unlockAchievement(achievementId);
    }

    Can you help me?

    ReplyDelete
    Replies
    1. Clearly both are defined: https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/BaseGameUtils/src/com/google/example/games/basegameutils/GameHelper.java

      Are the google projects marked 'is library'? Build paths OK? If you clone my example project, any issues? Best suggestion other than liberal refreshing and cleaning in eclipse would be to run through the tutorial carefully from 'LibGDX app setup in eclipse' heading, since others can get this working without issue by following the tutorial it is likely that you missed a step or have a local environmental issue, neither problem I can help with. Good luck! :-)

      Delete
    2. oops.. i imported the basegameutils from google, instead of the one provided here... they are slightly different.. the issue is now resolved.. tyty

      Delete
    3. Awesome :) I won't be continually updating this tutorial (sadly I don't have the time). Might be worth looking into what google have changed though, thanks for the heads up :)

      Delete
    4. I'm currently applying this tutorial with the latest version of GameHelper from Google.

      For the first error, it was easy:

      gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
      gameHelper.enableDebugLog(true);

      You can use these flags:

      CLIENT_NONE
      CLIENT_GAMES
      CLIENT_PLUS
      CLIENT_APPSTATE
      CLIENT_ALL = CLIENT_GAMES | CLIENT_PLUS | CLIENT_APPSTATE;

      Now, let's tackle the second error...

      Delete
    5. OK, for the second problem, here is what I've done:

      Replaced:

      gameHelper.getGamesClient().submitScore(scoreId, score);

      By:

      Games.Leaderboards.submitScore(gameHelper.getApiClient(), scoreId, score);

      It compiles on Eclipse.
      I did not tested it yet, but I post now or I'm capable of forgetting to post that solution later :-)

      And also:

      import com.google.android.gms.games.Games;

      //gameHelper.getGamesClient().unlockAchievement(achievementId);
      Games.Achievements.unlock(gameHelper.getApiClient(), achievementId);

      //startActivityForResult(gameHelper.getGamesClient().getLeaderboardIntent(scoreId), 100); startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), scoreId), 100);

      //startActivityForResult(gameHelper.getGamesClient().getAchievementsIntent(), 101);
      startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 100);

      Delete
    6. Awesome thanks for sharing Sébastien :-)

      Delete
    7. Well, it is actually tougher because I get a NullPointerException when instantiating the GameHelper because they modified the constructor:

      public GameHelper(Activity activity, int clientsToUse) {
      mActivity = activity;
      // NEW LINES:
      mAppContext = activity.getApplicationContext(); // THIS ONE GIVES NullPointerException
      mRequestedClients = clientsToUse;
      mHandler = new Handler();
      }

      The NullPointerException is because getApplicationContext() is:

      class ContextWrapper {
      ...
      public Context getApplicationContext() {
      return mBase.getApplicationContext(); // mBase IS NULL HERE
      }

      I'm currently only working a few minutes at a time on my project. I have to go. I will keep you posted when I have solved the problem.

      Delete
    8. OK, I fixed the NullPointerException:

      Remove the GameHelper instantiation in the constructor and move it at the very end of onCreate(Bundle):

      if (gameHelper == null) {
      gameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES);
      gameHelper.enableDebugLog(true);
      }
      gameHelper.setup(this);

      Also, in order to avoid a "java.lang.IllegalStateException: GoogleApiClient must be connected." when the user in not connected and clicked to show leaderboard or achievements screen, I wrapped the code like this:

      @Override
      public void showLeaderboardScreenGPGS(String scoreId) {
      if (gameHelper.isSignedIn()) {
      startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), scoreId, 100);
      } else if (!gameHelper.isConnecting()) {
      loginGPGS();
      }
      }

      @Override
      public void showAchievementsScreenGPGS() {
      if (gameHelper.isSignedIn()) {
      startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 100);
      } else if (!gameHelper.isConnecting()) {
      loginGPGS();
      }
      }

      Delete
    9. Oh man you have SAVED me such a damned headache!

      I had the game about 90% complete until I read that in 3 months everything was obsolete, spend most of the day sorting this and the ads out and it's now all done.

      Just device testing to go.

      Thanks for the article and thank you kind sir for the tip!

      Delete
    10. thank you Sébastien Laoût

      Delete
    11. OK, I'm usually reluctant to spam blogs with links, but you ended your article asking for game links... So, here I am ;-)

      I'm finally at a stage where I can start to publicly show previews of my game.

      Here it is:
      http://www.snaky360.com/sheet.php?p=snaky_360
      (the text is still French, but screenshots are language agnostic and the game is translated to English)

      If anyone is interested, ask me to become a beta tester...

      Delete
    12. Hey sebastien, can you elaborate a bit more on how you fixed the nullpointer? Sorry about that, I'm a beginner and also have this problem.

      Delete
    13. OK, tell me what part of my previous post you don't understand or can't apply in your case?

      ("Remove the GameHelper instantiation in the constructor and move it at the very end of onCreate(Bundle)")

      Delete
    14. Sorry about that, I've fixed it now.

      Delete
  18. That's nice tutorial . I am done with the stuff ,all working good.

    I am just wondering what method should i call to display the welcome message (Welcome + username) everytime user enters the game. Generally we can see it the first time login is completed .
    cheers

    ReplyDelete
    Replies
    1. Awesome I am glad to hear that :-)

      I think the method you're looking for is game.actionResolver.loginGPGS()

      Delete
  19. Hey Invader, thanks for the tutorial, here's the game I made, integrated with google play game services:

    https://play.google.com/store/apps/details?id=great.nomadic.seal.HungrySeal

    Thanks again, good stuff :)

    ReplyDelete
    Replies
    1. Cool :) Thanks for the link to your game, I'll check it out soon!

      Delete
  20. Hey invader. Thanks for the tutorial, it is awesome.

    However i'm having a problem, I always get false from getSignedInGPGS(), so I could never see the leaderboards. Do you know what may be causing this??

    Thank you!

    ReplyDelete
  21. Hey invader awesome tutorial! except i have this error i cant my head around.

    from lines like this:
    gameHelper.getGamesClient().unlockAchievement(achievementId);

    i get the error:
    The method getGamesClient() from the type GameHelper refers to the missing type GamesClient

    please help me!

    ReplyDelete
    Replies
    1. Are you using the google libraries from my github project? Newer versions won't work with this tutorial without some modification (I've not looked into updating so don't know what's involved). Any helpful hints in the problems view in eclipse?

      Delete
    2. Hello Invader. Is there a way to use the newer version of google libraries? The tutorial is perfect until the error in getGamesClient(). I can't use your google library because my admob ad is not working on that one. Thank you!

      Delete
    3. See another comment by Frederic Smith below:

      Thanks for the tutorial, I managed to use a part of it to integrate the new Google Game Services in my game.
      The main things that need to be modified are:
      - the construction of the Game Helper.
      - the methods unlockAchievementGPGS, getLeaderboardGPGS, getAchievementsGPGS and submitScoreGPGS.

      I'll update this tutorial when I get some time, but who knows when that'll be. In the meantime I'll leave it as an exercise to the reader!

      Delete
    4. Thanks Invader for the reply. I already got it using new Google play services. If you have time try my app. Thanks again! https://play.google.com/store/apps/details?id=com.viralsoft.RocketBoost

      Delete
    5. Awesome, I will check out your game tonight :-)

      Delete
  22. just integrated leaderboard and achievements by following your tut. Please have a look of my game:
    https://play.google.com/store/apps/details?id=com.onethumbgames.paperboatrun2

    ReplyDelete
    Replies
    1. Excellent, thanks for sharing Imtiaj :) I have installed your app and will have a play later this evening :D

      Delete
  23. Hi there !

    Thanks for the tutorial, I managed to use a part of it to integrate the new Google Game Services in my game.
    The main things that need to be modified are:
    - the construction of the Game Helper.
    - the methods unlockAchievementGPGS, getLeaderboardGPGS, getAchievementsGPGS and submitScoreGPGS.


    Here's my game:
    https://play.google.com/store/apps/details?id=com.novaprods.ultimaball

    Regards!

    ReplyDelete
  24. You helped me out bigtime.

    Below the link to my game:
    https://play.google.com/store/apps/details?id=com.crackedworldstudios.Sinkhole

    ReplyDelete
    Replies
    1. Thanks for posting :) That's a nice looking game, do you mind me asking who does your artwork? The style is perfect for something I've been mulling over for a while...

      Delete
  25. Thanks for this tutorial theinvader360, also thank you Sébastien Laoût for your comments..

    ReplyDelete
  26. Thank you!
    Your tutorial help me create my first game:
    https://play.google.com/store/apps/details?id=com.platform.game

    ReplyDelete
  27. Hey Invader, Thanks for the great tutorial, but i have quick question.
    How do i hide the circle progress bar??. I notices it shows quickly when i start my app.
    and it shows when signing in to google pla.

    ReplyDelete
    Replies
    1. Hi Brandon, not sure that's possible without at least messing with the google library. I'm afraid I don't have the time to look into it these days but a good place to start looking might be https://github.com/playgameservices

      Delete
    2. Alright so i found the solution. If anyone else doesnt want the circle progress bar to be showing cause it looks kinda ugly. Go into the GameHelper class. Then go into the beginUserInitiatedSignIn() method and delete the call to the showProgressDialog() method.

      Delete
  28. Have you got an idea of why this error occurs on my project ?

    06-13 23:11:32.981: E/Volley(4154): [272] tk.a: Unexpected response code 403 for https://www.googleapis.com/games/v1/players/115171141636978128288
    06-13 23:11:33.071: E/SignInIntentService(4154): Access Not Configured. Please use Google Developers Console to activate the API for your project.

    ReplyDelete
    Replies
    1. If I got an error message like that, I'd double check my setup in the Google play developer console. Some people find they have to setup a test device there, though I've never needed to do that personally.

      Delete
  29. Hey Everyone. I finally finished my game. So heres the link.
    https://play.google.com/store/apps/details?id=com.piixel.TapTheRightColor
    I want to also thank you invader for all the help, as well as Sébastien Laoût.
    Please share the game and give feedback, Thanks

    ReplyDelete
    Replies
    1. I love a good minimalist game - fun and challenging without the need to look flashy. Nice job :-)

      Delete
  30. Hey, fun :-) I'm first! Not for so long, I'm afraid ;-) Good idea: it's very simple to grab but hard to win!

    ReplyDelete
  31. hey it would mean the world if you would all share it on your social media .. lets make it the next flappy bird lol

    ReplyDelete
  32. Hello Invader, thanks for this tutorial. I'm quite new in Libgdx as well as in java programming, and I really learned a lot from this. However, I have a small question, I always get this on my console:

    [2014-06-23 01:13:35 - google-play-services_lib] Unable to resolve target 'android-10'
    [2014-06-23 01:13:40 - BaseGameUtils] Unable to resolve target 'android-10'
    [2014-06-23 01:13:40 - google-play-services_lib] Unable to resolve target 'android-10'

    Because of this, I got error on "UnusedStub" class. Do you know the solution to get rid of this? Is it on my installed sdk or libraries? Hope you can reply. Thanks a lot! =)

    ReplyDelete
    Replies
    1. Hi Jerald

      First thing I'd try is checking that android sdk 10 is installed (android 2.3.3) in android sdk manager.

      You could also try changing the min/target sdk in androidmanifest.xml

      Delete
    2. Hey! thanks a lot for immediate response, really appreciate it! =) Tried installing the sdk 10 and fixed the errors. However, I got this another error:

      The container 'Android Dependencies' references non existing library 'C:\Users\Jerald\Desktop\libgdx-gameservices-tutorial-master\BaseGameUtils\bin\basegameutils.jar'

      This proj is the one I've downloaded to your link, I think I need to analyze first this project before implementing on my own proj. I wonder you might know the solution for this. Any feedback will be greatly appreciated. Thanks so much!

      Delete
    3. Already figured it out! I messed up my library on that case. =) Already runned the program on android phone, but when I press the highscore and achivement, it will connect to google play services, but resulting to unknown error. Is that normal on that tutorial project?

      Delete
    4. Cool, at this point you will need to do the setup in Google play developer console, set the id's in your app to match your developer console values, do a signed build, and possibly add your device as a test device (I don't have to do this, but some commenters did have to). If you follow the developer console setup steps in the tutorial above you should be fine :-)

      Delete
  33. Hi Invader.
    I have managed to publish my game.
    Thanks for the blog which made GPGS real breeze to implement.
    Here is the link to my game, hope you like it:
    https://play.google.com/store/apps/details?id=com.wahwah.WordingGame

    ReplyDelete
  34. Hey TheInvader360,

    Thanks heaps for the tutorial, helped me a lot with implementing google play services.
    Like the others I think I'll post you a link of my first game for you to check out when you're free.
    https://play.google.com/store/apps/details?id=com.TomosanStudios.FudoDog

    ReplyDelete
  35. I have been having problems since the new sdk has been released. I have followed your instructions in the update bit at the bottom of your post and the problem is with GameHelper in the new BaseGameUtils.

    It says the import com.google.example.games.basegameutils.GameHelper; can not be resolved and it has caused a lot of errors in the android project. It also means that this has a red underline too. com.google.example.games.basegameutils.GameHelper.GameHelperListener;

    Any help would be immensely appreciated.

    ReplyDelete
  36. Hi infernox. Sounds like a build path problem to me. Right click google-play-services_lib project, properties, android, ensure Is Library is ticked. Right click BaseGameUtils project, properties, android, ensure Is Library is ticked, and google-play-services_lib project is listed with a green tick alongside it. Right click android project, properties, android, ensure BaseGameUtils and google_play_service_lib are listed in the library panel with green ticks alongside both. Right click android project, properties, java build path, ensure BaseGameUtils is in the Projects tab. That will hopefully solve your problem! :)

    ReplyDelete
    Replies
    1. I fixed it already. The problem was that you have linked to 2 different BaseGameUtil files and I downloaded the wrong one. The link in the update bit at the end (the playgameservices link) is the wrong one. I just had to delete that one and use the one in your updated tutorial github.

      Delete
  37. The version at https://github.com/playgameservices/android-samples.git is no longer working? I guess that's the problem with this stuff moving quickly! Thanks for the heads up, I'll add a note to the end of the article that either you get the latest and greatest from the official playgameservices project and make the required code changes to deal with it (I can't update every time they make a change that breaks things), or grab the snapshot from my github project and follow this walkthrough with no extra hassle. Cheers!

    ReplyDelete
    Replies
    1. hi, im new to Libgdx..
      i want to implement the game service in libgdx ..
      i try to follow your tutorial but suddenly i encounter an error in BasicGameUtils/bin is missing

      Delete
  38. Hi there, This is the first time I am using game Service and Libgdx. and it is frustrating that there is not much proper tutorials and directions there for starters. So far yours is the best i have found. I have followed your steps and everything is fine till implementing GameHelperListener, ActionResolver in AndroidLauncher. However, as u know in libgdx there are separate projects for different platforms, and all the game classes for gameover and mainmenu resides in Core project. So how do i call ActionResolver methods there? Would really appreciate if you could explain. Thank you

    ReplyDelete
    Replies
    1. Hi Deeyo

      Create ActionResolver interface in the core project: https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices/src/com/theinvader360/tutorial/libgdx/gameservices/ActionResolver.java

      ActionResolverDesktop implementation in the desktop project: https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices-desktop/src/com/theinvader360/tutorial/libgdx/gameservices/ActionResolverDesktop.java

      MainActivity implements GameHelperListener and ActionResolver in android project: https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices-android/src/com/theinvader360/tutorial/libgdx/gameservices/MainActivity.java

      Call ActionResolver methods from the core project (examples - https://github.com/TheInvader360/libgdx-gameservices-tutorial/blob/master/tutorial-libgdx-gameservices/src/com/theinvader360/tutorial/libgdx/gameservices/GameScreen.java). The calls will be delegated to the relevant ActionResolver implementation depending on what platform you are running.

      Do not call GameHelperListener methods from the core project, only the android project - Google Play Game Services only work on mobile devices. If you take a look at the ActionResolverDesktop implementation all it does is print to console to let you know that GPGS methods would have been called, which can be helpful. The GameHelperListener methods are platform specific and are irrelevant on the desktop platform.

      Hope this helps!

      Delete
  39. Hi,

    Im having some issues with the leaderboard displaying.
    I get the following message: Hmm something went wrong in google play games.

    Any idea were I went wrong?

    Thanks,
    Brian

    ReplyDelete
  40. Hi,

    I have the following problem. The Tutorial game works fine. But when I try the same stuff with my game, I get the following error:

    java.lang.NoClassDefFoundError: com.google.android.gms.games.Games$GamesOptions

    I can't find the problem. Any clues?

    Thanks, Marco

    ReplyDelete
    Replies
    1. @Marco, I think you have old version of google-play-services.jar
      Check, is you jar contain file: com\google\android\gms\games\Games$GamesOptions.class

      Delete
  41. Thank you! This is very helpful! I used it in my first app
    https://play.google.com/store/apps/details?id=com.snakefrenzy.android

    ReplyDelete
  42. This works great except for one problem. The first time I log in inside my game it does not display the logged in banner and it doesn't work (sending/viewing-scores/etc). Any other attempt to run the game it work correctly (displays logged in banner and works.) If I sign out and try again with a different account the same problem happens. It seems like it doesn't get logged properly. Same thing happened on different phones. My code looks similar/same to yours. Thoughts?

    ReplyDelete
    Replies
    1. Never mind. Solved it. Forgot to include and override the onStart(), onStop(), onActivityResult() methods in my android class.

      Delete
  43. hi
    thnx for the tutorial I completed my game and everything is working great the only problem is when I tap on share button in leaderboards it works there too but name of the app is not mine its "LibGDX Game Service" is a great game... so on I want to change it but I cant find where it is I checked all re folder and string xmls can u pls guide?

    ReplyDelete
  44. Hi Unknown, please check the values set in the google play developer console (screenshots 2 and 3 above).

    ReplyDelete
    Replies
    1. I cant go back to the page in ss 2 but in ss 3 its my app's name its correct but still I am dealing with same problem I didnt publish my game yet can it be related with that? or do I need to change smth in my code or in basegameutils or in googleplayservices lib ?

      Delete
  45. I'm on my phone so can't check right now, but if you notice in SS2 it specifies that "this is the name that will be displayed to users in Google Play game services", which sounds like the issue you're describing. If it can't be edited, you could try doing the play console setup again and updating your app to point to the newly configured play console app? Good luck :)

    ReplyDelete
    Replies
    1. I restarted everything I re-upload them and carefully name my app there as in ss 2 with my app's name but still when I try to share in leaderboard name of the app is LibGDX Game Services tutorial I think its not related with developer console do u have any other idea?

      Delete
  46. Hi Invader360,

    Thanks for the tuts and code on github. I've hit a problem that doesn't quite seem to tally with any I can find online (unless I'm missing something really obvious, which is possible)

    The achievements and leaderboard run fine on my phone and tablet when I install the APK directly through Android Studio but it won’t allow users to sign in when they have downloaded the game from Google Play Store.

    “Failed to sign in. Please check your network connection and try again”

    The SHA-1 matches in console.developers.google.com/apis/credentials/oauthclient/ and gradle.

    Leaderboards etc have all been published days ago.

    What have I forgotten to do? Is this something to do with debug and release apks?

    AndroidLauncher is up here: http://stackoverflow.com/questions/42027691/gpgs-fails-to-sign-in-when-download-from-playstore-okay-when-install-directly-f

    Thanks for reading. :)

    ReplyDelete
  47. Hi Martin, has the version up on google play been signed using the release key and are you sure you have that same certificate specified in the google play dashboard?

    I've personally always had to build and deploy apks manually when using gpgs, had the issue you are experiencing (but effectively in reverse) when deploying to test devices from android studio directly. Suggests a mixup between debug and release keys?

    ReplyDelete
    Replies
    1. Thanks for the answer mate. Yes it turned out I changed to debug sha1 but didn't realise you had to change back. Sorry I wasted your time I've posted this question in so many places I forgot to comment that I solved... (after 5 hours of googling)

      All looking good now.

      Search for Chugger Dodge if you fancy! :)

      Delete
    2. Excellent, glad to hear you sorted it :) I'll check out your game now!

      Delete
    3. Cheers. I see you got to 10 a lot quicker than some. :)

      Delete
    4. Yeah, you underestimate my fondness of scotch eggs :)

      Delete
    5. Haha. They are pretty delicious! Actually I was thinking of adding random scotch eggs into the game which will calm Chuggy down a bit if he eats them.

      Delete