DEV Community

Cover image for How to prevent exceptions when using google_sign_in in flutter
Jyotirmaya Sahu
Jyotirmaya Sahu

Posted on

How to prevent exceptions when using google_sign_in in flutter

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, com.google.android.gms.common.api.ApiException: 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.

Create a new Project

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

Give name to project

  • 3. Wait for the project to get created.

Creating Project

  • 4. Click on add android application button.

Select Android app

  • 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.

Add Application details

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

Download google-services.json

  • 7. Don't forget to add the following to the respective files.

Add to android

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

Cloud Console

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.

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

Top comments (0)