Search code examples
androidfluttergoogle-cloud-platformgoogle-signingooglesigninaccount

Keep getting the error Google Sign-In Error: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)


I'm trying to implement google sign-in for my app without firebase. I seem to have done all the steps suggested in the documentations, and for other answers, but i still keep getting this error:

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

enter image description here

Steps taken:

  1. Added necessary information for OAuth consent screen enter image description here --

  2. Added package name and SHA1 fingerprint in the google cloud console for my app:

  • Got the SHA1 fingerprint (running gradlew signingReport command) enter image description here

  • Added it with package name enter image description here

--

  1. Implemented the code:
  • AndroidManifest.xml (internet permissions are there) enter image description here This client Id is there in strings.xml

  • in app/build.gradle

         signingConfigs {
             debug {
                 keyAlias 'androiddebugkey'
                 keyPassword '*****'
                 storeFile file('mykey.jks')
                 storePassword '*****'
             }
         }
    
         buildTypes {
             debug {
                 signingConfig signingConfigs.debug
             }
         }
    
    dependencies {
            implementation 'com.google.android.gms:play-services-auth:20.7.0'
        }
    
  • in android/build.gradle

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
        buildscript {
            dependencies {
                classpath 'com.google.gms:google-services:4.3.10'
            }
        }
    }
    
  • Flutter login.dart

    class LoginAPI {
      static final _googleSignIn = GoogleSignIn();
      static Future<GoogleSignInAccount?> login() => _googleSignIn.signIn();
      static Future signOut = _googleSignIn.signOut();
    }
    
    onPressed: () async {
        var user = await LoginAPI.login();
        print('user.....');
        print(user);
    },
    

What am I doing wrong? Are there any more steps I'm missing.

NOTE: I'm implementing Google sign in without Firebase, as we also have a api to handle login. So google-services.json has not been added.

Any solutions from this post: https://stackoverflow.com/questions/54557479/flutter-and-google-sign-in-plugin-platformexceptionsign-in-failed-com-google did not help with the current issue for the same reason. Any other steps not involving firebase, and relevant to current implementation were already taken.


Solution

  • Found the issue with this- It was because of the incorrect key SHA-1 key. For people implementing google sign-in without firebase:

    1. First, run flutter doctor command: flutter doctor -v

    It will return the java bin library path: Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java

    1. Create you jks file: keytool -genkey -v -keystore '<path\wher\you\want\to\create\it\file_name.jks> -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias 'your_alias'

    Add details as requested, once the file is created - go to that path.

    Move the file to your projects 'android/app/' folder

    1. Run this command in android studio keytool -list -v -keystore <path\to\your\jks\file>

    Enter you password:

    Copy the SHA-1 key returned (We will be using this key)

    1. Add this sha fingerprint to you google cloud console.

    Google sign-in should work as expected.