Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem retrieving SafetyNet Token: 7, Flutter - Firebase Phone_Auth

I'm trying to implement the phone_auth provided by firebase, but it throws these errors and force closes when FirebaseAuth.instance.verifyPhoneNumber() is called.

E/zza     (12829): Problem retrieving SafetyNet Token: 7: 
W/ActivityThread(12829): handleWindowVisibility: no activity for token android.os.BinderProxy@28af8e3
W/mesecure.wmsap(12829): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/mesecure.wmsap(12829): Accessing hidden method Lsun/misc/Unsafe;- 
>getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/mesecure.wmsap(12829): Accessing hidden method Lsun/misc/Unsafe;- 
>putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/mesecure.wmsap(12829): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/mesecure.wmsap(12829): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/mesecure.wmsap(12829): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
.
.
D/DecorView(12829): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@5ad02b8[RecaptchaActivity]
D/AndroidRuntime(12829): Shutting down VM
E/AndroidRuntime(12829): FATAL EXCEPTION: main
E/AndroidRuntime(12829): Process: com.webmesecure.wmsapp, PID: 12829
E/AndroidRuntime(12829): java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/browser/customtabs/CustomTabsIntent$Builder;
E/AndroidRuntime(12829):    at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.0:92)
E/AndroidRuntime(12829):    at com.google.firebase.auth.api.internal.zzeq.zza(com.google.firebase:firebase-auth@@20.0.0:79)
E/AndroidRuntime(12829):    at com.google.firebase.auth.api.internal.zzeq.onPostExecute(com.google.firebase:firebase-auth@@20.0.0:88)
E/AndroidRuntime(12829):    at android.os.AsyncTask.finish(AsyncTask.java:755)
E/AndroidRuntime(12829):    at android.os.AsyncTask.access$900(AsyncTask.java:192)
E/AndroidRuntime(12829):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
E/AndroidRuntime(12829):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(12829):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(12829):    at android.app.ActivityThread.main(ActivityThread.java:7682)
E/AndroidRuntime(12829):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(12829):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
E/AndroidRuntime(12829):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
E/AndroidRuntime(12829): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.webmesecure.wmsapp-q6bDzrSR-XHplgXhRtWLoQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.webmesecure.wmsapp-q6bDzrSR-XHplgXhRtWLoQ==/lib/arm64, /data/app/com.webmesecure.wmsapp-q6bDzrSR-XHplgXhRtWLoQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
E/AndroidRuntime(12829):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
E/AndroidRuntime(12829):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(12829):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(12829):    ... 12 more
I/Process (12829): Sending signal. PID: 12829 SIG: 9
Lost connection to device.

This is my code, I'm calling the verifyPhoneNumber() when a button s pressed after getting the phone number from the user.

String phoneNumber, verificationId;
String otp, authStatus = "";

Future<void> verifyPhoneNumber(BuildContext context) async {
await FirebaseAuth.instance.verifyPhoneNumber(
  phoneNumber: phoneNumber,
  timeout: const Duration(seconds: 15),
  verificationCompleted: (AuthCredential authCredential) {
    setState(() {
      authStatus = "Your account is successfully verified";
    });
  },
  verificationFailed: (FirebaseAuthException authException) {
    setState(() {
      authStatus = "Authentication failed";
    });
  },
  codeSent: (String verId, [int forceCodeResent]) {
    verificationId = verId;
    setState(() {
      authStatus = "OTP has been successfully send";
    });
    otpDialogBox(context).then((value) {});
  },
  codeAutoRetrievalTimeout: (String verId) {
    verificationId = verId;
    setState(() {
      authStatus = "TIMEOUT";
    });
  },
);
}

Future<void> verifyPhoneNumber(BuildContext context) async {
await FirebaseAuth.instance.verifyPhoneNumber(
  phoneNumber: phoneNumber,
  timeout: const Duration(seconds: 15),
  verificationCompleted: (AuthCredential authCredential) {
    setState(() {
      authStatus = "Your account is successfully verified";
    });
  },
  verificationFailed: (FirebaseAuthException authException) {
    setState(() {
      authStatus = "Authentication failed";
    });
  },
  codeSent: (String verId, [int forceCodeResent]) {
    verificationId = verId;
    setState(() {
      authStatus = "OTP has been successfully send";
    });
    otpDialogBox(context).then((value) {});
  },
  codeAutoRetrievalTimeout: (String verId) {
    verificationId = verId;
    setState(() {
      authStatus = "TIMEOUT";
    });
  },
);
}

otpDialogBox(BuildContext context) {
return showDialog(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return new AlertDialog(
        title: Text('Enter your OTP'),
        content: Padding(
          padding: const EdgeInsets.all(8.0),
          child: TextFormField(
            decoration: InputDecoration(
              border: new OutlineInputBorder(
                borderRadius: const BorderRadius.all(
                  const Radius.circular(30),
                ),
              ),
            ),
            onChanged: (value) {
              otp = value;
            },
          ),
        ),
        contentPadding: EdgeInsets.all(10.0),
        actions: <Widget>[
          FlatButton(
            onPressed: () {
              Navigator.of(context).pop();
              signIn(otp);
            },
            child: Text(
              'Submit',
            ),
          ),
        ],
      );
    });
}

Future<void> signIn(String otp) async {
await FirebaseAuth.instance
    .signInWithCredential(PhoneAuthProvider.credential(
  verificationId: verificationId,
  smsCode: otp,
));
}

This has been bugging me for almost 3 days now. Any help would be greatly appreciated.

like image 237
Jerome Marshall Avatar asked Nov 09 '20 08:11

Jerome Marshall


Video Answer


2 Answers

Ensure you have enabled Android Device Check API and you have added your SHA256 to the Firebase Console.

like image 132
actuallymicah Avatar answered Jan 03 '23 16:01

actuallymicah


I'm having the same issue.The mistake is your dependencies in app/build.gradle in my case I added some extra dependecies from google analytics and after I deleted that it worked

like image 22
Zaharia Lucian Avatar answered Jan 03 '23 14:01

Zaharia Lucian