Flutter google_sign_in插件登录报错PlatformException,如何解决?
解决Google Sign-In PlatformException(sign_in_failed, com.google.android.gms.common.api.b: 10)错误
以下是针对性的解决步骤:
验证签名密钥配置
确保Firebase控制台项目设置中,同时上传了SHA-1和SHA-256密钥,两者缺一不可。
获取debug环境密钥可执行以下命令:keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android若为release环境,替换为对应的签名文件路径及密码。
更新google-services.json文件
修改Firebase密钥或认证设置后,必须重新下载最新的google-services.json文件,替换到Android项目的app目录下,禁止手动修改文件内容。检查依赖版本兼容性
确保google_sign_in与firebase_auth插件版本兼容,可参考pub.dev的版本说明。同时确认Android端配置:- 项目级
build.gradle中,google-services插件版本不低于4.4.0:classpath 'com.google.gms:google-services:4.4.1' - App级
build.gradle中,添加Play服务依赖:implementation 'com.google.android.gms:play-services-auth:20.7.0'
- 项目级
确认OAuth 2.0客户端ID配置
登录Google Cloud Console,进入对应项目的「API和服务→凭据」页面,检查是否存在匹配当前应用包名与SHA密钥的Android类型OAuth客户端ID。若缺失,手动创建并配置正确参数。代码优化(可选但有效)
初始化GoogleSignIn时指定必要参数,避免潜在的配置缺失问题:final GoogleSignIn _googleSignIn = GoogleSignIn( scopes: ['email', 'profile'], clientId: '从google-services.json中提取的Android客户端ID', );同时增加用户取消登录的判断:
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn(); if (googleUser == null) { log('用户取消登录操作'); return null; }重置应用环境
卸载设备上的测试应用,清除Android Studio缓存(File → Invalidate Caches/Restart),重新编译运行项目。
内容的提问来源于stack exchange,提问作者Kartik Gosai
相关产品推荐
相关产品推荐

