Flutter Firebase Kimlik Doğrulama Hatası .createUserWithEmailAndPassword: getGoogleApiForMethod () Gms'i döndürdü: com.google.firebase.auth.api.internal.zzao@fb1556c

Jan 04 2021

Önsöz

Şimdi ve hiçbir şey çalışıyor görünüyor bunun gayet iyi bir mücadele olmuştur, ben benzer soruların cevapları gördük burada ve burada ama eski fluttera değildi ve ikincisi önce gönderilmiş son değişiklikler için firebase_authve en önemlisi sanırım önerilen çözümler işe yaramadı.

Sorun

Sorun, flutter içinde çok basit bir ilk firebase kimlik doğrulaması kurulumuyla ilgilidir. Firebase projemi tam olarak burada önerildiği gibi kurdum ve bunu ve bunu kurmak için kullandım firebase_auth.

Soruna neden olan kod aşağıdaki gibidir:

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);
  }
}

Kod çalıştırıldığında hata

I / BiChannelGoogleApi (19546): [FirebaseAuth:] getGoogleApiForMethod () Gms'i döndürdü: com.google.firebase.auth.api.internal.zzao@fb1556c

Iade edildi.

Bu yanıt , hatanın alakasız olabileceğini, yani kodun yine de çalışabileceğini düşündürüyor gibi görünüyor. Satıra bir kesme noktası koydum UserCredential userCredential = await FirebaseAuth.instanceve üstünden geçtim , devam ediyor .createUserWithEmailAndPassword(, sonra tekrar ilk satıra geri dönüyor ve hata görüntüleniyor. İşlevin herhangi bir başka kırılmasının üzerinden geçilmesi, print(userCredential.user.email);satırın hiçbir zaman çalıştırılmamasıdır, bu da kodun çalışmadığını gösterir. Ek olarak, içindeki print(e);satır catchbu hatayı veren şey değildir.

Diğer bilgiler

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,
            ),
          ],
        ),
      ),
    );
  }
}

Ayrıca bu hata birkaç kez ortaya çıktı, ancak bu yanıt sorunumla hiçbir ilgisi olmadığını ve bir sorunun göstergesi olmadığını gösteriyor gibi görünüyor.

W / ConnectionTracker (19240): java.lang.IllegalArgumentException: Hizmet kayıtlı değil: lp @ fb1556c W / ConnectionTracker (19240): android.app.LoadedApk.forgetServiceDispatcher (LoadedApk.java:1729) W / ConnectionTracker (19240): adresinde android.app.ContextImpl.unbindService (ContextImpl.java:1874) W / ConnectionTracker (19240): 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): ci.d'de (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 2) W / ConnectionTracker (19240): lq.D'de (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 10) W / ConnectionTracker (19240) : lc.a'da (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 2) W / ConnectionTracker (19240): ee.run'da (: com.google.android.gms .dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 3) W / ConnectionTracker (19240): java.util.concurrent.Executors adresinde $ RunnableAdapter.call (Executors.java:462) W / ConnectionTracker (19240): java.util.concurrent.FutureTask.run (FutureTask.java: 266) W / ConnectionTracker (19240): ix.run adresinde (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0): 6)

DÜZENLE

Çizgi değiştirme onPressed: () => _registerTestUser(),bölgesindeki main.dartiçin onPressed: () {_registerTestUser();}aynı sonucu verir ama fb1556c @ zzao zzao @ ebc85e9 olur, hafif hata değiştirir.

Yanıtlar

GrahamD Jan 08 2021 at 19:24

FlutterFire örnek koduyla sorunuzu doğrudan yanıtlamamak ve görünüşe göre (çok farklı olmasa da) anlaşmazlık içinde olmak. Kullanıcı oluşturmak için kullandığım kod (Firebase_auth Type User) ve hatanızı görmüyorum:

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

Daha sonra gibi yöntemleri kullanabilir await _user.sendEmailVerification();ve _user.emailsorun olmadan özelliklerine erişebilirim .

Belki kimlik bilgisi yerine bunu deneyebilirsin.

PS. Sorun: W/ConnectionTracker(19240): java.lang.IllegalArgumentException: Service not registered:bahsettiğiniz burada izleniyor ve bunun kodunuzla ilgili olduğuna inanmıyorum:https://github.com/firebase/firebase-android-sdk/issues/1662#issue-638324848

Birkaç istisna kodu varyasyonu vardır, ancak hepsi birbiriyle ilişkilidir.

Güncelleme Ayrıca @amit kumar'ın neredeyse doğru olduğuna inanıyorum, dahaFirebaseAuth auth = FirebaseAuth.instance;öncekoşuyorsunuzFirebase.initializeApp();. FirebaseAuth'u başlatmadan önce geleceğin tamamlandığından emin olmalısın, inanıyorum. Muhtemelen değiştirilen kodumu yukarıda alakasız hale getiriyor.

AmitKumar Jan 05 2021 at 00:17

Önce sen başlatıldı değil gördüğünüz gibi bir firebasede main.dartdoğru dosyaya.

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

Bir ifadeyi kaçırdınız ve tekrar deneyin ve hala sorun yaşıyorsanız bana bildirin

JamM.HernandezQuiceno Jan 12 2021 at 01:41

Bunu bir deneyin:

  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);
    }
  }

Ayrıca UserCredential yerine User kullanmayı düşünün:

  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);
        });
    }