Firebase Phone Verification verifyPhoneNumber() deprecated + Application Crashed
Solution 1
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!
Solution 2
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.
Solution 3
In new Firebase auth version,they've made major changes like Recaptcha for human verification.it needs browser to verify so,Add below depen.and read about changes refer me
implementation 'androidx.browser:browser:1.2.0'
Solution 4
In new Firebase auth version,they've made major changes like Recaptcha , SafetyNet for human verification. I have faced the same issue by adding
implementation "androidx.browser:browser:1.3.0
it solved my problem but user experience was not good 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 https://firebase.google.com/docs/auth/android/phone-auth for info
- Update auth dependency implementation 'com.google.firebase:firebase-auth:20.0.1'
- To start PhoneNumber Verification
PhoneAuthOptions options = PhoneAuthOptions.newBuilder(mAuth)
.setPhoneNumber(phoneNumber) // Phone number to verify
.setTimeout(30L, TimeUnit.SECONDS) // Timeout and unit
.setActivity(this) // Activity (for callback binding)
.setCallbacks(mCallbacks)
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
-
Go to google cloud console, select your project.
-
Click on the navigation menu and select APis & services and then select Dashboard.
-
Click on enable api and services and enable API " Android Device Verification".
-
Add SHA-1 and SHA 256 in firebase project settings.(debug and release both)
-
Download and replace the latest google-services.json file in your project.
-
Test your app again on real device.
Solution 5
As it is specified in the official documentation of verifyPhoneNumber(String phoneNumber, long timeout, TimeUnit unit, Activity activity, PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks) method:
This method is deprecated in favor of verifyPhoneNumber(PhoneAuthOptions)
So from now on, to verify a phone number we'll need to call this method and pass a PhoneAuthOptions
object as an argument. In my opinion, this is some kind of similar to updateProfile(UserProfileChangeRequest request), where we should pass a PhoneAuthOptions
object as an argument.
Pratik Butani
Pratik Butani is Android/Flutter Lead at 7Span - Ahmedabad. He is working with Flutter Development since 2020 and Android Development since 2013. He is on the list of Top 100 User’s (85th) in India and Top 10 User’s (6th) in Gujarat as Highest Reputation Holder on StackOverflow. He was co-organizer at Google Developer Group – Rajkot in 2014-17. All-time Learner of new things, Googler and Eager to Help IT Peoples. He is also likes to share his knowledge of Android and Flutter with New Learner. SOReadyToHelp ツ Fell in Love with Android ツ I really feel proud to up-vote My Favorite #SO friend. => Android Application Developer by Passion :) => Being Helpful by Nature ;) => Now in List of Top 100 User's (85) in India and Top 10 User's (6) in Gujarat as Highest Reputation Holder on StackOverflow => Visit my blogs for learning new things : Happy to Help :) :) => My Apps on Playstore: AndroidButs & PratikButani => My Articles on Medium => Join Me on LinkedIn => Tweet Me on Twitter => Follow Me on Quora - Top Writer on Quora in 2017 => Hangout with Me on [email protected] => Social Networking Facebook => Get Users list whose bio's contains given keywords More about me :) -> Pratik Butani
Updated on June 05, 2022Comments
-
Pratik Butani about 2 years
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?
-
Pratik Butani over 3 yearsI am getting
[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Requests to this API identitytoolkit method google.cloud.identitytoolkit.v1.AuthenticationService.SendVerificationCode are blocked.
-
Alex Mamo over 3 yearsFirst of all, are you sure you are using the correct number? If yes, then most likely it's because the Authentication Service has blocked the service that sends verifications codes. If this error persists, maybe you should contact Firebase tea. However, there are some interesting answers here.
-
Pratik Butani over 3 yearsThe got solution, On this page I have restrict key that I have changed now to Don't restrict key
-
Pratik Butani over 3 yearsWhat is the use of
implementation 'androidx.browser:browser:1.2.0'
The reCAPTCHA thing will be done by Firebase itself? -
Jaineel Mamtora over 3 yearsIf we are using a phone with no Google Play Services OR an Emulator, Firebase will use reCAPTCHA for phone verification. The reCAPTCHA will open in the browser. So, to allow the app to open the browser, we need to add this dependency.
-
Alex Mamo over 3 yearsGood to hear that ;)
-
Thangamani Eraniyan over 3 yearsadding --> implementation 'androidx.browser:browser:1.2.0' helped from crashing
-
Sourav Kannantha B over 3 yearsI did all the above steps. But its still opening the browser in my mobile. :(
-
Sourav Kannantha B over 3 years@AlexMamo I have done all the steps above, mentioned in Pratik's answer, but still it is opening browser before sending otp. What else I have to do ?
-
Pratik Butani over 3 years@SouravKannanthaB check this stackoverflow.com/a/64614349/1318946
-
Sourav Kannantha B over 3 years@JaineelMamtora for me, its opening browser every time I login.. What to do?
-
Jaineel Mamtora over 3 years@SouravKannanthaB Are you using debug apk or release?
-
Sourav Kannantha B over 3 years@JaineelMamtora I was using debug apk, (it's the one available under 'build' section right?).
-
Jaineel Mamtora over 3 years@SouravKannanthaB Okay, so if you are using debug apk, most probably the app will open the browser for verification. If you are using release apk, it will directly send the OTP provided you have added your fingerprints (SHA1 and/or SHA256) in the firebase console. I suggest, use KeyStore Explorer for generating the Keystore and add the Fingerprint generated to the Firebase console.
-
Sourav Kannantha B over 3 years@JaineelMamtora Thanks. But keystore can be generated from android studio itself, RHS Gradle menu > Tasks > android > signingReport
-
Jaineel Mamtora over 3 years@SouravKannanthaB I agree. But when I generated fingerprints from Gradle and tried running the release apk, I was getting an error saying: 'app is not authorized to use firebase authentication'. The error was solved when I generated fingerprints from KeyStore Explorer.
-
Sourav Kannantha B over 3 years@JaineelMamtora Fine.. I will remeber this point when I will be generating my keystore. Thanks :)
-
Pratik Butani over 3 yearsHave you implemented it?
-
Himanshi Thakur over 3 years@PratikButani yes
-
Madhusudan Sharma over 3 yearsThis is the only solution which worked perfectly. Thanks!!
-
Himanshi Thakur over 3 years@SouravKannanthaB You need to enable "Android Device Verification" . You can see steps here stackoverflow.com/a/65248293/9942608