npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-google-play-game-services-workaround

v0.0.2

Published

Google Play Game Services bindings for React Native

Downloads

2

Readme

Credits to SempaiGames

react-native-google-play-game-services-workaround

npm version

React Native Google Play Game Services bindings for Android (Google Play Game Services for iOS no longer exists).

Currently implements achievements, leaderboards, snapshots (saved games). Events and more will be added on request.

Requirements

Android

  • SDK 23+

Compatibility

This package was built for React Native 0.40 or greater! If you're still on an earlier version you're welcome to check it out and patch the package.json file but there's not going to be anyone to support you.

Before installing

It is highly recommended that prior to installing this library that you make yourself familiar with Google Play Game Services and how to get started.

This document does not cover those steps but you will need to follow them prior to getting an app up and running.

There are two key steps in the process:

  • Add a new game in the Google Play Console and note down your app id
  • Link your app - if you don't follow this step correctly this library will silently fail

Also you will need to create some achievements and note down their ids for using the library.

Installation

Currently there are a number of steps that cannot be automated.

Run npm install --save react-native-google-play-game-services-workaround to add the package to your app's dependencies.

react-native cli

Run react-native link react-native-google-play-game-services-workaround so your project is linked against the Android library

Manual steps

In your android/build.gradle add:

...
allprojects {
  repositories {
    ...
+   maven { url 'https://maven.google.com' }
  }
}

In your android/app/build.gradle (note: this is not the same file as above) add:

...
dependencies {
  ...
+  compile "com.google.android.gms:play-services-games:11.6.0"
+  compile "com.google.android.gms:play-services-auth:11.6.0"
}
...

In your android/app/src/main/AndroidManifest.xml:

<application>
        ...
+      <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"/>
        ...
</application>

In your android/app/src/main/res/values/strings.xml (create it if it doesn't exist) you need to add your app id:

<resources>
    ...
    <string name="app_name">gpsgexample</string>
    <string name="app_id">{your app id from google play console - 10-12 digit number}</string>
</resources>

Lastly ensure that you have Google Play Services installed on the target device.

For Genymotion you can follow these instructions. For a physical device you need to search on Google for 'Google Play Services'. There will be a link that takes you to the Play Store and from there you will see a button to update it (do not search within the Play Store). ndroid Pay deployment and testing.

Usage

The API closely follows the Google Play Game Services Android API so if you're not following the below the official documentation should help.

Basically you need to sign in - you can do this silently or through the official UI from Google but you do need to call one of the two sigin in functions before any others will work so calling when your main UI component mounts is probably good practise. You may find if your app has been suspended it will also need to be called. How to deal with this I will leave as an exercise for the reader.

You can then assign achievements and show the achievement table. Simple.

import RNGooglePlayGameServices from 'react-native-google-play-game-services-workaround';

// SIGN in prior to doing anything - silent sign in works for those who are already logged into google play gaming services
RNGooglePlayGameServices.signInSilently()
	.then((msg) => {

	})
	.catch((msg) => {
		//silent sign in didn't work so show the dialog instead
		//note probably should catch errors here
		RNGooglePlayGameServices.signInIntent();
	});

//unlock an achievement - note the id supplied is obtained by creating a new achievement in the play console
RNGooglePlayGameServices.unlockAchievement("CgkI8oW5sqwOEAIQAQ")
        .then((msg) => { console.log("unlocked achievement -  ",msg)})
        .catch((msg) => { console.log("not signed in - ",msg)});

//reveal an achievement - note the id supplied is obtained by creating a new achievement in the play console
RNGooglePlayGameServices.revealAchievement("CgkI8oW5sqwOEAIQAQ")
        .then((msg) => { console.log("achievement revealed -  ",msg)})
        .catch((msg) => { console.log("not signed in - ",msg)});

//increment an achievement - note the id supplied is obtained by creating a new achievement in the play console
RNGooglePlayGameServices.incrementAchievement("CgkI8oW5sqwOEAIQAw",10)
        .then((msg) => { console.log("incremented achievement -  ",msg)})
		.catch((msg) => { console.log("not signed in - ",msg)});

//set an achievement to specific value - note the id supplied is obtained by creating a new achievement in the play console
RNGooglePlayGameServices.setAchievementSteps("CgkI8oW5sqwOEAIQAw",7)
        .then((msg) => { console.log("set achievement -  ",msg)})
        .catch((msg) => { console.log("not signed in - ",msg)});


//show player the achievements list
//note: should also catch errors here
RNGooglePlayGameServices.showAchievements();


//set the player score for an specifil leaderboard
//note: should also catch errors here
RNGooglePlayGameServices.setLeaderboardScore("AbCI8oW5sqwOEAXXXX",200);

//get the player score for an specifil leaderboard
//note: should also catch errors here
RNGooglePlayGameServices.getLeaderboardScore("AbCI8oW5sqwOEAXXXX")
    .then((score)=>console.log('Score:', score))
    .catch(error=>console.log('Error retrieving score:', error))

//show all leaderboards
//note: should also catch errors here
RNGooglePlayGameServices.showAllLeaderboards();

//show specific leaderboard
//note: should also catch errors here
RNGooglePlayGameServices.showLeaderboard("AbCI8oW5sqwOEAXXXX");

//Load a saved game:
RNGooglePlayGameServices.loadSnapshot("my_game").then(res=>{
    console.log(res);
}).catch(error=>{
    console.log('Error loading game:', error);
});

// Once you've loaded a game, you can close it or update it.
// To close it:
RNGooglePlayGameServices.discardAndCloseSnapshot();

// To write / overwrite it:
RNGooglePlayGameServices.commitAndCloseSnapshot("new saved data", "some description");


// Am I signed in?
RNGooglePlayGameServices.isSignedIn()
        .then((msg) => { console.log("signed in - ",msg)})
        .catch((msg) => { console.log("not signed in - ",msg)});

//sign out
RNGooglePlayGameServices.signOut()
        .then((msg) => { console.log("signed out - ",msg)})
		.catch((msg) => { console.log("not signed out - ",msg)});

// Get current player ID
RNGooglePlayGameServices.getUserId()
        .then(id => { console.log("ID:", id); })
        .catch(err => { console.log("Error:", err); })

Troubleshooting

It won't compile

Check you followed all the steps in the install guide

It's not doing anything or failing silently

Use the command adb logcat and grep for OAuth - if you're getting OAuth failures it's because you haven't linked your app properly. You need to follow the getting started instructions. There will be two apps - one is your debug and one is your release. It's important that you have two because the production OAuth doesn't work with debug and vice versa.