颤振:平台异常(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,空)
Posted
技术标签:
【中文标题】颤振:平台异常(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,空)【英文标题】:Flutter: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null) 【发布时间】:2020-01-22 09:58:45 【问题描述】:我有一个 Flutter 应用程序,我正在尝试允许用户登录他们的 Gmail,因为我希望能够列出他们的电子邮件。当我按下我的LoginButton
时,系统会提示我登录 Gmail,然后我输入我的凭据,但随后它会返回带有LoginButton
的屏幕,我遇到了错误:
Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
我尝试过的:
将google-services.json
添加到/android/app 并将GoogleService-Info.plist
添加到ios/Runner。
为 Firebase 身份验证启用 gmail。
将我的调试 SHA1 和 SHA256 添加到我的 Firebase 身份验证中。
填写 OAuth 同意书(我是在其他所有事情之后才这样做的。我不知道这是否会影响它。)
有什么想法吗?谢谢!
这是我的代码:
class AuthService
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
final Firestore _db = Firestore.instance;
Observable<FirebaseUser> user;
Observable<Map<String, dynamic>> profile;
PublishSubject loading = PublishSubject();
AuthService()
user = Observable(_auth.onAuthStateChanged);
profile = user.switchMap((FirebaseUser u)
if (u != null)
return _db
.collection('users')
.document(u.uid)
.snapshots()
.map((snap) => snap.data);
else
return Observable.just();
);
Future<FirebaseUser> googleSignIn() async
loading.add(true);
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
updateUserData(user);
print("signed in " + user.displayName);
loading.add(false);
return user;
void updateUserData(FirebaseUser user) async
DocumentReference ref = _db.collection('user').document('user.uid');
return ref.setData(
'uid': user.uid,
'email': user.email,
'photoURL': user.photoUrl,
'displayName': user.displayName,
'lastSeen': DateTime.now()
, merge: true);
void signOut()
_auth.signOut();
final AuthService authService = AuthService();
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
I/FA ( 4974): Tag Manager is not found and thus will not be used
W/d.memail.memai( 4974): Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (light greylist, reflection)
W/d.memail.memai( 4974): Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (light greylist, reflection)
W/d.memail.memai( 4974): Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (light greylist, reflection)
W/d.memail.memai( 4974): Accessing hidden method Landroid/util/LongArray;->get(I)J (light greylist, reflection)
Syncing files to device Android SDK built for x86...
I/OpenGLRenderer( 4974): Initialized EGL, version 1.4
D/OpenGLRenderer( 4974): Swap behavior 1
D/ ( 4974): HostConnection::get() New Host Connection established 0xd831cb40, tid 5016
D/EGL_emulation( 4974): eglCreateContext: 0xec485d80: maj 2 min 0 rcv 2
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/ ( 4974): HostConnection::get() New Host Connection established 0xd3f22780, tid 5005
D/EGL_emulation( 4974): eglCreateContext: 0xec485a80: maj 2 min 0 rcv 2
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485a80: ver 2 0 (tinfo 0xec483c50)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
I/d.memail.memai( 4974): Background concurrent copying GC freed 35614(5MB) AllocSpace objects, 27(1068KB) LOS objects, 50% free, 1856KB/3MB, paused 498us total 214.123ms
I/OpenGLRenderer( 4974): Davey! duration=719ms; Flags=1, IntendedVsync=65710145267, Vsync=66060145253, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=66062704600, AnimationStart=66062759800, PerformTraversalsStart=66062789600, DrawStart=66070699600, SyncQueued=66071765200, SyncStart=66073102800, IssueDrawCommandsStart=66074268300, SwapBuffers=66323835100, FrameCompleted=66431085200, DequeueBufferDuration=26966000, QueueBufferDuration=372000,
E/EnhancedIntentService( 4974): binding to the service failed
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485a80: ver 2 0 (tinfo 0xec483c50)
W/ActivityThread( 4974): handleWindowVisibility: no activity for token android.os.BinderProxy@b021561
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglCreateContext: 0xec485b40: maj 2 min 0 rcv 2
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485b40: ver 2 0 (tinfo 0xec483c50)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485b40: ver 2 0 (tinfo 0xec483c50)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
D/EGL_emulation( 4974): eglMakeCurrent: 0xec485d80: ver 2 0 (tinfo 0xec483d80)
E/flutter ( 4974): [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 ( 4974): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter ( 4974): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:344:48)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #3 GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:218:23)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #4 GoogleSignIn._addMethodCall (package:google_sign_in/google_sign_in.dart:257:20)
E/flutter ( 4974): #5 GoogleSignIn.signIn (package:google_sign_in/google_sign_in.dart:324:48)
E/flutter ( 4974): #6 AuthService.googleSignIn (package:memail/auth.dart:33:58)
E/flutter ( 4974): <asynchronous suspension>
E/flutter ( 4974): #7 LoginButton.build.<anonymous closure>.<anonymous closure> (package:memail/main.dart:86:46)
E/flutter ( 4974): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter ( 4974): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32)
E/flutter ( 4974): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 4974): #11 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter ( 4974): #12 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter ( 4974): #13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter ( 4974): #14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter ( 4974): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter ( 4974): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 4974): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 4974): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 4974): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 4974): #20 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 4974): #21 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 4974): #22 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 4974): #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 4974): #24 _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter ( 4974): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
E/flutter ( 4974):
【问题讨论】:
您能否在问题中指定您是否已下载google-services.json
并在./android/app/google-services.json 添加到您的android 项目中?
是的,我已将google-services.json
添加到/android/app 并将GoogleService-Info.plist
添加到ios/Runner。
我也遇到了这个问题。过去一年我们一直在顺利使用 Google 登录,所以我知道配置很好。它在 GoogleSignIn.signIn() 中失败。我也可以在身份验证部分下的 firebase 中看到该帐户。
我也面临同样的问题。我也使用谷歌登录一年多了。你找到解决办法了吗?请帮忙
【参考方案1】:
我也遇到过这个问题。就我而言,我尝试在我的一个已经处于生产级别的应用中实现GoogleSignIn
。
当我尝试这样做时..我也遇到了同样的错误..APIException: 10
.. 看起来你的也是同样的情况..
我尝试了很多次..但最后我妥协了,决定不在我的应用中包含GoogleSignIn
..
但是,再次..我解决了它..通过将 2 个 SHA1
键添加到 FireBase Project
..一个用于 debug mode
和另一个用于 release mode
..
如果我只放了调试SHA1
键..它不能在release
模式下工作,但在debug
模式下工作正常,如果我只放release
SHA1 键..它不能在@987654332 下工作@ 模式,但在 release
模式下工作正常。
不知道为什么会发生..但它正在发生..不知何故它工作正常..
好的..现在..什么是debug
和release
键.. 它们不一样..我如何获得它们..?
在这里..
在Command Prompt
.. 中转到您的项目,然后在cd android
中输入..
gradlew signingReport
它将提供SHA1
键..
debug keystore
生成一个密钥,release keystore
生成另一个密钥..
将它们都添加到项目中......它可以工作(希望)......就像它对我所做的那样......
希望对你有帮助..
注意:我正在使用Windows
..不确定在Mac
上生成密钥的过程是否相同..
【讨论】:
这实际上对我今天有用!添加两个 SHA1 密钥就可以了!【参考方案2】:只需连接 SHA 即可解决问题 https://developers.google.com/android/guides/client-auth
并替换分析依赖项:
implementation 'com.google.firebase:firebase-core:16.0.6'
【讨论】:
所以这个答案不依赖于链接的可用性,你介意编辑你的答案来总结如何连接 SHA 吗?以上是关于颤振:平台异常(sign_in_failed,com.google.android.gms.common.api.ApiException:10:,空)的主要内容,如果未能解决你的问题,请参考以下文章
当我运行颤振应用程序显示警告:映射新的 ns http://schemas.android.co
由于 12500(SIGN_IN_FAILED) 错误代码,使用 Google 登录 Firebase UI 失败
Firebase 身份验证:PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: