Flutter中的Firebase电话OTP身份验证

68bkxrlz  于 2023-06-24  发布在  Flutter
关注(0)|答案(1)|浏览(199)

我正在构建一个Flutter应用程序,涉及使用Firebase的电话OTP身份验证,它给出了以下错误。我在这里感到震惊,不知道如何调试。

2021-01-29 14:07:36.021 32521-32521/com.example.flutter_test1 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.flutter_test1, PID: 32521
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/browser/customtabs/CustomTabsIntent$Builder;
    at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.1:13)
    at com.google.android.gms.internal.firebase-auth-api.zzth.zzb(com.google.firebase:firebase-auth@@20.0.1:7)
    at com.google.android.gms.internal.firebase-auth-api.zzth.onPostExecute(Unknown Source:2)
    at android.os.AsyncTask.finish(AsyncTask.java:755)
    at android.os.AsyncTask.access$900(AsyncTask.java:192)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7397)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.example.flutter_test1-VMY7lKsstWxY71zd6Q5xmA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.flutter_test1-VMY7lKsstWxY71zd6Q5xmA==/lib/arm64, /data/app/com.example.flutter_test1-VMY7lKsstWxY71zd6Q5xmA==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.1:13) 
    at com.google.android.gms.internal.firebase-auth-api.zzth.zzb(com.google.firebase:firebase-auth@@20.0.1:7) 
    at com.google.android.gms.internal.firebase-auth-api.zzth.onPostExecute(Unknown Source:2) 
    at android.os.AsyncTask.finish(AsyncTask.java:755) 
    at android.os.AsyncTask.access$900(AsyncTask.java:192) 
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7397) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935) 

这是我发送OTP的函数:

Future verifyPhoneNumber(BuildContext context) async{
FirebaseAuth auth = FirebaseAuth.instance;

final PhoneVerificationCompleted verificationCompleted = (PhoneAuthCredential phoneAuthCredential) 
async {
await auth.signInWithCredential(phoneAuthCredential);
};

PhoneVerificationFailed verificationFailed =
  (FirebaseAuthException authException){
print("FAILED AUTH $authException");
};

//When code is Sent
PhoneCodeSent codeSent =
  (String verificationId, [int forceSendingToken]) async {
    String smsCode = '';
    PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(verificationId: 
   verificationId, smsCode: smsCode);
    await auth.signInWithCredential(phoneAuthCredential);
 };

 PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
  (String verificationId) {
_verificationId = verificationId;
 };

try {
  await auth.verifyPhoneNumber(
  phoneNumber: _mobileNumberController.text,
  timeout: const Duration(seconds: 10),
  verificationCompleted: verificationCompleted,
  verificationFailed: verificationFailed,
 codeSent: codeSent,
  codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
 );
}catch(e){
 print("error is : $e");
 }

输入移动的号码后,我在点击按钮时调用verifyPhoneNumber()。

inkz8wg9

inkz8wg91#

由于您仍在调试,因此还需要实现reCaptcha支持,因为使用debug sha指纹时Android safetynet会失败。
在项目中-> android-> app-> build.gradle,在底部的依赖项中添加以下行:

implementation "androidx.browser:browser:1.2.0"

所以build.gradle文件应该看起来像这样:
https://gitlab.com/codebasetutorials/flutter-phone-authentication/-/blob/7f29304527ffc8756321fcccfac7a3b4a2cbdba9/android/app/build.gradle
同时确保minSdk至少为21
我制作了一个视频教程,关于你在这里需要的一切:https://youtu.be/dTmgjPkBN58

相关问题