Flutter Firebase 电话身份验证不适用于 Android

时间:2021-01-12 13:53:00

标签: firebase flutter firebase-authentication

我正在尝试使用 firebase 电话验证登录,但它不起作用。代码未发送。 我尝试使用“keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android”来添加 sha-1 和 sha-256 密钥(我也尝试过其他方法) ,但仍然没有工作。我尝试启用 android 设备验证 API,但没有任何效果。我不知道我还能做什么,我什么都试过了。

代码如下:

      Future<void> _login() async {
    final _firebaseAuth = FirebaseAuth.instance;
    print('trying to send code');
    _firebaseAuth.verifyPhoneNumber(
      phoneNumber: '<myphonenumberhere>',
      verificationCompleted: (phoneAuthCredential) {
        print('verification completed');
      },
      verificationFailed: (exception) {
        print('verification failed');
      },
      codeSent: (verId, forceResToken) {
        print('code sent');
      },
      codeAutoRetrievalTimeout: (verId) {
        print('auto retieval timeouted');
      },
    );
  }
    I/flutter ( 5839): trying to send code
E/zzbf    ( 5839): SafetyNet Attestation fails basic integrity.
I/Timeline( 5839): Timeline: Activity_launch_request time:94668823 intent:Intent { act=com.google.firebase.auth.internal.ACTION_SHOW_RECAPTCHA pkg=com.example.test_phone_auth cmp=com.example.test_phone_auth/com.google.firebase.auth.internal.RecaptchaActivity (has extras) }
W/ActivityThread( 5839): handleWindowVisibility: no activity for token android.os.BinderProxy@7547327
W/test_phone_aut( 5839): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
W/zzdk    ( 5839): keyset not found, will generate a new one
W/zzdk    ( 5839): java.io.FileNotFoundException: can't read keyset; the pref value GenericIdpKeyset does not exist
W/zzdk    ( 5839):  at com.google.android.gms.internal.firebase-auth-api.zzdo.zzc(com.google.firebase:firebase-auth@@20.0.1:10)
W/zzdk    ( 5839):  at com.google.android.gms.internal.firebase-auth-api.zzdo.zzb(com.google.firebase:firebase-auth@@20.0.1:1)
W/zzdk    ( 5839):  at com.google.android.gms.internal.firebase-auth-api.zzat.zzi(com.google.firebase:firebase-auth@@20.0.1:1)
W/zzdk    ( 5839):  at com.google.android.gms.internal.firebase-auth-api.zzdj.zzi(com.google.firebase:firebase-auth@@20.0.1:1)
W/zzdk    ( 5839):  at com.google.android.gms.internal.firebase-auth-api.zzdj.zzd(com.google.firebase:firebase-auth@@20.0.1:2)
W/zzdk    ( 5839):  at com.google.firebase.auth.internal.zzk.<init>(com.google.firebase:firebase-auth@@20.0.1:7)
W/zzdk    ( 5839):  at com.google.firebase.auth.internal.zzk.zza(com.google.firebase:firebase-auth@@20.0.1:3)
W/zzdk    ( 5839):  at com.google.firebase.auth.internal.RecaptchaActivity.zzd(com.google.firebase:firebase-auth@@20.0.1:9)
W/zzdk    ( 5839):  at com.google.android.gms.internal.firebase-auth-api.zzth.<init>(com.google.firebase:firebase-auth@@20.0.1:13)
W/zzdk    ( 5839):  at com.google.firebase.auth.internal.RecaptchaActivity.onResume(com.google.firebase:firebase-auth@@20.0.1:43)
W/zzdk    ( 5839):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1413)
W/zzdk    ( 5839):  at android.app.Activity.performResume(Activity.java:7400)
W/zzdk    ( 5839):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3820)
W/zzdk    ( 5839):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3860)
W/zzdk    ( 5839):  at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
W/zzdk    ( 5839):  at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
W/zzdk    ( 5839):  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
W/zzdk    ( 5839):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
W/zzdk    ( 5839):  at android.os.Handler.dispatchMessage(Handler.java:106)
W/zzdk    ( 5839):  at android.os.Looper.loop(Looper.java:201)
W/zzdk    ( 5839):  at android.app.ActivityThread.main(ActivityThread.java:6810)
W/zzdk    ( 5839):  at java.lang.reflect.Method.invoke(Native Method)
W/zzdk    ( 5839):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
W/zzdk    ( 5839):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
I/zzjy    ( 5839): Provider GmsCore_OpenSSL not available
W/Activity( 5839): Slow Operation: Activity com.example.test_phone_auth/com.google.firebase.auth.internal.RecaptchaActivity onResume took 219ms
I/DpmTcmClient( 5839): RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
W/System  ( 5839): Ignoring header X-Firebase-Locale because its value was null.

1 个答案:

答案 0 :(得分:0)

如果您在模拟器上测试它,则需要包含依赖项 androidx.browser:browser 才能使其正常工作。

SHA256 密钥和安卓设备验证 API 用于真实设备通过 Safetynet 检查。

查看 Enable app verification 部分和 my response in the Flutterfire issue thread