0

I have been banging my head against the wall over this for a number of days now. Despite reading many posts describing numerous problems/solutions to GPS sign-in failure I have been unable to find a solution to my problem.

In short, I am developing a game in Android Studio using the LibGDX framework and have added BaseGameUtils as a library and added all the necessary dependencies etc.

Problem Statement: When the game starts, it attempts to connect to GPGS but always responds with a 'Failed to log in' message. The logcat contains the following message:

01-03 19:37:41.744 6693-7436/? E/TokenRequestor: You have wrong OAuth2 related configurations, please check. Detailed error: UNREGISTERED_ON_API_CONSOLE
01-03 19:37:41.764 20609-20609/? I/SignInActivity: Transition from 6 to 11
01-03 19:37:41.764 20609-20609/? W/SignInActivity: onSignInFailed()...
01-03 19:37:41.764 20609-20609/? W/SignInActivity: Sign in failed during 6
01-03 19:37:41.764 20609-20609/? W/SignInActivity: ==> Returning non-OK result: 10002

According to https://developers.google.com/android/reference/com/google/android/gms/games/GamesActivityResultCodes ...

public static final int RESULT_SIGN_IN_FAILED

Result code sent back to the calling Activity when signing in fails.

The attempt to sign in to the Games service failed.
For example, this might happen if the network is flaky,
or the user's account has been disabled, or consent could not be obtained.

Constant Value: 10002

My network is not 'flaky' and I don't believe my account has been disabled - other commercial games I have installed work perfectly fine with GPGS.

I have signed my APK - both debug and release (although I'm only working with debug at this stage). I have added the game into the Google Developer Console and linked it in the API Manager and created the OAuth2 client ID. In fact, I have done this many times, deleting the linked game and recreating it thinking that either my client ID or the SHA1 fingerprint were incorrect. The logcat message suggests that the OAuth2 configuration is wrong but I have checked this many times and it all looks okay to me. What is the best way to verify the signature?

I am testing on a physical Samsung S7 which I deploy to directly from my laptop. My Android Gradle has the necessary SigningConfigs declared so I believe my deployed game should be correctly signed.

android {
signingConfigs {
    config {
        keyAlias 'mygame-key'
        keyPassword 'mypassword'
        storeFile file('path/to/my/keystore.jks')
        storePassword 'keystorepassword'
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.config
    }
    debug {
        signingConfig signingConfigs.config
        debuggable true
    }
}

In my manifest, I have the required lines. E.g. -

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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"/>

Originally, in AndroidLauncher, I was using the GameHelper class but discovered recently that this is being deprecated, so I changed my code to use GoogleApiClient. The builder is defined as follows:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();

The code for the other methods has been taken directly from the TrivialQuest example app, e.g. -

@Override
protected void onStart() {
    Log.d(TAG, "onStart()");
    super.onStart();
    mGoogleApiClient.connect();
}

However, despite using the Google API client code, this has made no difference.

I'm not sure what else to provide here but please let me know if you need to see any other parts of the code. I would be extremely grateful for any suggestions of things to examine in the code or logs to get a better clue as to why this is failing.

Many thanks in advance.

Gavin
  • 33
  • 1
  • 6
  • Are you creating it in the [Google Play Developer Console](https://play.google.com/apps/publish) or in the [Google API Console](https://console.developers.google.com)? – ianhanniballake Jan 04 '17 at 00:09
  • First, I added the app to Game Services in the Developer Console. Then I click on the Linked Apps link and added it here to authorise it ... from here I get taken to the API Manager which is where I entered the name, package, and SHA-1 fingerprint. – Gavin Jan 04 '17 at 09:57

2 Answers2

3

The package name appears in a number of places in the project and MUST match the package name that is registered in the Google Play Developer Console. E.g. -

android build.gradle

defaultConfig {
    applicationId "com.package.name"
    ...
}

android AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.package.name"
   ...
</manifest>

I had a typo in my applicationId in the android build.gradle. Once this was corrected, Google Play Services signed in successfully.

Gavin
  • 33
  • 1
  • 6
1

I think you should carefully read (or re-read) all the procedure described here. Add a comment if you need more help on this after you followed the tutorial from the scratch again.

90% of problems with this are related to: wrong sha1 signed certificate, wrong app package name, missing client ID and something like those...

PS: here you can find all the working samples

MatPag
  • 41,742
  • 14
  • 105
  • 114
  • Thanks for this. I genuinely hope my problem is something trivial as you say because I'm a bit flummoxed otherwise! I will run through the steps again in the link you provided and will let you know how I get on. – Gavin Jan 04 '17 at 09:59
  • Deleted and re-registered my game on the Google Play Developer Console following the steps given in the link. Double checked the client ID, package name details in my manifest and Gradle files. Found a typo in the applicationId under defaultConfig ... now it works. :) Thank you. – Gavin Jan 04 '17 at 16:00
  • Nice!! You can accept the answer if in some part helped you to find the problem ;) – MatPag Jan 04 '17 at 17:34
  • Your answer did prompt me to double check everything but doesn't explain the precise issue I had as such. I did up-vote your answer but I don't think it shows up because I'm new to SO. – Gavin Jan 04 '17 at 17:58
  • There isn't a vote on my answer and there isn't an accepted answer for this question. You should "Accept an answer" flagging the check under the answers arrows. – MatPag Jan 05 '17 at 08:07
  • This answer led to me solving the problem. As MatPag stated, my app package name was mis-typed (see my explanation below). – Gavin Jan 06 '17 at 12:57