B4A Library Google Play Game Services

This is a wrapper for the Google Play Services related to games. This library was tested successfully with the API 37 of Google Play Services.

List of features:
  • Sign-in: supported;
  • Achievements: supported;
  • Leaderboards: supported;
  • Real-time multiplayer: supported (NEW!);
  • Turn-based multiplayer: supported;
  • Level and XP: supported;
  • Gifts and requests: supported;
  • Events and quests: not supported;
  • Saved games: supported;
  • Notifications: supported;
  • Player stats: supported;
  • Nearby connections: supported.
To compile, you need B4A v6+, JDK v7+ and android.jar v21+ (cf. Tools/Configure paths).

The library is provided with its Java source code and a few B4A modules:
  • ClsConnection: manages the sign-in, sign-out and connection events;
  • CodConverter: converts your data map to and from the byte array needed for the Saved Games service (this module requires three extra libraries: JSON, ByteConverter and RandomAccessFile) in case you don't own the DataCollection library;
  • CodTurnBasedMatch: helper module for turn-based matches.
Before using this library, you need to:
  • download the Google Play services SDK and Android Support Repository with the Android SDK manager;
  • copy the GooglePlayGameServices library (Jar+Xml) to your additional B4A libraries folder.
When you create a project requiring this library, you need to:
  • add this line in the project attributes of your Main module:
    B4X:
    #AdditionalJar: com.google.android.gms:play-services-games
  • add also this line if you want to access the Nearby Connections API:
    B4X:
    #AdditionalJar: com.google.android.gms:play-services-nearby
  • add these lines to your manifest:
    B4X:
    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.version"
        android:value="@integer/google_play_services_version" />)
  • add also these lines to the manifest if you want to access the Nearby Connections API:
    B4X:
    AddApplicationText(
    <meta-data android:name="com.google.android.gms.nearby.connection.SERVICE_ID"
        android:value="$PACKAGE$" />)
  • copy the games-ids.xml file generated by your Google Play developer console in the Objects\res\values folder.
To generate the games-ids.xml file, click on the link at the bottom of some screens (e.g. achievements) in your developer console (you need of course a game project properly configured to see it):
ressources.png


This file should look like this:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<!--
Google Play game services IDs.
Save this file as res/values/games-ids.xml in your project.
-->
<resources>
  <string name="app_id">01234567890</string>
  <string name="achievement_win_on_a_very_large_map">CgkIuqeG8-kOEAIQAQ</string>
  <string name="achievement_win_on_a_large_map">CgkIuqeG8-kOEAIQAg</string>
  <string name="achievement_win_on_a_medium_map">CgkIuqeG8-kOEAIQAw</string>
  <string name="achievement_win_on_a_small_map">CgkIuqeG8-kOEAIQBA</string>
  <string name="achievement_win_on_a_very_small_map">CgkIuqeG8-kOEAIQBQ</string>
  <string name="leaderboard_main_score">CgkIuqeG8-kOEAIQBw</string>
</resources>

To set up a game in the Google Play developer console, please read this, then this.

To get details about a returned status code, please read this.
 

Attachments

  • Demos_37.zip
    71 KB · Views: 467
  • GooglePlayGameServices_372.zip
    241.3 KB · Views: 484
Last edited:

tufanv

Expert
Licensed User
Longtime User
I have no problem with signing in or displaying the achivements etc.. But while senbding the score to leaderboard it gives me the error no : 6 ( submitscoreimmedaite: error =6 ) any idea why this occurs ?

TY
This wrapper for the Google Play Game Services is a complete rewriting of the wrapper available in a former thread and is intended to be used with the API 19 or 20 of Google Play Services (the API 21 is still untested).

List of features:
  • Sign-in: supported (I even added a GPlayNetworkInfo class to give you more informations about the available networks and their connectivity status);
  • Achievements: supported;
  • Leaderboards: supported;
  • Real-time multiplayer: not supported;
  • Turn-based multiplayer: supported;
  • Level and XP: supported;
  • Gifts and requests: supported;
  • Events and quests: not supported;
  • Saved games: supported;
  • Notifications: supported.
Some features are not supported for the essential and excellent reason that I don't need them.

The library is provided with its Java source code and three B4A modules:
  • ClsConnection: manages the sign-in, sign-out and connection events;
  • CodConverter: converts your data map to and from the byte array needed for the Saved Games service (this module requires three extra libraries: JSON, ByteConverter and RandomAccessFile);
  • CodTurnBasedMatch: helper module for turn-based matches.
Before using this library, you need to:
  • download the Google Play services SDK with the Android SDK manager;
  • copy the folder "android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res" to the root of your B4A project (so you should have 3 folders there now: Files, Objets and res);
  • copy the library "android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs\google-play-services.jar" to your B4A libraries folder;
  • add the path to your res folder in the project attributes of your Main module, e.g.:
    #AdditionalRes: D:\My Android Projects\My Game\res, com.google.android.gms
  • add these lines to your manifest:
    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.version"
    android:value="@Integer/google_play_services_version" />)
  • copy the games-ids.xml file generated by your Google Play developer console in the res/values folder;
  • copy this library (Jar+Xml) in your B4A libraries folder.
To generate the games-ids.xml file, click on the link at the bottom of some screens (e.g. achievements) in your developer console (you need of course a game project properly configured to see it):
ressources-png.22252

This file should look like this:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<!--
Google Play game services IDs.
Save this file as res/values/games-ids.xml in your project.
-->
<resources>
  <string name="app_id">01234567890</string>
  <string name="achievement_win_on_a_very_large_map">CgkIuqeG8-kOEAIQAQ</string>
  <string name="achievement_win_on_a_large_map">CgkIuqeG8-kOEAIQAg</string>
  <string name="achievement_win_on_a_medium_map">CgkIuqeG8-kOEAIQAw</string>
  <string name="achievement_win_on_a_small_map">CgkIuqeG8-kOEAIQBA</string>
  <string name="achievement_win_on_a_very_small_map">CgkIuqeG8-kOEAIQBQ</string>
  <string name="leaderboard_main_score">CgkIuqeG8-kOEAIQBw</string>
</resources>

To set up a game in the Google Play developer console, please read this, then this.

To get details about a returned status code, please read this.
 

tufanv

Expert
Licensed User
Longtime User
According to the Google doc, 6 = STATUS_NETWORK_ERROR_OPERATION_FAILED
Interesting. Where is the document located i searched for the error codes on google but couldnt find the doc. so ican read myself a bit :)

ty
 

tufanv

Expert
Licensed User
Longtime User
Ok Thank you Informatix. I am really having a interesting problem. Sometimes i get this number 6 error but i 1 of 5 tries it send the score without any problem. I will investigate the problem from the doc now.
The link is at the bottom of the first post of this thread.
 

tufanv

Expert
Licensed User
Longtime User
Ok Thank you Informatix. I am really having a interesting problem. Sometimes i get this number 6 error but i 1 of 5 tries it send the score without any problem. I will investigate the problem from the doc now.

I solved the problem by enabling real time multiplayer option. Few people had the same problem.
 

Carcas

Member
Licensed User
Longtime User
Hallo i have this error

Parsing code. 0.28
Compiling code. 0.26

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. 0.00
Generating R file. Error
C:\Users\Carcas\Documents\ApplicazioniB4A\LibGdx\Picnoid\Picnoid DEFINITIVO\res\values\ids.xml:19: error: Resource entry app_id is already defined.
C:\Users\Carcas\Documents\ApplicazioniB4A\LibGdx\Picnoid\Picnoid DEFINITIVO\res\values\game-ids.xml:7: Originally defined here.

I followed the instructions in the first post
I have V19 Google game service

I can not understand where is the problem

thank you
 

Carcas

Member
Licensed User
Longtime User
I ask not to consider the previous post

Parsing code. 0.00
Compiling code. 0.05

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. 0.00
Generating R file. Error
AndroidManifest.xml:21: error: Error: No resource found that matches the given name (at 'value' with value '@Integer/google_play_services_version').

I followed all the steps
I put the file game-ids.xml in res / values (is only read)

I think for res / values means that
  • copy the folder "android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res" to the root of your B4A project (so you should have 3 folders there now: Files, Objets and res)
Do you recommend?

Thank
 

Carcas

Member
Licensed User
Longtime User
Can anyone tell me why the resource is not found?
I have google_play_service 19 and I've followed all the instructions.

My library may be faulty?

You can give me library + res folder version 19?

Contact me in private

Please help me :(:(:(:(:(
 

Gunther

Active Member
Licensed User
Longtime User
Bon jour Informatix,

ça va?

well, I was trying your DEMO for Leaderboards with setting up a correct games-ids.xml etc.
The DEMO started but I am getting an error after pressing the SignIn Button:

Sing_In_Failed Error 3 code 10002

Does it has to do with the Client-ID one has to apply? I do have one JSON for it. WHre I have to add that, if neccessary?

Merçi, Gunther
 

Informatix

Expert
Licensed User
Longtime User
Bon jour Informatix,

ça va?

well, I was trying your DEMO for Leaderboards with setting up a correct games-ids.xml etc.
The DEMO started but I am getting an error after pressing the SignIn Button:

Sing_In_Failed Error 3 code 10002

Does it has to do with the Client-ID one has to apply? I do have one JSON for it. WHre I have to add that, if neccessary?

Merçi, Gunther
It's an error related to authorization/authentification. Did you read the first two posts of this thread, especially the second one ?
 

Gunther

Active Member
Licensed User
Longtime User
HI,

yes, sure exactly as you wrote already in a previous post I read both already and changed as requested.

by "changing the package name" is is mandatory to change it to an already existing AND published one on the Development Center?

Greetings, Gunther
 

Gunther

Active Member
Licensed User
Longtime User
Oh, unfortunately I am getting a different error now: internal error with error code 0.
So, it must be something wrong in my settings in the development center...
I have to figure it out.

Thanks, Gunther
 
Last edited:

Gunther

Active Member
Licensed User
Longtime User
Found!
The issue was between the ears.
The saved games was not configured in the development center (since not intended to use), but in the request it was still set to 'True' from the demo.

First setting ist now 'False':
B4X:
Connection.Initialize(False,  Me, "Connection_Success", "Connection_Failure", False, Debug)

Do you have a plan to add the Events to the library?

Thanks, Informatix!
 
Top