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)
Steps taken:
Added package name and SHA1 fingerprint in the google cloud console for my app:
--
AndroidManifest.xml (internet permissions are there) 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.
Found the issue with this- It was because of the incorrect key SHA-1 key. For people implementing google sign-in without firebase:
flutter doctor -v
It will return the java bin library path: Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
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
keytool -list -v -keystore <path\to\your\jks\file>
Enter you password:
Copy the SHA-1 key returned (We will be using this key)
Google sign-in should work as expected.