flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[📚] Google Sign-In documentation is a confusing mix between old and new procedures.

Open lucavenir opened this issue 1 year ago • 14 comments

Hi there,

As the title states, I want to notify how configuring Google Sign In - for me - is becoming really confusing if not actually impossible. This issue follows this issue, as it is now closed as resolved, but I think there's more onto it.

Say we want to initialize a new Flutter Project with Google Sign In. Then, I'd initialize Flutter Fire as mentioned here. Thanks to this issue I acknowledged that google_sign_in doesn't support dart-only initialization.

Then, I search for more documentation. I end up going through the archived (and therefore potentially old) documentation; I follow these instructions. I read:

Dart-only Firebase initialization isn't yet supported by google_sign_in plugin, if you're using Google as an auth provider you'll still have to do the manual installation steps to integrate the Firebase configuration files.

Okay. I'll then follow the manual instructions linked there, and apply whatever I'm told. The manual instructions page is full of warnings that scare me even more:

NOTICE This page is archived and might not reflect the latest version of the FlutterFire plugins. You can find the latest information on firebase.google.com:

https://firebase.google.com/docs/flutter/setup CAUTION Manual installation is not the recommended installation flow. These guides are for existing applications using FlutterFire.

Ok... but I guess I have no choice, right? And again the docs say:

In previous versions of FlutterFire, in order to add Firebase to your projects manual platform specific steps were required, such as downloading a google-services.json file for Android, downloading a GoogleService-Info.plist file for iOS or editing your index.html file for web.

FlutterFire now supports initialization from Dart using the FlutterFire CLI.

The new Dart-only initialization is fully backwards compatible with previous versions of FlutterFire - if you have an existing project with manual initialization, this will continue to work.

Ok... but I need manual installation. It doesn't look like there're alternatives. I then navigate to the iOS documentation. More warnings, ok, skip that and try to follow the procedure.

I add the .plist file as shown there. I then start the app to test that out. I click on a simple "Google Sign In" button. Something goes wrong immediately.

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

This is showing up even though GoogleService-info.plist is clearly there.

I try to search for more intel online and I end up going to the google_sign_in dart package. There, the iOS instructions are different. They mention adding a CFBundleURLTypes to Info.plist. I follow those instructions, too, and try again. I still get the error:

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

At this point I'm totally lost and I have no clue of what to do. Can we have proper, clearer and good documentation, with one single source of truth? Shouldn't flutterfire configure handle these details instead, as stated in #96?

lucavenir avatar Jul 21 '22 10:07 lucavenir

Thanks to this issue I acknowledged that google_sign_in doesn't support dart-only initialization.

@lucavenir google_sign_in now seems to support dart-only initialization, as the relevant PR was merged recently: https://github.com/flutter/flutter/issues/96391

Maybe now can you try the plugin with this initialization and see if the experience is smooth ?

darshankawar avatar Jul 21 '22 11:07 darshankawar

I'm not sure what documentation should I follow, though.

It looks like @mono0926 fixed the issue; this comment seems to indicate that I should just install the package, follow its dart instructions and I'll be good to go.

