Flutter and google_sign_in plugin: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
Troubleshooting Flutter and google_sign_in Plugin: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null) 🐛🚧
Hey there! Having trouble with your Flutter app and the google_sign_in
plugin? Don't worry, we've got your back! 👊 In this blog post, we'll help you troubleshoot and solve the PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10:, null)
error. Let's dive right in! 🏊♂️
Understanding the Problem 🕵️♂️
This error occurs when using the google_sign_in
plugin to authenticate with Google, but the sign-in operation fails. The stack trace you provided shows that the error is thrown at this line of code:
await _googleSignIn.signIn();
The error message you're seeing is: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10:, null)
. This error usually stems from issues with the Google Play Services on the Android device.
Possible Solutions 💡
To fix the PlatformException(sign_in_failed)
error, you can try the following solutions:
1. Update Google Play Services ⬆️
Make sure the Google Play Services on the Android device are up to date. An outdated version of Google Play Services could cause authentication errors. To update Google Play Services, follow these steps:
On your Android device, open the Google Play Store.
Tap the menu icon (three lines) in the top-left corner of the screen.
Tap "My apps & games."
Under the "Updates" tab, locate "Google Play Services" and tap the "Update" button if available.
2. Enable Google Play Services on the Virtual Device 📱
If you're testing your app on an Android emulator, make sure that Google Play Services is enabled on the virtual device. Here's how you can do it:
Open the Android Virtual Device Manager (AVD).
Click on the pencil icon (Edit) next to your virtual device.
In the "Hardware" section, click the "New" button.
Select "Play Store" from the dropdown menu and click "Finish."
Click "Finish" again to save the changes.
Launch the virtual device and run your app again.
3. Check the SHA-1 Fingerprint 🔑
Ensure that the SHA-1 fingerprint of your Android app is added to the Firebase project. To check and add the SHA-1 fingerprint, follow these steps:
Open the Firebase console and go to your project.
Click on the gear icon (Settings) in the top-left corner and select "Project settings."
Scroll down to the section "Your apps" and select the Android app.
If the SHA-1 fingerprint is missing, click on "Add fingerprint" and follow the instructions to add it.
4. Enable the Required APIs in the Google APIs Console ⚙️
Ensure that the necessary APIs are enabled in the Google APIs Console. Since you mentioned needing the Google Drive API, make sure it is enabled. To enable the API, follow these steps:
Go to the Google APIs Console.
Select your project.
In the sidebar, click on "Library."
Search for the required API (e.g., Google Drive API) and click on it.
Click the "Enable" button if the API is not already enabled.
5. Check Your Package Name and SHA-1 Key Match 🔑
Make sure the package name in your Firebase project matches the package name in your Flutter app, and the corresponding SHA-1 fingerprint is added to the project. To check and update these details, follow these steps:
Open the Firebase console and go to your project.
Click on the gear icon (Settings) in the top-left corner and select "Project settings."
Scroll down to the section "Your apps" and select the Android app.
Verify that the package name matches the one in your Flutter code.
If the package name is incorrect, click on "Register app" and follow the instructions to add the correct package name.
Conclusion and Call-to-Action 🏁📣
We hope these solutions helped you resolve the PlatformException(sign_in_failed)
error with the google_sign_in
plugin in your Flutter app. Now, it's time for you to give it a try and let us know if it worked for you! 🤞
If you have any further questions or run into any other issues, feel free to leave a comment below. We're here to help you out! Happy coding! 😄🚀