How to use google_sign_in in flutter without any weird exceptions

I was building an app which requires me to link user’s google drive in my application to store data. But doing that requires fetching the access token from google_sign_in.

Now, although it is not a very difficult task, many people like me struggle with the exception.

PlatformException(sign_in_failed, 10: , null, null)

Well, this is something I banged my head for. Now, lets get to the point. How to avoid this ? The answer is really simple, by using firebase. But wait, not the google login provided by firebase, but only a firebase project with your android application added in it (Don’t forget to add the SHA1 certificate though).

Google cloud console and firebase console share projects, so a project created in firebase can be accessed in the cloud console as well. Now, let’s see this through screenshots.

  1. First we go to the firebase console and click on create a new project.

2. Then we fill in the name and all other pages and create the project.

3. Wait for the project to get created.

4. Click on add android application button.

5. Fill in the package name, nickname and SHA1 certificate. The SHA1 can be fetched by running the following command in the android folder ./gradlew signingReport or gradlew signingReport.

6. Download the google-services.json file and place it inside your android/app directory and complete the process.

7. Don’t forget to add the following to the respective files.

8. Now, lets go the google cloud console, and we can find our newly created firebase project there with all necessary things already added.

Now, here we can configure the OAuth consent screen, and add scopes. This can be used now and login will work smoothly. We can edit this project and add web applications as well.

Don’t reveal your SHA1 and secrets to anyone or ever push them to a public remote repository. They can be used maliciously.