Błąd uwierzytelniania Flutter Firebase .createUserWithEmailAndPassword: getGoogleApiForMethod () zwrócił Gms: com.google.firebase.auth.api.internal.zzao@fb1556c

Jan 04 2021

Preambuła

To była walka o dobro natomiast teraz i nic nie wydaje się działać, widziałem odpowiedzi na podobne pytania tutaj i tutaj, ale były nie był w trzepotanie i ten ostatni został opublikowany przed ostatnimi zmianami do firebase_authi myślę, co najważniejsze proponowane rozwiązania nie zadziałały.

Problem

Problem dotyczy bardzo, bardzo prostej początkowej konfiguracji uwierzytelniania Firebase w flutter. Skonfigurowałem mój projekt Firebase dokładnie tak, jak sugeruje tutaj i użyłem tego i tego do skonfigurowania firebase_auth.

Kod powodujący problem jest następujący:

void _registerTestUser() async {
  try {
    UserCredential userCredential = await FirebaseAuth.instance
        .createUserWithEmailAndPassword(
            email: "[email protected]",
            password: "SuperSecretPassword!");
    print(userCredential.user.email);
  } on FirebaseAuthException catch (e) {
    if (e.code == 'weak-password') {
      print('The password provided is too weak.');
    } else if (e.code == 'email-already-in-use') {
      print('The account already exists for that email.');
    }
  } catch (e) {
    print(e);
  }
}

Po uruchomieniu kodu błąd

I / BiChannelGoogleApi (19546): [FirebaseAuth:] getGoogleApiForMethod () zwrócił Gms: com.google.firebase.auth.api.internal.zzao@fb1556c

Wraca.

Ta odpowiedź wydaje się sugerować, że błąd może być nieistotny, tj. Kod może i tak działać. Położyłem punkt przerwania na linii UserCredential userCredential = await FirebaseAuth.instancei przekroczyłem, kontynuuje .createUserWithEmailAndPassword(, a po ponownym przekroczeniu wraca do pierwszej linii i wyświetlany jest błąd. Przekroczenie wszelkich dalszych punktów powoduje całkowite wyłączenie funkcji, więc print(userCredential.user.email);linia nigdy nie jest wykonywana, co sugerowałoby, że kod nie działa. Ponadto print(e);wiersz w catchnie jest tym, co generuje ten błąd.

Inne informacje

Pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^0.5.3 #firebase core flutter sdk
  firebase_auth: ^0.18.4+1 #firebase authorisation

android / build.gradle

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.4'  // Google Services plugin
}

android / app / build.gradle

apply plugin: 'com.google.gms.google-services'  // Google Services plugin

main.dart

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';

FirebaseAuth auth = FirebaseAuth.instance;

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FutureBuilder(
        // Initialize FlutterFire:
        future: _initialization,
        builder: (context, snapshot) {
          // Check for errors
          if (snapshot.hasError) {
            return Error();
          }

          // Once complete, show your application
          if (snapshot.connectionState == ConnectionState.done) {
            return MyHomePage();
          }

          // Otherwise, show something whilst waiting for initialization to complete
          return Loading();
        },
      ),
    );
  }
}

class Loading extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text('Firebase is loading'),
      ),
    );
  }
}

class Error extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text('There has been an error'),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  void _registerTestUser() async {
    try {
      UserCredential userCredential = await FirebaseAuth.instance
          .createUserWithEmailAndPassword(
              email: "[email protected]",
              password: "SuperSecretPassword!");
      print(userCredential.user.email);
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('FlutterFire Test')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            RaisedButton(
              child: Text('Register a test user'),
              onPressed: () => _registerTestUser(),
              color: Colors.blue,
            ),
          ],
        ),
      ),
    );
  }
}

Również ten błąd pojawił się kilka razy, chociaż ta odpowiedź wydaje się sugerować, że nie ma to nic wspólnego z moim problemem i nie wskazuje na problem.

