Flutter Firebase 인증 오류 .createUserWithEmailAndPassword : getGoogleApiForMethod ()에서 Gms를 반환했습니다. com.google.firebase.auth.api.internal.zzao@fb1556c
전문
지금 아무것도 작동하는 것 같군하면서 좋은위한 투쟁이었다, 나는 비슷한 질문에 대한 답변을 보았다 여기 와 여기에 있지만, 전자는 떨림 아니 었 후자가 이전에 게시 한 최근 변경 to firebase_auth
내가 가장 중요하게 생각 제안 된 솔루션이 작동하지 않았습니다.
문제
이 문제는 flutter 내에서 매우 간단한 firebase 인증 초기 설정과 관련이 있습니다. 나는 그것을 알 수 있듯이 정확히 내 중포 기지 프로젝트를 설정 한 여기 및 사용 이 와 이 설정 firebase_auth
.
문제를 일으키는 코드는 다음과 같습니다.
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);
}
}
코드가 실행될 때 오류
I / BiChannelGoogleApi (19546) : [FirebaseAuth :] getGoogleApiForMethod ()에서 Gms를 반환했습니다. com.google.firebase.auth.api.internal.zzao@fb1556c
반환됩니다.
이 대답 은 오류가 관련이 없을 수 있음을 암시하는 것 같습니다. 즉, 코드가 어쨌든 작동 할 수 있습니다. 나는 줄에 중단 점을 넣어 UserCredential userCredential = await FirebaseAuth.instance
및 강화를 통해, 그것은 계속 .createUserWithEmailAndPassword(
, 다시 한번 첫 번째 줄에 다시 가서 오류가 표시됩니다를 통해 강화. 더 이상 단계를 수행하면 함수가 완전히 빠져 나가므로 print(userCredential.user.email);
행이 실행되지 않으므로 코드가 작동하지 않는다는 것을 의미합니다. 또한의 print(e);
행 catch
이이 오류를 출력하는 것이 아닙니다.
기타 정보
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,
),
],
),
),
);
}
}
또한이 오류는 몇 번 나타 났지만 이 대답 은 내 문제와 관련이 없으며 문제를 나타내는 것이 아니라는 것을 의미하는 것 같습니다.
W / ConnectionTracker (19240) : java.lang.IllegalArgumentException : 서비스 등록 안 됨 : lp @ fb1556c W / ConnectionTracker (19240) : at 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) : lq.D (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0) : 10) W / ConnectionTracker (19240) : at lc.a (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0) : 2) W / ConnectionTracker (19240) : at ee.run (: com.google.android.gms .dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0) : 3) W / ConnectionTracker (19240) : at java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:462) W / ConnectionTracker (19240) : at java.util.concurrent.FutureTask.run (FutureTask.java : 266) W / ConnectionTracker (19240) : ix.run (: com.google.android.gms.dynamite_measurementdynamite @ 204217100 @ 20.42.17 (150700-0) : 6)
편집하다
줄 onPressed: () => _registerTestUser(),
을 main.dart
로 변경하면 onPressed: () {_registerTestUser();}
동일한 결과가 나오지만 오류가 약간 변경되고 zzao @ fb1556c는 zzao @ ebc85e9가됩니다.
답변
질문에 직접 답하지 않고 FlutterFire 샘플 코드와 크게 다르지는 않지만 분명히 상충됩니다. 다음은 사용자 (Firebase_auth 유형 사용자)를 만드는 데 사용하는 코드이며 오류가 표시되지 않습니다.
User _user = (await _firebaseAuth.createUserWithEmailAndPassword(
email: email,
password: password,
)).user;
그런 다음과 같은 메서드를 사용 await _user.sendEmailVerification();
하고 _user.email
문제없이 해당 속성에 액세스 할 수 있습니다 .
자격 증명 대신 시도해보십시오.
추신. 문제 : W/ConnectionTracker(19240): java.lang.IllegalArgumentException: Service not registered:
당신이 언급 한 것은 여기에서 추적되고 있으며 귀하의 코드와 관련이 있다고 생각하지 않습니다.https://github.com/firebase/firebase-android-sdk/issues/1662#issue-638324848
예외 코드의 여러 변형이 있지만 모두 관련이 있습니다.
업데이트 나는 또한 그 @amit 쿠마 거의 정확한, 실행중인 것으로 판단FirebaseAuth auth = FirebaseAuth.instance;
하기 전에Firebase.initializeApp();
. FirebaseAuth를 인스턴스화하기 전에 미래가 완료되었는지 확인해야합니다. 아마도 위의 변경된 코드를 무의미하게 만듭니다.
먼저 당신이 초기화되지 않은 볼 수의 firebase
에 main.dart
올바르게 파일.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
하나의 진술을 놓쳤습니다. 다시 시도하고 여전히 문제가 발생하면 알려주세요.
이것을 시도하십시오 :
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);
}
}
UserCredential 대신 User를 사용하는 것도 고려하십시오.
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);
}
}
final FirebaseAuth _auth = FirebaseAuth.instance;
registerUser()async{
_auth.createUserWithEmailAndPassword(
email:"[email protected]",
password: "SuperSecretPassword!",
).then((result){
User user = result.user;
}).catchError((e) {
print(e);
});
}