B4A Library Google Play Game Services

Discussion in 'Additional libraries, classes and official updates' started by Informatix, Oct 1, 2014.

  1. Informatix

    Informatix Expert Licensed User

    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:
      Code:
      #AdditionalJar: com.google.android.gms:play-services-games
    • add also this line if you want to access the Nearby Connections API:
      Code:
      #AdditionalJar: com.google.android.gms:play-services-nearby
    • add these lines to your manifest:
      Code:
      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:
      Code:
      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:
    Code:
    <?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.
     

    Attached Files:

    Last edited: Nov 12, 2016
  2. Informatix

    Informatix Expert Licensed User

    [DEPRECATED - The new demo files are in the first post]

    Here are a few demos: AchievementsLeaderboards, NearbyConnections, SavedGames and TurnBasedMatch.
    To run them with an existing game project, you have to change their package name, copy the res data, set the path to the res folder at the beginning of Main and add the games-id.xml file in Objects\res\values.
    Note: The SavedGames demo requires that you add the Drive API in your developper console.
     

    Attached Files:

    Last edited: Feb 17, 2017
    Daniel-White and Jaames like this.
  3. joseluis

    joseluis Active Member Licensed User

    This is fantastic! Does it work in B4J also?
     
  4. Informatix

    Informatix Expert Licensed User

    I don't know. My knowledge of B4J is next to none. But I really doubt that the lib can be useful on your desktop because it needs the Google Play Services (an application installed on mobile devices).
     
    Last edited: Oct 2, 2014
    victormedranop likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    It will not work on B4J as it is based on Android specific API / services.
     
  6. joseluis

    joseluis Active Member Licensed User

    Last edited: Oct 2, 2014
  7. Informatix

    Informatix Expert Licensed User

    If you're able to send a HTTP POST, GET or PUT with B4J, then you can use the GPGS.
    Note that some features are unavailable this way, e.g. real-time multiplayer and saved games.
     
    Last edited: Oct 2, 2014
  8. joseluis

    joseluis Active Member Licensed User

    Thank you Informatix. I'm gonna try to make a wrapper/library to use the REST API.
     
  9. Jaames

    Jaames Active Member Licensed User

    Thank you man. Your work and contribution for this community is unquestionable and irreplaceable.
     
  10. Marcela Calixto

    Marcela Calixto Member Licensed User

    I've tried to follow the recipe but I'm getting an error when trying to use

    Initialize: creating a GoogleAPIClient instance
    java.lang.NoSuchMethodError: com.google.android.gms.common.api.GoogleApiClient$Builder.addApi
    at flm.b4a.googleplay.GooglePlayConnection.Initialize2(GooglePlayConnection.java:165)
    at flm.b4a.googleplay.GooglePlayConnection.Initialize(GooglePlayConnection.java:139)
     
  11. Informatix

    Informatix Expert Licensed User

    No idea. Check your google-play-services.jar (2 765 459 bytes), and check the version of your Google Play Services app on your device (should be 6.1.xxx).
     
  12. Marcela Calixto

    Marcela Calixto Member Licensed User

    Yes, my google-play-services.jar was old. I replaced and it fixed it. But know, when I'm clicking Sign In, I'm getting

    java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5089000 but found 4323000. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@Integer/google_play_services_version" />

    In my Manifest editor I have
    AddApplicationText(
    <activity android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    <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"/>
    )
     
  13. Informatix

    Informatix Expert Licensed User

    Did you update the res folder as well?
     
  14. MaxApps

    MaxApps Active Member Licensed User

    Hi

    I am getting

    internal error
    Error=0 Code=8

    any ideas?
     
  15. Informatix

    Informatix Expert Licensed User

    From the Google's documentation:
    "An unspecified error occurred; no more specific information is available."
    If they don't know what's going wrong in their product, I cannot know better.
    I had this error once, and I retried, with success.
     
  16. MaxApps

    MaxApps Active Member Licensed User

    Hmm. Tried 2 different phones and get the same result.
     
  17. Informatix

    Informatix Expert Licensed User

  18. Marcela Calixto

    Marcela Calixto Member Licensed User

    I now also get this error. Did you find any solution?
     
  19. MaxApps

    MaxApps Active Member Licensed User

    No. There seems to be no solution
     
  20. Informatix

    Informatix Expert Licensed User

    During the development of the library, I got a few strange errors while testing. Some of them happened after I changed something in my project on the dev console. We obviously have to wait after any change. For example, I had to wait a couple of hours before one of my leaderboards work as expected. The other errors were due to the network. So you should retry later; things might suddenly work.
    About leaderboards, I'm still unable to make the social variant work (I can only see the current's player; no one else from the same circles). I probably did not understand something.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice