Firebase手机号认证无法发送SMS,出现[SmsRetrieverHelper]超时错误
Firebase手机号认证无法接收SMS验证码问题
问题概述
两周前功能正常,昨日测试手机号登录时无法收到验证SMS验证码,更换多台设备测试无效。已升级相关依赖包(firebase_core: ^2.4.0、cloud_firestore: ^4.2.0、firebase_auth: ^4.2.1),问题未解决。
相关代码
按钮触发代码
ElevatedButton( onPressed: () { if (otpVisibility) { verifyOTP(); } else { loginWithPhone(); } }, child: Padding( padding: EdgeInsets.symmetric(vertical: 1.h, horizontal: 1.h), child: Text( otpVisibility ? "verify" : "login", style: TextStyle(fontSize: 15.sp, fontFamily: 'Cairo'), ), ), ),
报错信息
W/BpBinder( 2464): Slow Binder: BpBinder transact took 433ms, interface=com.google.android.gms.auth.api.phone.internal.ISmsRetrieverApiService, code=1 oneway=false W/FirebaseAuth( 2464): [SmsRetrieverHelper] Timed out waiting for SMS.
登录与验证方法代码
void loginWithPhone() async { auth.verifyPhoneNumber( phoneNumber:_prefix + phoneController.text, verificationCompleted: (PhoneAuthCredential credential) async { await auth.signInWithCredential(credential).then((value) { if (value.user != null) { print("Done !!"); print("You are name saved successfully"); print("You are logged in successfully"); } else { print("Failed!!"); } }).catchError((e) { Fluttertoast.showToast(msg: 'Something Went Wrong: ${e.toString()}'); }); }, verificationFailed: (FirebaseAuthException e) { print(e.message); }, codeSent: (String verificationId, int resendToken) { otpVisibility = true; verificationID = verificationId; setState(() {}); }, codeAutoRetrievalTimeout: (String verificationId) {}, timeout: const Duration(seconds: 20), ); } void verifyOTP() async { PhoneAuthCredential credential = PhoneAuthProvider.credential( verificationId: verificationID, smsCode: otpController.text); await auth.signInWithCredential(credential).then((value) { print("You are logged in successfully"); uploadUserInfoToFirebase(); _nameSaver(); Fluttertoast.showToast( msg: "You are logged in successfully", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: KInActiveColor, textColor: Colors.white, fontSize: 12.sp); Navigator.push( context, MaterialPageRoute(builder: (context) => HomePage())); }); } }
排查与解决步骤
Firebase控制台配置检查
- 确认手机号认证功能未被关闭,进入控制台→Authentication→登录方法查看状态。
- 检查SMS发送配额:控制台→项目设置→使用量与配额,确认未超出免费额度或付费配额。
- 验证应用签名:Android端确保
google-services.json中的SHA-1/SHA-256指纹与打包签名一致;iOS端检查GoogleService-Info.plist配置完整。
设备与网络排查
- 关闭设备上的第三方短信拦截应用,避免验证码被拦截。
- 切换网络环境(Wi-Fi/移动数据),部分网络运营商可能延迟或拦截Google短信。
- 确认测试地区可正常接收国际短信,部分地区存在运营商限制。
代码优化
- 延长验证码超时时间:将
timeout从20秒调整为30秒,减少网络波动导致的超时。 - 完善超时回调:在
codeAutoRetrievalTimeout中添加用户提示,示例:codeAutoRetrievalTimeout: (String verificationId) { Fluttertoast.showToast(msg: "验证码自动获取超时,请手动输入或重新发送"); }, - 校验手机号格式:确保
_prefix + phoneController.text符合E.164标准(如+8613xxxxxxxxx),格式错误会导致短信无法发送。
- 延长验证码超时时间:将
服务状态确认
- 查看Firebase官方状态页面,确认手机号认证服务无故障或维护。
内容的提问来源于stack exchange,提问作者Fada
相关产品推荐
相关产品推荐