But here's what I did:

  1. Created a new Firebase Project, with firebase init
  2. Created a new Flutter Project flutter create app --org com.mybrand --platforms ios,android
  3. Ran the dart pub global activate flutterfire_cli && flutterfire configure --project=my-project commands
  4. Ran into some issues mentioned in #9169 and fixed them (multidex, initialization, min AndroidSDK, min iOS version)
  5. Added a SHA key for Android (although I'm testing on a iOS simualtor)
  6. Added Google as a Sign In option via the Firebase console
  7. Followed the google_sign_in instructions from pub.dev (except I didn't manually add the .plist file again, as the previous steps already put that in there for me)
  8. Added a simple "google log in button" in my dummy Flutter App too see what happens... output:

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

This is weird as I can clearly see that file added in app/ios/Runner/GoogleService-Info.plist.

So, how should one use google sign in at this point? I think it's crucial to update and have some organic documentation of these "basic" firebase services at the moment. Or at least to have a published and documented workaround.

lucavenir avatar Jul 21 '22 14:07 lucavenir

8. Added a simple "google log in button" in my dummy Flutter App too see what happens... output:

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

This is weird as I can clearly see that file added in app/ios/Runner/GoogleService-Info.plist.

So, how should one use google sign in at this point?

@lucavenir Although I didn't create a dummy Flutter project from scratch, but have a running Flutter + Firebase wired up project with dart-only initialization, in which, I added google_sign_in plugin and ran it which compiled properly and upon tapping sign in , works properly as below:

Screenshot 2022-07-22 at 12 35 59 PM

I also have the GoogleService-Info.plist file in place.

Can you provide your flutter project setup details so that we can take a look ?

darshankawar avatar Jul 22 '22 07:07 darshankawar

Hi there,

I just replicated every step cited in here.

Can you provide your flutter project setup details so that we can take a look ?

Sure thing, I created a repo in which I replicate these exact steps. There's a quick description in the readme.

I hope this helps finding the problem

lucavenir avatar Jul 22 '22 08:07 lucavenir

Thanks for these details. In your repo, I see that you mentioned below error:

result: I/flutter ( 7885): Error: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)

Which is different from the one you shared earlier:

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

Which one are you getting consistently ?

If it is the former, then there's an open issue in flutter repo for it: https://github.com/flutter/flutter/issues/33393 in which you can check underlying comments and see if they help.

darshankawar avatar Jul 22 '22 11:07 darshankawar

  1. Created a new Firebase Project, with firebase init

I've never tried creating Firebase project from terminal, which I'll try out soon. But maybe you can try to create one from firebase console itself and try too ?

darshankawar avatar Jul 22 '22 11:07 darshankawar

Hi @darshankawar I did, although it doesn't look like this has an impact into my issue.

I can see that the error

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

mentions not being able to find the config file, even though it's right there. google_sign_in needs the clientId from that file OR you can provide it programmatically (i.e. hard code it by copy pasting from the config file). But shouldn't the configuration pick up such info from the file instead?

lucavenir avatar Jul 22 '22 13:07 lucavenir

Sorry for coming back late on this. I cloned your repo and do see same error as you mentioned.

flutter: Error: PlatformException(missing-config, GoogleService-Info.plist file not found and clientId was not provided programmatically., null, null)

I noticed few things in your repo and tried fixing them, but have been getting another unrelated compile error which I need to look into, but below are some things I tried:

  1. Added GoogleService_Info.plist which I didn't see in your project structure.
  2. Added below code in your main() method:
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

  runApp(MyApp());
}
  1. Noticed lot of other FF plugins, so, commented them and kept only firebase_auth, firebase_core and google_sign_in.
  2. Uncommented platform :ios, line in ios/podfile and updated it to 11.0

After above, I am getting:

 "/Users/dhs/Documents/NCFlutter/google-sign-in-test/app/build/ios/Debug-iphonesimulator/Runner.app.dSYM/Contents/Resources/DWARF/Runner"
    Running upload-symbols in Build Phase mode
    Validating build environment for Crashlytics...
    warning: DEBUG_INFORMATION_FORMAT should be set to dwarf-with-dsym for all configurations. This could also be a timing issue, make sure the Firebase run script build phase is the
    last build phase and no other scripts have moved the dSYM from the location Xcode generated it. Unable to process Runner.app.dSYM at path
    /Users/dhs/Documents/NCFlutter/google-sign-in-test/app/build/ios/Debug-iphonesimulator/Runner.app.dSYM
    Make sure your project build settings are generating a dSYM file.


    Processing dSYMs...
    Command PhaseScriptExecution failed with a nonzero exit code

Pointing to crashlytics settings probably. Can you take a look at this error and see if resolving it and then running the app folder from your project compiles and eventually try to sign in and see if you still get same error or not ?

darshankawar avatar Jul 26 '22 11:07 darshankawar

Hi there,

Thanks for your reply.

  1. Added GoogleService_Info.plist which I didn't see in your project structure.

I can clearly see my GoogleService_Info.plist here. Is there anything I'm missing, here? Even if so, as stated above (step 3) I initialized the project with flutterfire configure. No further actions are required nor asked in the Firebase Console or the Documentation. If anything besides that should be done (and the issues cited in #9169), then it should be documented. Even better, I'd expect flutterfire configure to handle all of this process (see this issue).

EDIT. Below I'll repeat myself about such issue, but I guess it is necessary as it shows how much that is a needed thing to smooth out this process.

  1. Added below code in your main() method

Thanks, I totally forgot that in this repo, but I always do that in my actual app(s). It doesn't really change much though.

Noticed lot of other FF plugins, so, commented them and kept only firebase_auth, firebase_core and google_sign_in.

How are other Firebase Plugins related to problems with firebase_auth with google_sign_in? Anyways, I plan to use such Plugins in my production app (for obvious reasons), so I don't see this as a problem tbh.

Uncommented platform :ios, line in ios/podfile and updated it to 11.0

