Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] signIn() returns null #129

Open
erperejildo opened this issue Nov 27, 2023 · 103 comments
Open

[Android] signIn() returns null #129

erperejildo opened this issue Nov 27, 2023 · 103 comments

Comments

@erperejildo
Copy link

erperejildo commented Nov 27, 2023

I followed all the steps here: https://akdebuging.com/posts/integrate-gamekit-and-google-play-services/

Added to AndroidManifest:

<meta-data
            android:name="com.google.android.gms.games.APP_ID"
            android:value="MY_ID" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>

In Google Play Console everything seems fine (the SDK is not marked as done, not sure if related. UPDATE: this is not currently showing up):

image

When I call this it returns just null:

Future<void> signIn() async {
    final result = await GameAuth.signIn();
    print(result);
  }
@theLee3
Copy link
Collaborator

theLee3 commented Nov 28, 2023

Try creating a string resource for your app id and use it in AndroidManifest.

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

@erperejildo
Copy link
Author

resource

Changed to:

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

Created file (\android\app\src\main\res\values\games-ids.xml):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--app_id-->
    <string name="app_id" translatable="false">MY_ID</string>
</resources>

Same result, null

@theLee3
Copy link
Collaborator

theLee3 commented Nov 28, 2023

Double check the credential setup process as it's almost certainly an issue with your app authorizing with Play Games. Are you using the Project ID that looks like a large number and the fingerprint for the debug key?

The 4th item in that list will not be checked until you upload a build with Play Games Services and is not necessary to get the service working.

If I recall, it can take up to 24 hours when play services is first setup. So if you are still in that window, that could be the case as well.

@theLee3
Copy link
Collaborator

theLee3 commented Nov 28, 2023

Try the troubleshooting checklist provided here.

@erperejildo
Copy link
Author

erperejildo commented Nov 28, 2023

  • ID is also correct. I got the credentials directly from "Get resources" in Google Play. It looks like 79XXXXXXXXXX
  • SHA-1 is the one I have in App Integrity:
    image

same as:
image

  • I uploaded a build with Play Games Services (a few versions back in fact):
dependencies {
    implementation "com.android.billingclient:billing:6.1.0"
    implementation "com.google.android.gms:play-services-games-v2:+"
}
  • Play Services was created more than 24h ago

More screenshots:

image

image

Maybe I have to wait for this? I didn't find any related info in the docs here (TBH not sure if this is even necessary at all):

image

@theLee3
Copy link
Collaborator

theLee3 commented Nov 28, 2023

That could be the problem. They are not very clear, but you can get all of this working without verification if you don't change certain aspects of the consent screen, such as the icon. However, once you change it or submit for verification, there is no undoing the need to verify.

You may be able to select BACK TO TESTING in order to get it working on the debug app to confirm everything is setup correctly.

@erperejildo
Copy link
Author

erperejildo commented Nov 28, 2023

That could be the problem. They are not very clear, but you can get all of this working without verification if you don't change certain aspects of the consent screen, such as the icon. However, once you change it or submit for verification, there is no undoing the need to verify.

You may be able to select BACK TO TESTING in order to get it working on the debug app to confirm everything is setup correctly.

I did that but I published it when checking before. So when I was getting the error, it was in testing already.

More screens:

image

@erperejildo
Copy link
Author

any other idea @theLee3?

@erperejildo
Copy link
Author

I have tried with an old phone and I can see the popup:

image

but it's not working as expected either way.

Resuming:

  • Old phone: popup displayed all the time, no matter if I logged in before.
  • New phone/emulator: spinner and no popup.

For all on them, these 2 methods return null:

Future<void> signIn() async {
    final result = await GameAuth.signIn();
    print(result);
  }

  Future<void> isSignedIn() async {
    final result = await GameAuth.isSignedIn;
    print(result);
  }

and again, for all of them, this function fails with this error: leaderboard_not_found

Future<void> showLeaderboards() async {
    final result = await Leaderboards.showLeaderboards(
        androidLeaderboardID: 'CgkI...');
    print(result);
  }

The ID is correct:

image

@theLee3
Copy link
Collaborator

