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

Flutter中Firebase Auth短信验证码在移动设备无法接收,但Web端正常的问题排查求助

Flutter中Firebase Auth短信验证码在移动设备无法接收,但Web端正常的问题排查求助

大家好,我最近在用Firebase Auth做用户手机号验证功能时遇到了一个奇怪的问题:

  • 移动设备(包括模拟器和我的物理真机)完全收不到OTP验证码
  • 但用命令 flutter run -d chrome 在Chrome浏览器上运行应用时,输入同一个手机号却能正常收到验证码
  • 另外,使用Firebase官方提供的测试手机号时,整个OTP验证流程是能成功完成的

我实在搞不懂为什么会出现这种差异,希望大家能帮我排查一下问题。

我的OTP验证核心代码:

void signInWithPhone(BuildContext context, String phoneNumber) async {
  try {
    await auth.verifyPhoneNumber(
      phoneNumber: phoneNumber,
      verificationCompleted: (PhoneAuthCredential credential) async {
        print('Before-signing in with credential');
        await auth.signInWithCredential(credential);
        debugPrint('After-signing in with credential');
      },
      verificationFailed: (e) {
        debugPrint(e.message.toString());
        debugPrint(" THIS IS ERROR ${e.message}");
        showSnackbar(context: context, content: e.message!.trim());
        throw Exception(e.message);
      },
      codeSent: ((String verificationId, int? resendToken) async {
        debugPrint('Code sent');
        Navigator.pushNamed(context, OTPScreen.routeName,
            arguments: verificationId);
      }),
      codeAutoRetrievalTimeout: (String verificationId) {
        debugPrint('Auto retrieval timeout');
      });
  } on FirebaseAuthException catch (e) {
    debugPrint(e.message!);
    debugPrint(e.toString());
    showSnackbar(context: context, content: e.message!);
  }
}

调用上述函数的代码:

void sendPhoneNumber() {
  try {
    debugPrint('VerificationCompleted');
    String phoneNumber = phoneController.text.trim();
    if (country != null && phoneNumber.isNotEmpty) {
      ref
          .read(authControllerProvider)
          .signInWithPhone('+${country!.phoneCode}$phoneNumber', context);
    }
  } catch (e) {
    showSnackbar(context: context, content: 'Fill the phone number field');
  }
}

控制台输出的错误信息:

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     ( 4546): Ask the user to update Play Store.
E/zzb     ( 4546):  (https://developer.android.com/google/play/integrity/reference/com/google/android/play/core/integrity/model/IntegrityErrorCode.html#CANNOT_BIND_TO_SERVICE).
D/EGL_emulation( 4546): app_time_stats: avg=632.60ms min=33.58ms max=1231.62ms count=2
W/System  ( 4546): Ignoring header X-Firebase-Locale because its value was null.
W/LocalRequestInterceptor( 4546): Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: No AppCheckProvider installed.
E/OpenGLRenderer( 4546): Unable to match the desired swap behavior.
E/FirebaseAuth( 4546): [GetAuthDomainTask] Error getting project config. Failed with INVALID_CERT_HASH 400
E/zzb     ( 4546): 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/WindowOnBackDispatcher( 4546): sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda17@cbdc15b
D/EGL_emulation( 4546): app_time_stats: avg=1098.10ms min=1098.10ms max=1098.10ms count=1
W/System  ( 4546): Ignoring header X-Firebase-Locale because its value was null.
W/LocalRequestInterceptor( 4546): Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: No AppCheckProvider installed.
E/FirebaseAuth( 4546): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17093 null
D/FirebaseAuth( 4546): Invoking original failure callbacks after phone verification failure for +917387251914, 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.
D/CompatibilityChangeReporter( 4546): Compat change id reported: 247079863; UID 10192; state: DISABLED
I/flutter ( 4546): 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.
I/flutter ( 4546):  THIS IS 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.

我已经尝试过的解决步骤:

  • 配置了正确的SHA密钥并添加到了Firebase控制台
  • 升级了所有依赖包到最新版本
  • 查阅了Stack Overflow和Google上几乎所有相关的问题和解答,但都没解决我的问题

备注:内容来源于stack exchange,提问作者KAPIL BADOKAR

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.20 06:13:10