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?
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!
Finally, I got solutions with the help of Alex Mamo's Answer and This Documentation
The steps which I followed:
Update new dependency implementation 'com.google.firebase:firebase-auth:20.0.0'
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.
You need to copy SHA-256 from your Keystore or JKS file and add here in SHA Certificate fingerprints:
Finally, You did it.
There is no need for a reCAPTCHA verification.
Thank you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With