theLee3 commented Nov 30, 2023

All of these symptoms point to the app not being configured properly for Play Games authorization. Anytime I've seen this, it's been because the signing config was off for the build. You have to ensure that if you are running a debug build, that it was signed with the debug key and the correct fingerprint is used. If you are running a release build, you need to ensure that the fingerprint coincides with the key that you signed your app with, or perhaps provided by the Play Store when using Google's app signing service.

@erperejildo
Copy link
Author

All of these symptoms point to the app not being configured properly for Play Games authorization. Anytime I've seen this, it's been because the signing config was off for the build. You have to ensure that if you are running a debug build, that it was signed with the debug key and the correct fingerprint is used. If you are running a release build, you need to ensure that the fingerprint coincides with the key that you signed your app with, or perhaps provided by the Play Store when using Google's app signing service.

I'll delete it and start from scratch

@erperejildo
Copy link
Author

erperejildo commented Nov 30, 2023

well, I can't remove anything, just edit it.

If I go to Authorisation it shows an Application ID that I can't changeOAuth client in a dropdown, but only with this option in it. So I click in Create OAuth client and go to Create OAuth Client ID:

image

This time, instead of copying it from the suggested data,

image

I ran the keytool command:

image

As you mentioned, both are different. So I used the last one, but when I try to create it, it fails:
The request failed because the Android package name and fingerprint are already in use

The previous one was removed as you can see here now:

image

This was weird so I checked not just this project but all of them and found this:

image

I had this one duplicated. Not sure when I created 2, maybe it was done by Firebase (I could see that it happend with another project that it was created twice). The thing is that I was using this fingerprint in the other one, so I removed it and also the project.

Now I have created both:

image

with the only different that the DEBUG can't be verified.

In Google Play Services I have now 2 in the dropdown and 2 credentials created, one for each environment:

image

From this point, having both fingerprints, I run this again:

Future<void> signIn() async {
    await GameAuth.signIn(); // returns null
    await isSignedIn(); // returns false
  }

I'll wait a few hours in case it's something related to that.

UPDATE: after 6h I'm getting the same thing

@theLee3
Copy link
Collaborator

theLee3 commented Nov 30, 2023

Having two GCP projects may be the culprit, and the next step I would suggest is going into Google Play Console for your game. Then under Play Games Services select Setup and management > Configuration, and at the very bottom Remove Play Games Services. I am not sure if Unpublish game project is necessary for this as well or not. If so though, it will not remove the actual app, just the game project. Then you can walk through setting up the game services in the Play Console again, including selecting the remaining GCP project and importing the credentials.

@erperejildo
Copy link
Author

erperejildo commented Nov 30, 2023

That doesn't work as expected. First of all I unpublished it and then, removed it. Now, when I go to create a new one, I have 2 options:

  • Create new Play Games services project: here, the project is not available from the dropdown
  • Use an existing Play Games services project: I can choose previous project (also the duplicated one that I removed earlier, not sure why) but this will load all the previous configuration. Also, choosing this again doesn't fix anything. I tried after republishing this, and got the null

I could try creating a new project in GPC

@theLee3
Copy link
Collaborator

theLee3 commented Nov 30, 2023

That would be the next step. Great a new GCP project from the Play Store menu and setup the credentials again from there. Then update your app with the new credentials.

@erperejildo
Copy link
Author

erperejildo commented Nov 30, 2023

Yeah, I was doing it in the meantime. Everything created and filled again, published, and app updated with new IDs.

