I did update the firebase dependency to latest version as per this doc
Old dependencies
implementation 'com.google.firebase:firebase-core:17.5.1'
implementation 'com.google.firebase:firebase-analytics:17.6.0'
implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
implementation 'com.google.firebase:firebase-auth:19.4.0'
implementation 'com.google.firebase:firebase-firestore-ktx:21.7.1'
Updated dependencies
//firebase
//By using the Firebase Android BoM, your app will always use compatible versions of the Firebase Android libraries.
implementation platform('com.google.firebase:firebase-bom:26.0.0')
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx'
//The Firebase Authentication Android library now works on devices without Google Play services.
// implementation "com.google.android.gms:play-services-base:17.5.0"
old phone auth method works fine
PhoneAuthProvider.getInstance().verifyPhoneNumber(
number,
60,
TimeUnit.SECONDS,
activity,
this
)
But,after updated the dependency above method shows deprecated.so,tried this
val auth = FirebaseAuth.getInstance()
binding.fab.setOnClickListener {
val options = PhoneAuthOptions.newBuilder(auth)
.setPhoneNumber("+1 5123456788")
.setTimeout(60L, TimeUnit.SECONDS)
.setActivity(this)
.build()
PhoneAuthProvider.verifyPhoneNumber(options);
}
This error occurs when build method is called.
2020-10-29 16:14:57.406 3422-3422/com.gowtham.firebasephoneauthwithmvvm E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gowtham.firebasephoneauthwithmvvm, PID: 3422
java.lang.NullPointerException: null reference
at com.google.android.gms.common.internal.Preconditions.checkNotNull(com.google.android.gms:play-services-basement@@17.1.0:2)
at com.google.firebase.auth.PhoneAuthOptions$Builder.build(com.google.firebase:firebase-auth@@20.0.0:22)
at com.gowtham.firebasephoneauthwithmvvm.MainActivity$onPostCreate$2.onClick(MainActivity.kt:50)
at android.view.View.performClick(View.java:7861)
at android.view.View.performClickInternal(View.java:7830)
at android.view.View.access$3600(View.java:878)
at android.view.View$PerformClick.run(View.java:29354)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2020-10-29 16:14:57.428 3422-3422/com.gowtham.firebasephoneauthwithmvvm I/Process: Sending signal.
This error occured after i added the callbacks
2020-10-30 10:47:34.239 24898-24898/com.gowtham.firebasephoneauthwithmvvm E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gowtham.firebasephoneauthwithmvvm, PID: 24898
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:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.gowtham.firebasephoneauthwithmvvm-Cn_en1RDZ9XDneMCJamrPw==/base.apk"],nativeLibraryDirectories=[/data/app/com.gowtham.firebasephoneauthwithmvvm-Cn_en1RDZ9XDneMCJamrPw==/lib/arm64, /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.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:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
2020-10-30 10:47:34.314 24898-24898/com.gowtham.firebasephoneauthwithmvvm I/Process: Sending signal. PID: 24898 SIG: 9
According to the Firebase Phone-Auth documentation, you need to enable reCAPTCHA verification
Start by adding implementation 'androidx.browser:browser:1.3.0'
at build.gradle (module app) dependencies
This will make firebase to open the browser for reCAPTCHA verification.
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