I have been hard working on Google Play Game integration in my upcoming game : Word Hunter and I am posting my finding heres. Hopefully it can help someone else :)

Configuring Google Play Game

Log on to the developer console (if you don’t already have an account, you will need to create one for 25$)

Select “Game Services” and follow the instructions to create a new game.

Some notes :

The game name doesn’t really matter at this point, it can be changed later on.

You will be asked to provide a RSA key for the game. To do so you will need to generate it in command line using a certificate, you have two choices

Use the debug certificate in your android sdk install folder You will be able to test Google Play Game integration directly when you launch your application from Eclipse without having to sign it with your production certificate But you will have to restart the process all over again once you want to push it to production (…)



Use your production certificate that you use to publish your application to google play You will need to sign your APK using your production certificate (right click on your project -> Export as Android Application) and then install this APK on your device to test it And you are done, you can simply publish the game when you are done and it will work



I went with solution #2 since I am publishing my game in Alpha state in Google play and I want my testers to be able to use it

DO NOT forget to add your testers email in the list of testers for the GAME, it is a different list than the application testers or even the Alpha testers

Do not bother trying to test Google Play Game with your developer account, even if it is marked as a tester, it just doesn’t work. Use another account.

Once you are done, you should get an application ID associated to your game, follow this documentation to make it available in your game (short version, create an ids.xml file in the android res/values folder and add this id in it as a string with name app_id). This is also where you will put the key for your leaderboards/achievements. You will also need to modify your manifest as indicated in the documentation.

Configuring the libGDX Core project

In your Core project, create an interface with all the actions that you want to be able to do from your game. The basis are :

Logon

Logoff

Send a score to the leaderboard

Unlock an achievement

Show the Score Leaderboard

Show the Achievements Screen

Pastebin code

Configuring the Android project

Once this is done, we need to do several things:

First follow the instructions to download the sample apps from here .

You should get the google-play-services-lib when you install the google play service SDK. Add it to your workspace and add it to your Android project as a library (right click on your android projects -> Properties)

From the BaseGameUtils projects, copy the GameHelper.java class directly into your Android project.

Now we will modify the Android project MainActivity class.

First it needs to implement the previously created interface, as well as the GameHelper.GameHelperListener interface (from the GameHelper class we just copied) :

public class MainActivity extends AndroidApplication implements LeaderboardInterface, GameHelper.GameHelperListener

In this class, we will need to instantiate a GameHelper and implement the different methods specified in the Interface. Most of this code was inspired/copied from the BaseGameActivity available in the sample Android project.

Once this is done, we need to pass the MainActivity itself as an argument of the initialize method.

Here is the code

Possible improvements :

Show a toast when the unlockAchievement method is called by user is not logged in google play

Push scores and achievements right after login, in the onSignInSucceeded method

I noticed that by using this method, the Title Bar now appears in game. To solve this issue, simply add the following theme to your main activity in the manifest :

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

How to use it in game

In your main class in the core libGDX project (the one which implements ApplicationListener), create a variable of type GameServiceInterface and set it using the arguments passed in the constructor :

public class Game implements ApplicationListener { public GameServiceInterface _leaderboard; public Game(GameServiceInterface leaderboard){ this._leaderboard = leaderboard; }

And now you can just call/bind _leaderboard.login() or any other method of the GameServiceInterface anytime in your game.