Result: null again :(

Honestly I don't know what's going on and what else could I change/try.

@andynewman10
Copy link

andynewman10 commented Dec 1, 2023

@theLee3 what is GamesServices.signIn() supposed to return? I believe this returns null for me too. However, isSignedIn then returns true as expected.

@erperejildo the screen capture you provided above here looks like a Play Games v1 sign-in dialog. Can you confirm whether you're using games_services 3.x (using Play Games v1) or 4.x (Play Games v2, different dialog)?

@Abedalkareem
Copy link
Owner

Abedalkareem commented Dec 1, 2023

Hi @andynewman10 @erperejildo ,
signIn returns no result, and if it fails it will throw an exception, I'll update the return to void. Sorry for the trouble.

@Abedalkareem
Copy link
Owner

@erperejildo
Did you add your debug keystory SHA-1?

@andynewman10
Copy link

@erperejildo

I have the debug and release SHA1 fingerprints registered in the Cloud Console, as returned by gradlew signingReport. I don't use keystore (debug) and Play Console App Integrity (release).

Can you check

  • your keystore debug SHA1 is the same as the gradlew signingReport debug SHA1?
  • your gradlew signingReport release SHA1 Play Console is the same as your Play Console App Integrity SHA1?

@theLee3
Copy link
Collaborator

theLee3 commented Dec 1, 2023

@Abedalkareem signIn() returns 'success' for me or throws an error. I do think a void method would be more appropriate though, and clean the code up. The signIn call should be in a try-catch block.

I do think something is printing null to the console though.

@theLee3
Copy link
Collaborator

theLee3 commented Dec 1, 2023

Also ensure that the OAuth consent screen is available to external users or that all users attempting to sign in are added as testers on the GCP project.

And double check all of this common issue points.

@erperejildo
Copy link
Author

@theLee3 what is GamesServices.signIn() supposed to return? I believe this returns null for me too. However, isSignedIn then returns true as expected.

@erperejildo the screen capture you provided above here looks like a Play Games v1 sign-in dialog. Can you confirm whether you're using games_services 3.x (using Play Games v1) or 4.x (Play Games v2, different dialog)?

I'm using games_services: ^4.0.0

@erperejildo Did you add your debug keystory SHA-1?

I added both, debug and release. I'd suggest adding this to the documention, just to avoid the case of copying the wrong one as I did in the first try (because Google Play Console pops up the release one as a recommendation and it might be confusing).

Hi @andynewman10 @erperejildo , signIn returns no result, and if it fails it will throw an exception, I'll update the return to void. Sorry for the trouble.

Ok. In my case, GameAuth.isSignedIn is also returning false

  • gradlew signingReport

not sure how to get that. Am I doing it correctly?

PS C:\Users\d15_1\Desktop\repos\times_ap\android> ./gradlew signingReport

> Task :gradle:compileGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit 'C:\flutter\packages\flutter_tools\gradle\src\main\groovy\app_plugin_loader.groovy' Unsupported class file major version 65

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s

Also ensure that the OAuth consent screen is available to external users or that all users attempting to sign in are added as testers on the GCP project.

And double check all of this common issue points.

Didn't we mention that when click publish there is nothing we can change after that? It should be accesible while in testing as well, right?

Checking that list, I also added the user I have in emulator/device to tests users:
"While publishing status is set to 'Testing,' only test users are able to access the app"

I tried after this but didn't do anything unfortunately.

@andynewman10
Copy link

@erperejildo gradlew signingReport failing is fishy. You need to debug this. It might suggest your build is failing somewhere, and because of this you might currently be debugging an old build.

@andynewman10
Copy link

@erperejildo restart your machine, do a flutter clean, then flutter pub get, then rebuild your project from scratch (e.g., flutter build appbundle). If the build is successful, go to the android directory and issue a gradlew signingReport. As for the games_services version, look in the pubspec.lock file.

@andynewman10
Copy link

andynewman10 commented Dec 2, 2023

@theLee3 I confirm signIn() returns null for me for both games_services 3.0.3 and 4.0.0. This is so weird! How come you get 'success'?

@erperejildo In the Play Console, in the Game Project settings, click the Examine and publish button in the top right corner. There is a Testers tab there. You need to add the email address of your Google Account there too. Adding an email address only in the OAuth part (Cloud Console) is not sufficient.

Once you've done that, wait 10-20 minutes and try again. It should work.

@andynewman10
Copy link

@erperejildo the screen capture you provided above #129 (comment) looks like a Play Games v1 sign-in dialog. Can you confirm whether you're using games_services 3.x (using Play Games v1) or 4.x (Play Games v2, different dialog)?

The sign-in dialog is the same between PGSv1/PGSv2 (games_services 3.0.3/4.0.0). I checked again and I was wrong, sorry about this.
The dialog I was showing is displayed only when a Play Games profile has never (ever) be created for a particular Google Account before. I don't know under which software setup it is displayed though (PGSv2 only, or PGSv1, Android 13+ only etc.). At the time this was displayed I was using Android 13 Go and PGSv2, for sure.

@erperejildo
Copy link
Author

@erperejildo restart your machine, do a flutter clean, then flutter pub get, then rebuild your project from scratch (e.g., flutter build appbundle). If the build is successful, go to the android directory and issue a gradlew signingReport. As for the games_services version, look in the pubspec.lock file.

This took me a while so I'll go step by step.

The game_services is version 4 as mentioned. This app is 2 weeks old and also the pubspec.lock is pointing to the same version.

I upgraded Flutter yesterday and didn't compile after that. Trying now I saw that I was getting an issue. This was fixed by removing some file in /.gradle so it might be in conflicting with the key maybe?
The thing is that I compiled with flutter build appbundle --release ok after that.

Now I tried again ./gradlew signingReport and I got exactly the same problem as before:
> BUG! exception in phase 'semantic analysis' in source unit 'C:\flutter\packages\flutter_tools\gradle\src\main\groovy\app_plugin_loader.groovy' Unsupported class file major version 65
With another app it did work.

So I went here: https://maven.google.com/web/index.html?q=tools#com.android.tools.build:gradle and remove the 7.3.0 version and took the last one: 8.2.0

Now more things... when trying again to build it fails saying:

> Android Gradle plugin requires Java 17 to run. You are currently using Java 11.    
      Your current JDK is located in C:\Program Files\Android\Android Studio\jre  

Weird thing because java -version said that I was using 21. But it seems that it's taking the one from the Android folder, not the java that I have installed. So I went to Android Studio and updated some SDK Tools. Found that it shoud be changed here:

https://i.stack.imgur.com/85e6U.png

but to make things more complicated I don't see this part:

image

searching different places in Google I found this other one:

image

This change "worked". At least, removed the previous error BUT added a new one (this doesn't end):

image

Now here I'm confused. Definetely, settings.gradle is present (and open) in the root of the android folder.

At this point I was totally tired so I decided to create a new project and copy lib, assets, etc. to it.

But nah... the problem was still there.

And this is where I am right now. Everything points to gradle-wrapper.properties and this line:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Some people say to change this version and try again. That's what I also did but with no luck

@erperejildo
Copy link
Author

@theLee3 I confirm signIn() returns null for me for both games_services 3.0.3 and 4.0.0. This is so weird! How come you get 'success'?

@erperejildo In the Play Console, in the Game Project settings, click the Examine and publish button in the top right corner. There is a Testers tab there. You need to add the email address of your Google Account there too. Adding an email address only in the OAuth part (Cloud Console) is not sufficient.

Once you've done that, wait 10-20 minutes and try again. It should work.

GameAuth.isSignedIn also returns false to yuo?

You mean here?

image

I added it there also and waited 30 minutes. Nothing changed

@theLee3
Copy link
Collaborator

theLee3 commented Dec 2, 2023

My bad everyone... @andynewman10, you are correct. signIn does in fact return 'null'. 'success' is logged to the console from Kotlin.

@andynewman10
Copy link

I clicked Confirm, then followed the validation process (responded to the email then went to the Google Search Console to validate my domain). Somehow GCP still does not react to my validation on Search Console (basically I am stuck here). Will see tomorrow if the situation changed.

The validation is now complete.

I actually didn't have to do 'Back to testing', as suggested in the link I provided above. Instead, after a few hours, I was sent an email saying my website needed to comply with my branding, and other requests. I fullfilled the demands and everything went fine.

The only hesitation I had was about the scopes: I only left the games_lite scope (not games_lite + games). I am now heavily crossing my fingers and am waiting to see if this scope will be sufficient for in-the-wild login-only Play Games v2 functionality. 🤞 😵‍💫 (I am not using scores/leaderboards right now as I said before).

Somehow I haven't found much info about games vs games_lite, so I assumed games_lite alone was OK (it seems to be fine according to my testing).

@theLee3
Copy link
Collaborator

theLee3 commented Dec 16, 2023

@andynewman10 I'm not sure about the differences between the 2 either. I wonder, with v2's seamless flow, if you need to declare any scopes there. It seems to be implied by the framework, and I tested briefly with no scopes and still had access to everything, including saved games. Point is, I think you'll be fine 👍

@andynewman10
Copy link

@theLee3 thank you!

@theLee3
Copy link
Collaborator

theLee3 commented Jan 3, 2024

FTR @andynewman10, I have since confirmed that PGSv2's implementation does not negate the need for scope declarations in the GCP project. Login continued to work fine, but once propagated all other PGS functionality broke.

@andynewman10
Copy link

andynewman10 commented Jan 3, 2024

@theLee3 thanks for the information.
Actually, I have noticed the following today in my Android 11 log (Google Pixel 2), right after authentication took place:

2024-01-03 19:44:36.357 14577-32327 SignInPerformer-4       com.google.android.gms               I  Requested scopes is empty. Promoting to `games_lite` & `drive_appfolder`. [CONTEXT service_id=1 ]

Does this mean PGS automatically (kind of automagically) obtains the drive_appfolder scope? So weird! The only scope I have is games_lite, I just checked.

@andynewman10
Copy link

Here is all the relevant log (running an Internal Test build):

2024-01-03 19:44:36.326 14577-28504 AlertsManager           com.google.android.gms               I  (REDACTED) current session %s
2024-01-03 19:44:36.329 14577-25474 SignInPerformer-2       com.google.android.gms               I  Connection from games connect service, returning false for shouldShowWelcomePopup. [CONTEXT service_id=1 ]
2024-01-03 19:44:36.330 14577-32350 GamesConnectResMan      com.google.android.gms               I  (REDACTED) Recorded engagement for game %s
2024-01-03 19:44:36.334 14577-25474 GamesConnectSignInOp    com.google.android.gms               I  (REDACTED) signIn(%s): Returning SUCCESS (%s) for request %s
2024-01-03 19:44:36.351 14577-18767 GetServiceValidatorImpl com.google.android.gms               I  (REDACTED) onGetService() from Client SDK version [%s], Module version [%s], PGA version [%s], Account [%s], Calling package [%s], Game package [%s]
2024-01-03 19:44:36.352 14577-18767 GetGamesServiceReqFacto com.google.android.gms               W  Parsing request with ignored arguments. signInOptionsBundle [Bundle[mParcelledData.dataSize=1292]], isRetryingSignIn [false], skipWelcomePopup [false], requireGooglePlus [false]
2024-01-03 19:44:36.357 14577-32327 SignInPerformer-4       com.google.android.gms               I  Requested scopes is empty. Promoting to `games_lite` & `drive_appfolder`. [CONTEXT service_id=1 ]
2024-01-03 19:44:36.358 14577-32327 SignInPerformer-4       com.google.android.gms               I  (REDACTED) Handling request [%s], isFirstPartyCaller [%s]
2024-01-03 19:44:36.358 14577-32327 SignInPerformer-4       com.google.android.gms               I  (REDACTED) java sdk version: [%s]	unity sdk version: [%s]
2024-01-03 19:44:36.366 14577-32327 SignInPerformer-4       com.google.android.gms               I  (REDACTED) Found existing game run [%s]
2024-01-03 19:44:36.381 14577-32327 SignInPerformer-4       com.google.android.gms               I  (REDACTED) Successfully resolved account: [%s]
2024-01-03 19:44:36.413 14577-32327 SignInPerformer-4       com.google.android.gms               I  (REDACTED) Successfully authorized %s
2024-01-03 19:44:36.413 14577-32327 PlayerManager           com.google.android.gms               I  (REDACTED) Fetching player: account [%s] gamePackageName [%s] forceServerFetch [%s] getLegacyPlayerIdResponse [%s]
2024-01-03 19:44:36.423 14577-32327 PlayerManager           com.google.android.gms               I  (REDACTED) Found player: account [%s] validatedLegacyPlayerId [%s] playerId [%s] legacyPlayerId [%s]
2024-01-03 19:44:36.423 14577-32327 SignInPerformer-4       com.google.android.gms               I  (REDACTED) Successfully found player (id [%s], originalId [%s], displayName [%s]) for account [%s]

@andynewman10
Copy link

Note that I almost never look at the logcat, which I don't know how to consult in VS Code (?). I checked the above logcat with Android Studio.

@theLee3
Copy link
Collaborator

theLee3 commented Jan 3, 2024

Yes, the v2 scopes are indeed added to the sign-in request by the PGS sign-in flow. Interesting though, is the lack of the games scope, bringing further scrutiny to its purpose and differences from games_lite.

While the scopes are attached to the sign-in request, they are not actually granted unless the GCP configuration matches. In your case, as you have declared the games_lite scope on GCP you would have functionality to everything but the saved games feature. Even though the scope is included in the sign-in request, and even if you turn on saved games on the Play Console, since the scope is not added to your GCP project, your app could not get permission to access resources under this scope on the user's behalf. Any request related to saved games would return an error that the feature must be activated in the Google Play Console.

This also explains why sign in can be achieved with no scopes declared on GCP, but all other functionality fails.

@erperejildo erperejildo reopened this Mar 12, 2024
@erperejildo
Copy link
Author

erperejildo commented Mar 12, 2024

@theLee3 there is something going on after logging in with 2 users on one device. Since I did this on my phone, I'm unable to test anything else on this device.

Right now, when I build, I don't see any user notification being logged in. GameAuth.isSignedIn is returning false. So I show the button "Sign in with GPG" and this calls GameAuth.signIn(), looking ok with my user:

image

but after this, I get false again.

Future<bool> signIn() async {
    try {
      await GameAuth.signIn();
      return await isSignedIn();
    } catch (error) {
      debugPrint(error.toString());
      return false;
    }
  }

Future<bool> isSignedIn() async {
    var isSignedIn = await GameAuth.isSignedIn;
    return isSignedIn; // ending up here with false again
  }

NOTE: on emulator it doesn't even show the login popup.

I don't face the same issue, for example, on my wife's phone with her account, where I just test from the released version always (and never using my account). She only has her account there. On my phone, I have multiple accounts, including hers. All of them show up here (changing to another one doesn't work):

image

And of course, I didn't change any configuration anywhere. This was (and it "is") working fine, the only problem wast that, linking my 2 accounts.


Edit:
I wiped out the emulator and tried with my wife's account this time from scratch. It doesn't even show the initial popup after triggering GameAuth.signIn();:

image

What I did:

  • Wipe out
  • Run app
  • GameAuth.signIn()
  • Log in with Gmail on the phone
  • GameAuth.signIn()
    Nothing happens

I remember doing this before, and after all of that, I got a warning saying I had to install/update Google Play Games from the store. I am not sure if this is a regression or not. So I installed it manually and continued the test with this installed...

...but nothing happens.

So I decided to use my wife's phone to test and this time I got exactly the same behaviour; it doesn't show anything.

In resume, only my phone is showing the popup, rest of the devices (reals or emulators), don't, but in any of them, I can log in.

@theLee3
Copy link
Collaborator

theLee3 commented Mar 12, 2024

@erperejildo please confirm that you can login to other games on the devices. If possible, confirm that switching between multiple accounts work as well.

@erperejildo
Copy link
Author

Good point.

Trying on another app, I don't face the same situation, but both work in a different way. In this one, I don't have any Firebase implementation, while in the other one I'm comparing to, the user is sent from Firebase.

So this one is just this:

 Widget gpgButtons() {
    return FutureBuilder<bool>(
      future: GPG().isSignedIn(),
      builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
        if (snapshot.hasData) {
          if (snapshot.data == true) {
            return Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                statsButton(),
                achievementsButton(),
              ],
            );
          } else {
            return signInPGAButton();
          }
        }
        return signInPGAButton();
      },
    );
  }

Since isSignedIn() is returning false I show the Sign in button all the time.

In this other one:

class Auth extends ChangeNotifier {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  late String userId;

  getUser() {
    return _auth.currentUser;
  }

-----

 Widget build(BuildContext context) {
    return Provider.of<Auth>(context).getUser() != null
        ? Container(
...

But it's true that here, I do get true:

if (Provider.of<Auth>(context, listen: false).getUser() == null) {
            await GPG().isSignedIn().then((isSigned) async {
              if (isSigned) return _showCreateAccountAlert(context); // HERE

              await GPG().signIn().then((value) {
                if (value) return _showCreateAccountAlert(context);
              });
            });
          } else {
            Navigator.of(context).pushNamed('/new-set');
          }

Here, I have placed both functions/apps next to each other. Before this, I don't do anything related to the GPG at all in any of them:

image
left is always false and right always true and both GPG methods are the same

@erperejildo
Copy link
Author

I just checked Google Consoles's notifications and found this:

image

@theLee3
Copy link
Collaborator

theLee3 commented Mar 12, 2024

I'm not sure that GPG login would fail due to billing not being enabled, but I suppose it could break the whole project. Try to enable billing and try again.

@erperejildo
Copy link
Author

I'm not sure that GPG login would fail due to billing not being enabled, but I suppose it could break the whole project. Try to enable billing and try again.

But in the same Console account, I have both apps, and the other one is working fine. The billing account is shared across all my apps. Shouldn't be the other one failing as well?

@theLee3
Copy link
Collaborator

theLee3 commented Mar 12, 2024

It may depend on if this app is using APIs (which require billing) that the other app is not. Billing is not necessary solely for GPG.

Another thought, ensure you have not triggered the API usage quota for GPG during your testing.

@erperejildo
Copy link
Author

erperejildo commented Mar 12, 2024

That's ok. I checked if I was getting this before, but today, while I got stuck, I've trying in the meantime to integrate Firebase as I did for the other app and created/removed some stuff. Not sure why is display but "I would say it's not related".

I double checked; I wasn't getting this before, and I got 2 notifications today after these changes:

image

Since other apps are working fine, notifications appeared just today and this was failing days before (and probably weeks) I wouldn't worry (I'll check it anyway).

Edit: about the billing thing, I don't see anything weird

image

@theLee3
Copy link
Collaborator

theLee3 commented Mar 13, 2024

So your billing account setup is fine, but make sure it is selected as the billing account for the project. Do so by selecting the project associated with the app. Open the navigation menu on the left and select billing.

@erperejildo
Copy link
Author

All the billing thing was fixed already, and the notification is green now.

The problem persists. It should come from another place but Google doesn't want to give me any idea.

I just opened this: https://stackoverflow.com/questions/78155719/cant-link-firebase-project-to-google-play

Again, I didn't have Firebase before, so this shouldn't be related, but I'm just trying to connect some dots.

What I'm going to do now is create a new flutter app with the basics and see if that one has any problem.

@theLee3
Copy link
Collaborator

theLee3 commented Mar 13, 2024

Good call. I am unable to replicate, so I cannot provide any more insight. Nothing stands out to me as a cause for the problem either. I look forward to hearing what you learn.

@erperejildo
Copy link
Author

erperejildo commented Mar 13, 2024

I tried with both IDs in a fresh new app and neither of them worked. I have the feeling I'm missing something really stupid (but I don't think so because I went to the tutorial several times).

https://github.com/erperejildo/test

Steps:

  • Created new project
  • Installed games_services 4.0.1
  • Changed AndroidManifest:
<meta-data android:name="com.google.android.gms.games.APP_ID" 
            android:value="WITH_MY_ID"/>
<meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
  • Added some simple logic:
class _MyHomePageState extends State<MyHomePage> {
  bool logged = false;

  @override
  void initState() {
    checkUser();
    super.initState();
  }

  checkUser() async {
    logged = await GPG().isSignedIn();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: logged
            ? const Text('user is logged in')
            : Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  const Text('user is not logged in'),
                  TextButton(
                    onPressed: () async {
                      await GPG().signIn().then((value) {
                        setState(() {
                          logged = value;
                        });
                      });
                    },
                    child: const Text('Sign in'),
                  ),
                ],
              ),
      ),
    );
  }
}
  • Didn't update any SHA-1 key because I'm just debugging and this app use the say key for it
  • await GPG().signIn().then((value) { is false
  • updated <meta-data android:name="com.google.android.gms.games.APP_ID" android:value="WITH_MY_ID"/> with the other ID (working one)
  • await GPG().signIn().then((value) { is false

@erperejildo
Copy link
Author

erperejildo commented Mar 15, 2024

I tried today again, but surprisingly, it worked. I didn't change anything at all from yesterday. I was getting GameAuth.isSignedIn as false and then I called GameAuth.signIn(). This time, after showing the popup and continuing, the first one was true.


UPDATE
When checking the working project, I had created a games-ids.xml. Since I saw in my game I didn't have this file, to make it exactly the same I created one file there and continued with this test. I thought this was a way to just have these IDs saved together.

If we follow the documentation (and comments from @Abedalkareem) it says this:

image

So I had this:

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

and that does not work. At least not now. Not sure why it worked before for me, but updating the working project like that, breaks it.
This is the working way:

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

Please, update that part of the written tutorial.

Let's continue...

At this point I'm still logged in but when trying to load the game, it fails saying:
"4: SIGN_IN_REQUIRED"
but also:
"Cannot use snapshots without enabling the 'Saved Game' feature in the Play console"

image

image

When showing the leaderboard I get:
"Not signed in when calling API"

For achievements:
"4: SIGN_IN_REQUIRED"

Are both the same error?

I checked already for this, but it's fine:
#126 (comment)
#22
#127

BUT

on emulator everything is fine: no popup, logged, achievements, saved games, achievements...

@theLee3
Copy link
Collaborator

theLee3 commented Mar 15, 2024

Those are all the same error. It is an authentication issue. If isSignedIn is true, the issue is likely permissions for the user signed in or app/services configuration.

@erperejildo
Copy link
Author

but I haven't changed user. It was always the same one

@theLee3
Copy link
Collaborator

theLee3 commented Mar 16, 2024

I suggest you reach out to Google Play Console support and see if they can provide any insight from their side as to what is causing the issue. Even if it's something in the package or on your end, they can likely give you more specific details of the failure from their end.

@erperejildo
Copy link
Author

I sent this already to Google and they said they will have a look. Let's see.

Testing also with a friend remotely, after he logs in, the app breaks. Not sure why (I don't have his phone with me)

@erperejildo
Copy link
Author

erperejildo commented Mar 28, 2024

@theLee3 I could try on a different friend's phone and it was failing there. I found out that the 2 phones failing had Android 9 so I did a new test with 2 emulators. One with Android 14 and the other with Android 9:

image

With the last one, I can't log in. I run GameAuth.signIn() but nothing happens. Android 14 is using the same account, and it's totally fine, I can log in and also check leaderboards/achievements.

I can't see here anything related to Android versions, but if we follow official documentation it says from Android 5.

@theLee3
Copy link
Collaborator

theLee3 commented Mar 28, 2024

Does the emulator with Android 9 have the Google Play Games app installed? If I'm not mistaken, on older Android versions, an attempted Play Games login by an app should lead to a popup to install the GPG app if it is not available. I will have to look into it though.

@erperejildo
Copy link
Author

erperejildo commented Mar 29, 2024

Does the emulator with Android 9 have the Google Play Games app installed? If I'm not mistaken, on older Android versions, an attempted Play Games login by an app should lead to a popup to install the GPG app if it is not available. I will have to look into it though.

GPG is installed on Android 9. If it's not, the app doesn't tell you anything, but it does if Google Services is not updated. After updating that, it was still failing, so I also installed GPG (as I said, no warning for this) and got the same result.

On Android 14, it wasn't installed, and it was working. After installing it, it was also working, no difference.

Also, another difference that might be related, on Android 9 when opening Play Games, when showing profile takes ages (but I guess it is just the emulator itself).

Unfortunately I wasn't able to reproduce the same issue my friends were having after opening the app:
image

Mine was more related to just being unable to log in to GPG, but for sure, Android version should be related here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants