Error while doing phone authentication on firebase

不羁的心 提交于 2021-01-28 19:26:58

问题


While doing phone number authentication on firebase i'm getting crash with this error message. please help.

com.russvkm.chathut is my package name

E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.russvkm.chathut, PID: 24323
        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.0:92)
            at com.google.firebase.auth.api.internal.zzeq.zza(com.google.firebase:firebase-auth@@20.0.0:79)
            at com.google.firebase.auth.api.internal.zzeq.onPostExecute(com.google.firebase:firebase-auth@@20.0.0:88)
            at android.os.AsyncTask.finish(AsyncTask.java:695)
            at android.os.AsyncTask.access$600(AsyncTask.java:180)
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:201)
            at android.app.ActivityThread.main(ActivityThread.java:6826)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
         Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.russvkm.chathut-22XI8m2uPLL7Q6CgxXHPiw==/base.apk"],nativeLibraryDirectories=[/data/app/com.russvkm.chathut-22XI8m2uPLL7Q6CgxXHPiw==/lib/arm, /system/lib, /vendor/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
            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.0:92) 
            at com.google.firebase.auth.api.internal.zzeq.zza(com.google.firebase:firebase-auth@@20.0.0:79) 
            at com.google.firebase.auth.api.internal.zzeq.onPostExecute(com.google.firebase:firebase-auth@@20.0.0:88) 
            at android.os.AsyncTask.finish(AsyncTask.java:695) 
            at android.os.AsyncTask.access$600(AsyncTask.java:180) 
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712) 
            at android.os.Handler.dispatchMessage(Handler.java:106) 
            at android.os.Looper.loop(Looper.java:201) 
            at android.app.ActivityThread.main(ActivityThread.java:6826) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
    I/Process: Sending signal. PID: 24323 SIG: 9

my application is communicating well with firebase server as i don't find any error or crash while doing email authentication.

I'm using following approach to authenticate

PhoneAuthProvider.verifyPhoneNumber(
                PhoneAuthOptions.newBuilder(mAuth)
                        .setPhoneNumber(phoneNumber)
                        .setActivity(this)
                        .setTimeout(60,TimeUnit.SECONDS)
                        .setCallbacks(object:PhoneAuthProvider.OnVerificationStateChangedCallbacks(){
                            override fun onVerificationCompleted(credential:PhoneAuthCredential) {
                                dismissDialog()
                                val smsCode=credential.smsCode
                                Log.i("SMS code",smsCode!!)
                                signInWithPhoneAuthCredential(credential)
                            }

                            override fun onVerificationFailed(p0: FirebaseException) {
                                Toast.makeText(this@Register,p0.message,Toast.LENGTH_SHORT).show()
                            }
                            override fun onCodeSent(verificationId: String, token: PhoneAuthProvider.ForceResendingToken) {
                                super.onCodeSent(verificationId, token)
                                numberLinearLayout.visibility=View.GONE
                                otpLinearLayout.visibility=View.VISIBLE
                                storedVerificationId=verificationId
                                resendToken=token
                                dismissDialog()
                            }
                        })
                        .build()
               )

programme isn't executing otpSent method it is being crashed without sending otp.


回答1:


Some major changes have been made in the latest Firebase auth version, like Recaptcha for human verification.it needs a browser to verify so, Add below depen. and read about changes refer me

    implementation 'androidx.browser:browser:1.2.0'

Update : If you want to avoid human verification, you need to enable safetynet in google cloud console for your firebase project refer this.




回答2:


By adding

implementation "androidx.browser:browser:1.3.0"

it solved my problem but user experience was not good because firebase was opening browser to verify Recaptcha and that was looking odd in app flow.

Firebase Quote "The reCAPTCHA flow will only be triggered when SafetyNet is unavailable or your device does not pass suspicion checks. Nonetheless, you should ensure that both scenarios are working correctly."

So to enable SafetyNet follow below steps or you can also visit Firebase Auth for more info.

1.Go to google cloud console , select your project .

2.Click on navigation menu and select APis & services and then select Dashboard.

3.Click on enable api and services and enable api " Android Device Verification".

4.Add SHA 256 in firebase project settings. (debug and release both)

5.Test your app again.



来源:https://stackoverflow.com/questions/64605057/error-while-doing-phone-authentication-on-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!