If this is a thing, this should be documented. If anything, again, flutterfire configure should have done this for me. Furthermore, since it's still supported, I'd use iOS 10, right?

Pointing to crashlytics settings probably. Can you take a look at this error and see if resolving it and then running the app folder from your project compiles and eventually try to sign in and see if you still get same error or not?

I hardly see what crashlytics has to do with this issue. Furthermore, I never got this error message before, I'm not sure how to help you. This is something you're getting after manually altering some of the files above, so I'm not sure I can reproduce this. I guess I can try.

Anyways, I tried to install the above repo on my Android Device and - still - it doesn't work. This is the message I get:

Error: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)

I'll reach back with more testing on my MacOS soon.

lucavenir avatar Jul 27 '22 13:07 lucavenir

Hi again,

  1. Added GoogleService_Info.plist which I didn't see in your project structure.

I guess you meant to add GoogleService_Info.plist to XCode. If that's the issue, I just did that to try replicate your building error(s). No errors are displayed to me at build time.

Nonetheless, something changed. When I click the "Login with Google" button, the application crashes. Error message shown on the terminal before crash:

flutter: Error: PlatformException(google_sign_in, Your app is missing support for the following URL schemes: com.googleusercontent.apps.561734077415-53ofktkaonkg6497489o3khu3koosk2i, NSInvalidArgumentException, null)

Furhtermore, on further trials, such error message doesn't show anymore: the app just crashes.

EDIT. I pushed the changes you suggested, @darshankawar, so that the issues are more reproducible.

lucavenir avatar Jul 27 '22 13:07 lucavenir

flutter: Error: PlatformException(google_sign_in, Your app is missing support for the following URL schemes: com.googleusercontent.apps.561734077415-53ofktkaonkg6497489o3khu3koosk2i, NSInvalidArgumentException, null)

This probably indicates that the google_sign_in setup / config is missing below, as mentioned in plugin's readMe:

Then add the CFBundleURLTypes attributes below into the [my_project]/ios/Runner/Info.plist file.
<!-- Put me in the [my_project]/ios/Runner/Info.plist file -->
<!-- Google Sign-in Section -->
<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleTypeRole</key>
		<string>Editor</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<!-- TODO Replace this value: -->
			<!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
			<string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string>
		</array>
	</dict>
</array>
<!-- End of the Google Sign-in Section -->

darshankawar avatar Jul 28 '22 05:07 darshankawar

This probably indicates that the google_sign_in setup / config is missing below, as mentioned in plugin's readMe

Such configuration is done as explained in the first comment above and as you can see it's right here in my repo.

I thank you for your assistance, but aren't we running in circles at this point?

This issue clearly showcased that the documentation deceives the developer away from correct procedures as there is no clear indication on how to configure Firebase Auth w/ Google Sign In. You yourself experienced such problems, and then even more problems when you tried to address those.

Wonder why?

Cause there's no clear documentation on how to initialize these plugins with Flutter!!

This is what this issue is about. I'd like to have a clear response - but even better - to have clear and easy-to-find documentation about these topics. This would be really awesome for the community.

Let me know what I can do to help.

lucavenir avatar Jul 28 '22 07:07 lucavenir

Thanks for your feedback and patience. Going ahead and labeling it for further insights from the team on this.

/cc @kevinthecheung @russellwheatley

darshankawar avatar Jul 28 '22 09:07 darshankawar

I can see the platform: ios tag. I can kind-of apply the above statements for android, too, since this is a documentation issue. I'll file a detailed android report while following the documentation and see if I'm able to "log in with google".

lucavenir avatar Jul 28 '22 21:07 lucavenir

@lucavenir When you open the project with Xcode do you see GoogleService-Info.plist file under Runner directory? If not then you need to link the file to xcode. Follow this if you need help https://www.kindacode.com/article/flutter-correctly-adding-googleservices-info-plist-to-ios/

adar2378 avatar Jan 24 '23 11:01 adar2378

Hi Lucas, flutterfire configure will also install the service file for android and iOS as standard now, it no longer just creates the firebase_options.dart file. Therefore, there are no further procedures other than what is documented here. Sorry for the confusion. We stopped just creating the firebase_options.dart file when we realised that some plugins require the service file. For further details on why, see this comment on the FlutterFire CLI repo.

russellwheatley avatar Feb 07 '23 16:02 russellwheatley

Hi @russellwheatley! Thank you!! This is very helpful. @adar2378 sorry I didn't reply, I hadn't the time to verify your suggestion.

Thank you for being active, kind interest and for actually solving problems for us (:

lucavenir avatar Feb 07 '23 16:02 lucavenir