B4A Library Google Play Game Services

First off, my apologies on my Wrapping Skill, this is no where near as polished as from the big boys of wrapping here. Also, many thanks to Erel for helping me get through this.

The story: I need this library, and it is working for me. If you know what it is, and have been waiting for it, hopefully my tutorial will help you get going with it. If you don't know what this library does, or if you need it, check out here

Right now, this library can handle Leaderboards, Achievements, Room Creation/Communication (have not done RealTimeSocket yet), One-Click signIn, and Anti-Piracy Checks. Did not implement Cloud Save.

Still interested? Read on.

First, please review Google's branding guidelines, as there is no way I can keep that up to date on this thread. Here

Next, I recommend just studying the flow of events here particularly the Developer's Guide section.

Still awake? Good.

Before any of this works, you need to register your app within your Developer Account, to get the OAuth necessary. The Google/Java speak instructions are in that developer's guide.

For B4A speak. Must do the following:

1. Follow these directions for adding your app to the console here.

** EDIT - See Erel's post below on how to grab SHA1 fingerprint straight from B4A... **

When you get to the part about adding your SHA1 fingerprint, it's time to break out your command prompt. (If you already know how to get your SHA1 fingerprint, then continue on) First, find out where (or make a new) password file for B4A is kept by looking at your B4A->Tools->Private Sign Key.

Then in your command prompt, change to the directory with keytool in it (for me that is "c:\Program Files\Java\jre6\bin") and type
B4X:
keytool -exportcert -keystore <path-to-debug-or-production-keystore> -list -v
which for me would be
B4X:
keytool -exportcert -keystore C:\Programming\b4a.keystore -list -v
A prompt asking for your password should then pop up. Type your password in that you used to create it(shown on your B4A->Private Sign Key window)

Then, enter that SHA1 fingerprint (type it, copy paste it... I copy the whole command prompt to notepad, and then copy/paste it from there) into the final OAUTH Step and you should get back that your app is linked.
Note the code back will look something like this -> 211205627476-74off6bsgue1qbcka2878p3lurctabft.apps.googleusercontent.com ONLY THE FIRST PART BEFORE THE HASH IS YOUR APP_ID FOR USE IN THE XML FILE

2. Create your new B4A project and include this in your manifest:
AddApplicationText(
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
)

3. Create an XML file in your B4A (using your favorite text editor) project called ids.xml in your projectdirectory-> Objects -> res -> values folder, and put something like this in it

Put your AppID obtained from before in the ReplaceMe section and then make sure to set the file to read only (just edit the file included in the sample app)

4. Now it is time for the achievements/leaderboard ID's Need to do that here and here

In the sample app created I use two leaderboards (easy and hard) and four achievements (put in five if you need to continue in your Developer account, but not required to use them all) the four achievements are:
B4X:
Dim easyLeaderboard As String = "ReplaceMe"
Dim hardLeaderboard As String = "ReplaceMe"
Dim EasyAchievement As String = "ReplaceMe" 'for playing a game of easy level
Dim HardAchievement As String = "ReplaceMe" 'for playing a game of hard leve
Dim IncrementAchievement As String = "ReplaceMe" 'for playing 10 games (either hard or easy)
Dim HiddenAchievement As String = "ReplaceMe" 'not visibile until hard and easy games played

Follow these directions, but use these sample Achievements and Leaderboards for the sample application and fill in with your own pithy comments, and Replace the ReplaceMe's for each one in the sample app **Note the IncrementAchivement is of type increment and I used 10 as the amount. The HiddenAchivement is of type Hidden, and you can see in the code how I went about unlocking it**

5. Now time for a choice, either download the attached xml/jar files that go in your library, or (advanced mode) download and compile the attached project source files. Either way, must have gameplayservices.jar, gameplayservices.xml (which are the library wrappers) installed in your Libraries folder and then have gameplayservices selected in B4A. Also, I am a big fan of having a bit of something in my demos, so you will also need Informatix' most excellent AnimationPlus library installed (do search for latest link) and Agraham's superbly efficient ByteConverter library (again, do search).

