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

Firebase手机号验证报错Error code:39,已做常规配置仍未解决

Firebase Auth手机号验证报错:unknown status code: 17499 Error code:39

E/FirebaseAuth( 9898): [SmsRetrieverHelper] SMS verification code
request failed: unknown status code: 17499 Error code:39 I/flutter (
9898): An internal error has occurred. [ Error code:39 ]

已完成的配置操作

  • 在Firebase控制台添加了SHA-1和SHA-256密钥
  • 在Firebase控制台启用了手机号和Google登录方式
  • 将google-services.json放入android/app目录,GoogleService-Info.plist放入ios/Runner目录
  • 项目根目录已自动添加firebase.json文件
  • 在Firebase控制台App Check中启用Play Integrity,并添加了调试和发布版SHA256密钥
  • 启用了Firebase Blaze付费方案
  • 在Google Cloud控制台启用了Google Play Integrity API
  • 将应用上传至Play Store进行内部测试
  • 等待1天以避免配额超限,确保配置生效

项目配置代码

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter

  flutter_localizations:
    sdk: flutter
  intl: ^0.19.0
  shared_preferences: ^2.3.1
  firebase_core: ^3.3.0
  firebase_auth: ^5.1.4
  flutter_bloc: ^8.1.6
  fluttertoast: ^8.2.8
  cloud_firestore: ^5.2.1
  image_picker: ^1.1.2
  firebase_storage: ^12.1.3
  mobile_scanner: ^5.1.1
  omni_datetime_picker: ^2.0.3
  pdf: ^3.11.1
  printing: ^5.13.1
  flutter_email_sender: ^6.0.3
  pretty_qr_code: ^3.3.0
  url_launcher: ^6.3.0
  firebase_app_check: ^0.3.0+4

项目根目录build.gradle

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.4.2"
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    localProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    namespace "com.---.----" //已隐藏
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.---.----" //已隐藏
        minSdkVersion 23
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
    
    signingConfigs {
        release {
            keyAlias localProperties['keyAlias']
            keyPassword localProperties['keyPassword']
            storeFile localProperties['storeFile'] ? file(localProperties['storeFile']) : null
            storePassword localProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:33.1.2')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-appcheck-playintegrity'
}

核心业务代码

main.dart初始化逻辑

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    systemNavigationBarColor: Colors.white, // navigation bar color
    statusBarColor: Colors.white, // status bar color
    statusBarIconBrightness: Brightness.dark, // status bar icons' color
    systemNavigationBarIconBrightness:
        Brightness.light, //navigation bar icons' color
  ));
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  await FirebaseAppCheck.instance.activate();
  runApp(const MyApp());
}

手机号验证逻辑

void _verifyPhone(AuthVerifyPhoneEvent event, emit) async {
    await FirebaseAuth.instance.setSettings(appVerificationDisabledForTesting: false);
    await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber: event.phone,
      verificationCompleted: (PhoneAuthCredential credential) async {
        await FirebaseAuth.instance.signInWithCredential(credential);
        _onVerificationComplete();
      },
      verificationFailed: (FirebaseAuthException e) {
        if (e.code == 'invalid-phone-number') {
          add(AuthEmitStateEvent(
              state: state.copyWith(error: "invalidPhoneNumber")));
        } else {
          print("---error:${e.message}");
          add(AuthEmitStateEvent(state: state.copyWith(error: e.message)));
        }
      },
      codeSent: (String verificationId, int? resendToken) {
        this.verificationId = verificationId;
        add(AuthEmitStateEvent(state: state.copyWith(pages: Pages.Code)));
      },
      codeAutoRetrievalTimeout: (String verificationId) {
        this.verificationId = verificationId;
      },
    );
  }

Flutter环境检测结果

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.0, on macOS 13.6.7 22G720 darwin-x64, locale en-KG)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.92.1)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

Flutter环境检测无异常,但上述错误仍未解决,寻求技术支持。

内容的提问来源于stack exchange,提问作者Jamaldin Sabirjanov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 15:14:52