W / ConnectionTracker (19240): java.lang.IllegalArgumentException: Usługa niezarejestrowana: lp @ fb1556c W / ConnectionTracker (19240): w android.app.LoadedApk.forgetServiceDispatcher (LoadedApk.java:1729) W / ConnectionTracker (19240): at android.app.ContextImpl.unbindService (ContextImpl.java:1874) W / ConnectionTracker (19240): at android.content.ContextWrapper.unbindService (ContextWrapper.java:792) W / ConnectionTracker (19240): at ci.f (: com .google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 1) W / ConnectionTracker (19240): at ci.d (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 2) W / ConnectionTracker (19240): w lq.D (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 10) W / ConnectionTracker (19240) : w lc.a (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 2) W / ConnectionTracker (19240): w ee.run (: com.google.android.gms .dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 3) W / ConnectionTracker (19240): w java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:462) W / ConnectionTracker (19240): w java.util.concurrent.FutureTask.run (FutureTask.java: 266) W / ConnectionTracker (19240): w ix.run (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 6)

EDYTOWAĆ

Zmiana linii onPressed: () => _registerTestUser(),w main.dartcelu onPressed: () {_registerTestUser();}daje ten sam wynik, ale nieznacznie zmienia błąd The zzao @ fb1556c staje zzao @ ebc85e9.

Odpowiedzi

GrahamD Jan 08 2021 at 19:24

Nie odpowiadając bezpośrednio na twoje pytanie i najwyraźniej sprzeczny (choć niezbyt różny) z przykładowym kodem FlutterFire. Oto kod, którego używam do tworzenia użytkownika (Firebase_auth Type User) i nie widzę Twojego błędu:

User _user = (await _firebaseAuth.createUserWithEmailAndPassword(
              email: email,
              password: password,
            )).user;

Mogę wtedy bez problemu korzystać z metod takich jak await _user.sendEmailVerification();i uzyskiwać dostęp do jego właściwości _user.email.

Może spróbuj tego zamiast poświadczenia.

PS. Problem: W/ConnectionTracker(19240): java.lang.IllegalArgumentException: Service not registered:do którego się odnosisz, jest tutaj śledzony i nie sądzę, aby był powiązany z Twoim kodem:https://github.com/firebase/firebase-android-sdk/issues/1662#issue-638324848

Ma kilka odmian kodu wyjątku, ale wszystkie są ze sobą powiązane.

Aktualizacja Uważam również, że @amit kumar jest prawie poprawne, działałeśFirebaseAuth auth = FirebaseAuth.instance;wcześniejFirebase.initializeApp();. Uważam, że przed utworzeniem instancji FirebaseAuth musisz się upewnić, że Twoja przyszłość dobiegnie końca. Prawdopodobnie sprawia, że ​​mój zmieniony kod powyżej jest nieistotny.

AmitKumar Jan 05 2021 at 00:17

Po pierwsze, jak widzę nie masz zainicjowana firebasew main.dartpliku poprawnie.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

Przegapiłeś jedno oświadczenie, spróbuj ponownie, a jeśli nadal masz problem, daj mi znać

JamM.HernandezQuiceno Jan 12 2021 at 01:41

Spróbuj:

  void _registerTestUser() async {
    try {
      await FirebaseAuth.instance
          .createUserWithEmailAndPassword(
              email: "[email protected]",
              password: "SuperSecretPassword!")
          .then((userCredential) => print(userCredential.user.email));
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }

Rozważ także użycie User zamiast UserCredential:

  void _registerTestUser() async {
    try {
      final User user = (await FirebaseAuth.instance
              .createUserWithEmailAndPassword(
                  email: "[email protected]",
                  password: "SuperSecretPassword!"))
          .user;

      print(user.email);
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }
ChizaramSuccess Jan 12 2021 at 22:34
 final FirebaseAuth _auth = FirebaseAuth.instance;

        registerUser()async{
        _auth.createUserWithEmailAndPassword(
         email:"[email protected]",
         password: "SuperSecretPassword!",
        ).then((result){
User user = result.user;
}).catchError((e) {
          print(e);
        });
    }