Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

app crash while using firebase phone Auth in android

This question is not similar to any of the others. I've already tried many solutions from App crashes with firebase phone auth, error while getting firebase phone auth OTP

Android app crashes on firebase phone authentication, but nothing works.

In my flutter app(android) I am using firebase phone authentication. When I call the 'verifyPhoneNumber' method of firebase to send OTP, my app getting crashes and exits leaving no error message.

Here's my code

 final FirebaseAuth _auth = FirebaseAuth.instance;
 Future sendOTP(String mobNo, BuildContext context, UserData _userData) async {
 try {
  _auth.verifyPhoneNumber(
      phoneNumber: mobNo,
      verificationCompleted: (val) {
        print("verification completed val = $val");
      },
      verificationFailed: (val) {
        print("verification failed val = $val");
      },
      codeSent: (String verificationId, [int forceResendingToken]) {
        print("code sent to $mobNo");
        Navigator.pushNamed(context, '/get_otp', arguments: {
          'verificationId': verificationId,
          'UserData': _userData,
        });
      },
      codeAutoRetrievalTimeout: (val) {
        print("code auto retrieval timeout val = $val");
      });
} catch (e) {
  print("auth error = $e");
  }
}

I added my SHA-1, SHA-256 certificates in my firebase project, I tried changing versions of firebase_auth, fiebase_core. But, nothing works. I tried adding breakpoints in all the lines. The app exits when the reaches this line. _auth.verifyPhoneNumber( It is not proceeding further. Please help me to solve this!!??

Here's my debug console log

E/AndroidRuntime(17712): java.lang.NoClassDefFoundError: Failed resolution of: 
Landroidx/browser/customtabs/CustomTabsIntent$Builder;
E/AndroidRuntime(17712):    at                     
com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase- 
auth@@20.0.2:13)
E/AndroidRuntime(17712):    at com.google.android.gms.internal.firebase-auth- 
api.zztw.zzb(com.google.firebase:firebase-auth@@20.0.2:7)
E/AndroidRuntime(17712):    at com.google.android.gms.internal.firebase-auth- 
api.zztw.onPostExecute(Unknown Source:2)
E/AndroidRuntime(17712):    at android.os.AsyncTask.finish(AsyncTask.java:755)
E/AndroidRuntime(17712):    at android.os.AsyncTask.access$900(AsyncTask.java:192)
E/AndroidRuntime(17712):    at 
android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
E/AndroidRuntime(17712):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(17712):    at android.os.Looper.loop(Looper.java:228)
E/AndroidRuntime(17712):    at 
android.app.ActivityThread.main(ActivityThread.java:7826)
E/AndroidRuntime(17712):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17712):    at 
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(17712):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:981)
E/AndroidRuntime(17712): Caused by: java.lang.ClassNotFoundException: Didn't find 
class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip 
file "/data/app/com.creda.location_project- 
1fyv3Q9ek4vLZKMcRkGyDQ==/base.apk"],nativeLibraryDirectories= 
[/data/app/com.creda.location_project-1fyv3Q9ek4vLZKMcRkGyDQ==/lib/arm64, 
/data/app/com.creda.location_project-1fyv3Q9ek4vLZKMcRkGyDQ==/base.apk!/lib/arm64-v8a, 
/system/lib64, /system/product/lib64]]
question from:https://stackoverflow.com/questions/65839861/app-crash-while-using-firebase-phone-auth-in-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In new Firebase auth version i,e 20.0.0 ,they've made major changes like Recaptcha , SafetyNet for human verification. To fix crash you can add

implementation "androidx.browser:browser:1.3.0"

This dependency only fix crash but still user experience will not look good because firebase will open browser to verify Recaptcha .

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. Download and replace the latest google-services.json file in your project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...