6. Not sure why, but in order to get the required dependency file "googleplayservices.jar" You must follow the directions here to download the SDK. Then, grab that file and put it in your library. (the file itself is a bit above the limit for me to include here, and I'm not sure about the legal ramifications of including it by itself after reading here) If anybody can tell me otherwise, I'll post it someplace else for easier access to download.

7. Three modules are included in the sample app. The main module is just the basics of logging in (once you get past that, then it's time for the other two) and displaying the SignIn button. The other two modules are my own take on the Type A Number and Button Clicker sample apps (no typing of numbers in my version, but I do add displaying player icons, more robust message passing)

8. Logic/documentation. As I said, trying to figure out how to wrap all of this was a very good challenge/learning process for me. As some of these wrappers included nested classes, and I didn't know exactly how to approach, I made the nested classes separate classes for exposing to B4A. What does that mean? Well, some of the things that happen "behind the scenes" in the original library, I had to make a choice on where they happen in my wrapper. I finally decided that almost anything to do with Room Stuff, happens in the gRoomConfig wrapper (As opposed to RoomConfig, Room and GamesClient in original flow). My samples show a lot of what was wrapped, but if you have a question about a function, and you go to look for more detail on Google's developer site, Where that function is exposed may be different in this library, and sometimes not at all. (If not exposed, it is generally something I didn't see how to write a wrapper for that functionality, at least not yet, but again... it's working for me with a lot of what I wanted to accomplish) I am also including all of the source files, which may help out for those looking to try and learn how to wrap things in the future. Please forgive my poor coding logic in advance. Also, some things are exposed that don't do anything (at least not for me) and are there to show where I think they should be exposed moving forward (most notably the RealTimeSocket stuff), but they are annotated with the hint system as not being ready for prime time!

Of note, many, many listeners in this, and I did include code in the Java to explain many of them, but I don't see how to bring up those hints when using the "Sub "space-Tab" auto-fill" feature.

9. Going forward - I am sure I will be updating some things as I go along, but I don't know at what pace, and who knows, maybe RTS's are really, really important to someone, or the ability to do cloud saving. So, I also am including the source files that I used to wrap. While a learning tool in and of themselves, I do ask, that if you add any functionality, that you pass those additions back to the community. I think we all benefit from using these libraries that others create, and let's face it, sometimes having that 1 library wrapped makes all the difference.. and until Erel figures out how to auto-wrap any library out there... some of us come to a halt going down certain paths unless someone out there can help boot strap our project. (which is why I started this in the first place ) Also, please note you'll probably see some ("why is THAT there") in the source code, and it's because I learned a LOT doing this, and changed how some implementations worked as I kept building wrapper classes. I would do it all from scratch to make it cleaner... but I need to get going on the projects that I built this for!
 

Attachments

  • GoogleGameServiceSampleApp.zip
    20.5 KB · Views: 540
  • GamePlayServicesLibraryFiles.zip
    56.3 KB · Views: 622
  • EclipseSourceFiles.zip
    87.6 KB · Views: 464
Last edited:

Informatix

Expert
Licensed User
Longtime User
My library, which is an unfinished work (real-time is not entirely supported), was created for the API 14 of Google Play Services. It does not work with other APIs. To use it, you have to configure properly your app with the advices given in this post.
 

lucad

Member
Licensed User
Longtime User
Computersmith64 said:
Yes, you do need to create achievements in order to be able to use a leaderboard. Play Services won't let you have a leaderboard without achievements.

Hi Colin. thank you this helps and explain me my leaderboard problem. I'll work on that ( Mysql and php has to wait )


Yes, the app and the system was right configured as per your instruction.... but I will check that again, thank you.

Luca
 

lucad

Member
Licensed User
Longtime User
Maybe it's not the point, I have the latest API 19 .

Here the last config I tried :

Project attributes

B4X:
#AdditionalRes: C:\Programmi\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

Manifest

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"
   
    />)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.


AddApplicationText(
<meta-data android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version"/>
<activity android:name="com.google.android.gms.ads.AdActivity"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
)


'for leaderboards
AddApplicationText(
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="@string/app_id" />)
 

lucad

Member
Licensed User
Longtime User
Correct ...

But I can see in the "Extras" at "Google play Services" , i got Rev. 15 and there is a 16 availble for update.
If "Rev" is related to the API then it's anyway > 14.
 

Informatix

Expert
Licensed User
Longtime User
Correct ...

But I can see in the "Extras" at "Google play Services" , i got Rev. 15 and there is a 16 availble for update.
If "Rev" is related to the API then it's anyway > 14.
Google changed many important things after API 14. I tried the API 15 and I had a few issues with it (but can't remember which ones exactly; it was maybe a change in the parameters of some functions). I decided to stop working on my library so there will be no update for the new APIs. I have a copy of the API 14 and I don't need the real-time classes, so my library is perfect for my own use.
 

lucad

Member
Licensed User
Longtime User
ok no probs. I will test again NFOboy library, now Colin gave me some hope
thank you.
 

lucad

Member
Licensed User
Longtime User
... crazy It seems I cannot test the lib yet, i got this : "This client ID is globally unique and is already in use"
a big mess with a deleted ( previous ) api project and Google will only clean the key after a week ...
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Also - you need to make sure the correct version of google-play-services.jar is in your \Basic4android\Libraries folder.
 

RichyK68

Active Member
Licensed User
Longtime User
Hi, I'm trying to implement multiplayer services into my app, I'm using version 0.50 of the gameplayservices library, I've confgured my ids.xml resource to include my app id provided by Google to use their service, modified my manifest as per instructions at the beginning of this post, but on the line

B4X:
GGS.initialize("GGS")

it simply kills my app with the very helpful message "Unfortunately, ... has stopped working."

I've put this in a try-catch to see if there is any useful exception message but the try-catch is ignored and the app just dies a death.

Can anybody tell me what I am missing? What jar versions I should have etc perhaps.

Thanks,

Richard
 

RichyK68

Active Member
Licensed User
Longtime User
Can anybody help with this one? I've tried the example application at the beginning of this thread, substituting the ids.xml in the res values folder with the ones generated from my developer console. Everything appears to be set-up at my side, but both the example app and my app (which doesn't do much yet beyond initialize the GGS (gGoogleGameService) object fail.

Both apps simply die without any error message except the "Unfortunately ... has stopped working" which is no of no use whatsoever.

Richard
 

Informatix

Expert
Licensed User
Longtime User
All the answers to your questions are in the posts of this thread. Begin to read those above your post.
 

RichyK68

Active Member
Licensed User
Longtime User
I know that my SDK tells me I'm on API 16 of google-play-services.jar, do you know where I can get a copy of API 14 which seems to be the version that this wrapper is for? I can't see anything in the six pages of threads, and have Googled but they certainly don't it easy to find.

Cheers,

Richard
 

lucad

Member
Licensed User
Longtime User
I used the latest API because it seems that the wrapper can manage leaderboards, unfortunately my tests have been interrupted ... waiting for Google to delete my previous ID key.

For my app I have had to build an online ranking using PHP and MySql
 

capisx

Member
Licensed User
Longtime User
There are two libraries in this thread. One written by NFOBoy and another written by me. My own version, compatible with API 14, is untested for leaderboards and achievements, but should work. I implemented all functions for that.
I was using your library for leaderboards and achievements, and it was work on my game (Thanks alot to you Informatix ).

The leaderboards and achievements also work using the latest Google Play Services API after edit the version.xml under values folder (on API res folder) and replace the version of "google_play_services_version" to 4132500.
Edit: Only works with v14 API jar.
 
Last edited:

Magnus Gärtner

Member
Licensed User
Longtime User
Can anyone who has v14 googlegameservices.jar post the link, please I'm searching the internet for hours to get this file but i had no luck :/
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…