Flutter集成Firebase手机OTP验证遇reCAPTCHA令牌获取失败问题
Flutter Firebase手机OTP验证错误排查方案
核心错误指向证书哈希无效和Play Integrity服务绑定失败,导致reCAPTCHA验证不通过,最终OTP请求被拒绝。以下是针对性解决步骤:
错误日志
ForceRecaptchaFlow from phoneAuthOptions = false, ForceRecaptchaFlow from firebaseSettings = false W/System ( 4367): Ignoring header X-Firebase-Locale because its value was null. D/TrafficStats( 4367): tagSocket(73) with statsTag=0xffffffff, statsUid=-1 I/PlayCore( 4367): UID: [10162] PID: [4367] IntegrityService : requestIntegrityToken(IntegrityTokenRequest{nonce=DZbwPB95mzwtBbgqcpPKnQqBoNSKj0zFgVVgh1fvBG0, cloudProjectNumber=551503664846}) I/PlayCore( 4367): UID: [10162] PID: [4367] IntegrityService : Initiate binding to the service. I/PlayCore( 4367): UID: [10162] PID: [4367] IntegrityService : Failed to bind to the service. E/zzb ( 4367): Play Integrity Token fetch failed, falling back to Recaptcha-9: Integrity API error (-9): Binding to the service in the Play Store has failed. This can be due to having an old Play Store version installed on the device. E/zzb ( 4367): Ask the user to update Play Store. E/zzb ( 4367): (https://developer.android.com/google/play/integrity/reference/com/google/android/play/core/integrity/model/IntegrityErrorCode.html#CANNOT_BIND_TO_SERVICE). D/EGL_emulation( 4367): app_time_stats: avg=41.80ms min=3.95ms max=507.57ms count=23 W/System ( 4367): Ignoring header X-Firebase-Locale because its value was null. W/Parcel ( 4367): Expecting binder but got null! E/FirebaseAuth( 4367): [GetAuthDomainTask] Error getting project config. Failed with INVALID_CERT_HASH 400 E/zzb ( 4367): Failed to get reCAPTCHA token with error [There was an error while trying to get your package certificate hash.]- calling backend without app verification W/System ( 4367): Ignoring header X-Firebase-Locale because its value was null. E/FirebaseAuth( 4367): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17093 null D/FirebaseAuth( 4367): Invoking original failure callbacks after phone verification failure for +917977501362, error - This request is missing a valid app identifier, meaning that Play Integrity checks, and reCAPTCHA checks were unsuccessful. Please try again, or check the logcat for more details.
解决步骤
确认证书哈希准确性
- 分别获取debug和release环境的SHA-1、SHA-256哈希值:
- Debug环境:
keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore(默认密码android) - Release环境:
keytool -list -v -keystore 你的发布密钥文件路径
- Debug环境:
- 将所有哈希值添加到Firebase控制台的项目设置中
- 重新下载
google-services.json文件,替换项目android/app目录下的旧文件
- 分别获取debug和release环境的SHA-1、SHA-256哈希值:
修复Play Integrity绑定问题
- 确保测试设备的Google Play Store已更新至最新版本,更新后重启设备
- 若使用模拟器,选择带有Google Play服务的系统镜像(如Google APIs或Google Play版)
- 确认设备已登录有效的Google账号
重置项目构建配置
- 清理项目缓存并重新构建:
flutter clean flutter pub get cd android && ./gradlew clean && cd .. flutter run - 再次确认Firebase控制台中电话登录功能已启用
- 清理项目缓存并重新构建:
检查基础配置
- 确保
pubspec.yaml中firebase_auth依赖版本与当前Flutter版本兼容 - 检查
android/app/src/main/AndroidManifest.xml是否添加了网络权限:<uses-permission android:name="android.permission.INTERNET"/>
- 确保
内容的提问来源于stack exchange,提问作者Pratham Dave
相关产品推荐
相关产品推荐

