Google Play Game Services in Flutter returns null

91 Views Asked by At

I want to use the Google Play Game Services with Flutter. Concretely, I want to use the SaveGames.

For that, I use this package: https://pub.dev/packages/games_services

I imported it in my pubspec.yaml like this (oc I have more dependencies than this):

dependencies:
  games_services: ^4.0.0

And the important part in /android/build.gradle look like this:

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

And the dependencies in /android/app/build.gradle look like this:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "com.google.android.gms:play-services-games-v2:+"
}

At the application level in my AndroidManifest.xml I have added the following:

    <meta-data
        android:name="com.google.android.gms.games.APP_ID"
        android:value="[Here is my number from Google Play Console, only numbers, pretty sure it is the correct one]" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

This is the status on the Google Play Console:

enter image description here

I did create an OAuth consent screen in the Google Cloud Console and OAuth 2.0 Client ID. Also, in the Google Play Console under Game Services, Credentials, Android I have a reference to the published OAuth thing. In the Google CLoud Console, in the app registration phase, my scopes are:

enter image description here

In my code, I have a button (I know, not final with the button), that triggers printing the following code:

(await GameAuth.signIn()).toString()

I receive null.

This one is always false:

await GameAuth.isSignedIn

Additionally I get this debug console output whenever I call that line of code.

I/PlayService( 4730): isAuthenticated: false toString: com.google.android.gms.games.AuthenticationResult@36a8a74
I/signin  ( 4730): success

TL;DR: It does not work. Somehow I don't get this (Hey you are signed in)-popup.

If you need any additional code/information, I am happy to provide you with it.

1

There are 1 best solutions below

0
John On

It seems that directly adding the id in the manifest doesn't work. so this is wrong:

<meta-data android:name="com.google.android.gms.games.APP_ID"
    android:value="app_id" />

Fix it by adding a strings.xml folder in the android/app/src/main/res/values/strings.xml folder like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_id">1111111111</string>
</resources>

Then in the manifest add the reference to this string :

   <meta-data
            android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />