Firebase Google登录“未处理的异常:PlatformException sign_in_failed ...”

时间:2019-05-11 23:02:45

标签: android firebase flutter firebase-cloud-messaging google-signin

我知道网络上有很多信息,并且我已经阅读了我在网络上找到的所有帖子和文章,但仍然无法弄清,并且有关错误的Google文档非常糟糕。许多人对此表示抱怨,但我看不到任何明显的修复方法,并且大多数人都在使用调试和开发模式来避免此设置。

我创建了一个Flutter应用,该应用需要进行Google登录,当然,它不起作用。

1)我创建了firebase项目,激活了android app项目,将SHA1版本和.json放在了该项目上。

2)我已经按照flutter的文档发布了该应用程序(key.properties,更改了signingConfigs和类似内容。该应用程序不在Play商店中,我正在用手机进行测试。

2.1)keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

3)Flutter依赖性:

firebase_auth: 0.7.0
  google_sign_in: 3.2.4
  cloud_firestore: 0.8.2+3
  fluttertoast: ^2.0.7
  image_picker: 0.4.12+1
  shared_preferences: 0.4.3
  firebase_storage: 1.0.4
  cached_network_image: ^0.7.0
  intl: ^0.15.7
  firebase_core: ^0.2.5

4)我使用的是新的GoogleAuthProvider.getCredential,而不是旧的SignInWithGoogle

final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );

4.1)Built build\app\outputs\apk\debug\app-debug.apk.

5)当我按登录时,出现此错误:

E/flutter (23045): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
E/flutter (23045): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (23045): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter (23045): <asynchronous suspension>
E/flutter (23045): #2      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:217:58)
E/flutter (23045): <asynchronous suspension>
E/flutter (23045): #3      GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:256:20)
E/flutter (23045): #4      GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:324:48)
E/flutter (23045): #5      _LoginScreenState._handleSignIn (package:flikmechat/login_signup.dart:69:57)
E/flutter (23045): <asynchronous suspension>
E/flutter (23045): #6      _LoginScreenState._loginPage.<anonymous closure> (package:flikmechat/login_signup.dart:566:52)
E/flutter (23045): <asynchronous suspension>
E/flutter (23045): #7      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14)
E/flutter (23045): #8      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:566:30)
E/flutter (23045): #9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
E/flutter (23045): #10     TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
E/flutter (23045): #11     TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:211:7)
E/flutter (23045): #12     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (23045): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:225:20)
E/flutter (23045): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)
E/flutter (23045): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (23045): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (23045): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (23045): #18     _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (23045): #19     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (23045): #20     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (23045): #21     _invoke1 (dart:ui/hooks.dart:233:10)
E/flutter (23045): #22     _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5)

请告知,我真的不知道该怎么办。非常感谢。

2 个答案:

答案 0 :(得分:0)

我通过在Firebase上添加Sha1调试键来解决。

我认为放置Sha1版本就足够了,但这并不是因为我们在移动设备上进行测试时使用了apk调试。

希望这对某人有所帮助。

答案 1 :(得分:0)

正如我在对此问题的回答中所解释的那样,很多都可能出错:Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

确保在您的Firebase项目设置中设置Public Setting Support Email