I've been having the same error for two days, the problem is that Android Studio the only error it gives me is that; "Google: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)"
I am trying to do my login with Firebase
I have searched a lot of information and I can't find the solution. Previously it did give me more errors but I have been polishing it until I only left this one.
I leave you some configurations, so you can see if it is correct or not.
I have the firebase_options.dart and also install firebase-tools-instant-win.exe, doing my login.
My android/build.gradle is:
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.15'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
My build.gradle is:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
namespace "com.example.untitled"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.untitled"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 20
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
signingConfigs {
release {
storeFile file("xxxxxxxxx.jks")
storePassword 'xxxxxxx'
keyAlias 'xxxxxxxkey'
keyPassword 'xxxxxxx'
}
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:32.2.0')
}
My Main calls Firebase, in the Main code I doubt there is any error, it must be external. Since no error appears and without firebase YES there is the loggin
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(const MyApp());
}
I think the problem is in the Credentials, since I can't create a "Create OAuth client ID" because it tells me "The request failed because the Android package name and fingerprint are already in use"
The SHA keys are correct... everything else is correct, checked one, two, three... and four times, I don't see any errors anywhere.
PS: I add the code of my Main, eliminating EVERYTHING (since it is a very complete code) and leaving only the "logic" to start the session.
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:logger/logger.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Inicio de Sesión con Firebase')),
body: const SignInWithGoogleButton(),
),
);
}
}
class SignInWithGoogleButton extends StatefulWidget {
const SignInWithGoogleButton({Key? key}) : super(key: key);
@override
State<SignInWithGoogleButton> createState() => _SignInWithGoogleButtonState();
}
class _SignInWithGoogleButtonState extends State<SignInWithGoogleButton> {
final Logger _logger = Logger();
bool _isSignedIn = false;
@override
void initState() {
super.initState();
_checkSignInStatus();
}
Future<void> _checkSignInStatus() async {
final preferences = await SharedPreferences.getInstance();
setState(() {
_isSignedIn = preferences.getBool('isSignedIn') ?? false;
});
}
Future<void> _signInWithGoogle() async {
try {
final GoogleSignIn googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
if (googleUser != null) {
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(credential);
final User? user = userCredential.user;
if (user != null) {
setState(() {
_isSignedIn = true;
});
final preferences = await SharedPreferences.getInstance();
preferences.setBool('isSignedIn', true);
}
}
} catch (error) {
_logger.e('Error al iniciar sesión con Google: $error');
}
}
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: _isSignedIn ? null : _signInWithGoogle,
child: Text(_isSignedIn ? 'Ya iniciaste sesión' : 'Iniciar sesión con Google'),
),
);
}
}