Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Phone Verification verifyPhoneNumber() deprecated + Application Crashed

Getting error after upgrading Firebase Auth (20.0.0) dependency for Phone Authentication, PhoneAuthProvider.getInstance().verifyPhoneNumber()

Dependency:

implementation 'com.google.firebase:firebase-auth:20.0.0'

Error:

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: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:237)
        at android.app.ActivityThread.main(ActivityThread.java:7948)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder"

Can anyone explain what should I change for new dependency? What are the new steps?

like image 823
Pratik Butani Avatar asked Oct 30 '20 12:10

Pratik Butani


Video Answer


2 Answers

This is what I did to remove the Error:

I referred firebase phone auth documentation and made the necessary changes:

Replace this:

PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber, //phone number to be verified
            60, // validity of the OTP
            TimeUnit.SECONDS,
            (Activity) TaskExecutors.MAIN_THREAD,
            mCallBack // onVerificationStateChangedCallback
    );

With this

PhoneAuthOptions options =
            PhoneAuthOptions.newBuilder(mAuth)
                    .setPhoneNumber(phoneNumber)       // Phone number to verify
                    .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
                    .setActivity(this)                 // Activity (for callback binding)
                    .setCallbacks(mCallBack)          // OnVerificationStateChangedCallbacks
                    .build();
    PhoneAuthProvider.verifyPhoneNumber(options);

Also, add this to your app/gradle file dependencies:

implementation 'androidx.browser:browser:1.2.0'

This will help firebase to open the browser for reCAPTCHA verification.

Hope this works!

like image 100
Jaineel Mamtora Avatar answered Oct 18 '22 20:10

Jaineel Mamtora


Finally, I got solutions with the help of Alex Mamo's Answer and This Documentation

The steps which I followed:

  1. Update new dependency implementation 'com.google.firebase:firebase-auth:20.0.0'

  2. Update new code:

    For send OTP:

    PhoneAuthProvider.verifyPhoneNumber(
         PhoneAuthOptions
                 .newBuilder(FirebaseAuth.getInstance())
                 .setActivity(this)
                 .setPhoneNumber(phoneNumber)
                 .setTimeout(60L, TimeUnit.SECONDS)
                 .setCallbacks(mCallbacks)
                 .build());
    

    For Resend OTP

    PhoneAuthProvider.verifyPhoneNumber(
             PhoneAuthOptions
                     .newBuilder(FirebaseAuth.getInstance())
                     .setActivity(this)
                     .setPhoneNumber(phoneNumber)
                     .setTimeout(60L, TimeUnit.SECONDS)
                     .setCallbacks(mCallbacks)
                     .setForceResendingToken(token)
                     .build());
    

    Still, you will get an error as below:

[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17028 A safety_net_token was passed, but no matching SHA-256 was registered in the Firebase console. Please make sure that this application’s packageName/SHA256 pair is registered in the Firebase Console.

  1. You need to copy SHA-256 from your Keystore or JKS file and add here in SHA Certificate fingerprints:

    enter image description here

  2. Finally, You did it.

    There is no need for a reCAPTCHA verification.

Thank you.

like image 15
Pratik Butani Avatar answered Oct 18 '22 20:10

Pratik Butani