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

Flutter Android版Firebase电话认证仅Release模式异常求助

仅在Release模式下Firebase电话认证页面无法跳转问题

用户能收到OTP验证码,但页面无法跳转,使用Firebase电话认证时出现以下未处理异常:

E/flutter ( 9235): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception:        [firebase_auth/unknown] null
E/flutter ( 9235): #0      AuthProvider.signInWithPhone.<anonymous closure> (package:my_cube/services/auth.dart:62)
E/flutter ( 9235): #1      MethodChannelFirebaseAuth.verifyPhoneNumber.<anonymous closure> (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:663)
E/flutter ( 9235): #2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594)
E/flutter ( 9235): #3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
E/flutter ( 9235): #4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271)
E/flutter ( 9235): #5      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123)
E/flutter ( 9235): #6      _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253)
E/flutter ( 9235): #7      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153)
E/flutter ( 9235): #8      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594)
E/flutter ( 9235): #9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
E/flutter ( 9235): #10     _DelayedData.perform (dart:async/stream_impl.dart:515)
E/flutter ( 9235): #11     _PendingEvents.handleNext (dart:async/stream_impl.dart:620)
E/flutter ( 9235): #12     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591)
E/flutter ( 9235): #13     _microtaskLoop (dart:async/schedule_microtask.dart:40)
E/flutter ( 9235): #14     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)

Logcat还会先抛出以下错误:

[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Instantiation of JsonResponse failed! class com.google.android.gms.internal.firebase-auth-api.o2

实际流程

输入手机号并点击按钮后,跳转至reCAPTCHA验证网页,验证完成返回应用后触发上述错误,但能正常收到OTP验证码。

相关代码

传递手机号的函数:

void sendPhoneNumber() {
    final AuthProvider authService = Provider.of<AuthProvider>(
        context, listen: false);
    String phoneNumber = phoneController.text.trim();
    FirebaseAuth.instance.setSettings(appVerificationDisabledForTesting: false);

    authService.signInWithPhone(context, "+${country.phoneCode}$phoneNumber");
  }

signInWithPhone函数:

signInWithPhone(BuildContext context, String phoneNumber,) async {
    ToastContext().init(context);
    try {
      await _auth.verifyPhoneNumber(
          phoneNumber: phoneNumber,

          verificationCompleted:
              (PhoneAuthCredential phoneAuthCredential) async {
                await _auth.signInWithCredential(phoneAuthCredential);
                Toast.show("Verification Completed", duration: Toast.lengthShort, gravity:  Toast.bottom);
      },
          verificationFailed: (FirebaseAuthException error) {
            Toast.show('$error', duration: Toast.lengthShort, gravity:  Toast.bottom);
            throw FirebaseAuthException(code: error.code, message: error.message);
          },
          codeSent: (verificationId, forceResendingToken) {
            Toast.show("Code Sent", duration: Toast.lengthShort, gravity:  Toast.bottom);
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => Otp(verificationId: verificationId),
              ),
            );
          },
          codeAutoRetrievalTimeout: (verificationId) {});
    } on FirebaseAuthException catch (e) {
      showSnackBar(context, e.message.toString());
      Toast.show('$e', duration: Toast.lengthLong, gravity:  Toast.bottom);
      print(e.message);
    }
  }

已尝试的操作

  • 验证Firebase控制台与项目中的SHA-1哈希值一致
  • 启用Play Integrity API(但未在应用中添加相关代码,不知道如何为未上架Play商店的应用配置)
  • 添加最新的google-services.json文件

请求帮助

用户能收到OTP,但因页面无法跳转无法输入验证码。如果问题源于缺失PlayIntegrity令牌,请提供Flutter应用的解决方法(面向初学者)。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 18:13:25