You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用获取Google Sign-In访问令牌时触发PlatformException问题

关于Flutter中Google Sign-In触发PlatformException的问题

尝试在Flutter应用中使用Google Sign-In登录时触发了PlatformException,错误日志如下:

W/Auth    (10169): [GoogleAuthUtil] [GoogleAuthUtil] error status:UNKNOWN with method:getTokenWithDetails
...
I/flutter (10169): error: PlatformException(exception, ERROR, null, null)
E/flutter (10169): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(exception, ERROR, null, null)
E/flutter (10169): #0 GoogleSignInApi.getAccessToken (package:google_sign_in_android/src/messages.g.dart:250:7)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #1 GoogleSignInAndroid.getTokens.<anonymous closure> (package:google_sign_in_android/google_sign_in_android.dart:68:15)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #2 GoogleSignInAccount.authentication (package:google_sign_in/google_sign_in.dart:95:9)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #3 GoogleLoginProvider.getAuthCredential (package:firebase_manager/src/auth/login/providers/google_login_provider.dart:15:11)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #4 LoginTool.loginByGoogle (package:firebase_manager/src/auth/login/login_tool.dart:36:37)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169): #5 StatePage.build.<anonymous closure> (package:saiwai/ui/loginpage/login_page.dart:80:42)
E/flutter (10169): <asynchronous suspension>
E/flutter (10169):

已尝试以下解决步骤:

  • 更新所有依赖至最新版本
  • 检查并更新Firebase控制台中的SHA-1指纹
  • 验证Firebase配置文件(google-services.json)
  • 执行flutter clean操作

尽管做了这些尝试,错误仍未解决。当前使用Flutter最新稳定版本,测试设备为Android设备。

报错位置的代码片段:

Future<OAuthCredential?> getAuthCredential() async {
  // Trigger the authentication flow
  final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
  if (googleUser != null) {
    // Obtain the auth details from the request
    final GoogleSignInAuthentication googleAuth =
        await googleUser.authentication;
    // Create a new credential
    return GoogleAuthProvider.credential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );
  }
  return null;
}

恳请各位帮忙分析问题原因,或提供进一步诊断与解决的方案,非常感谢!

内容的提问来源于stack exchange,提问作者normidar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 05:42:40