Reputation: 353
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.
Upvotes: 10
Views: 17660
Reputation: 381
If you follow the above settings and still unsuccessful, please try
$ flutter clean
Upvotes: 0
Reputation: 83
In my case, i going to google developer console and enable Android Device Verification api.
Upvotes: 0
Reputation: 545
In Android, the solution was to enable agree the terms and conditions of the SafetyNet in FireBase Project settings under App Check tab.
Just Click on the App that you want to enable the SafetyNet on and a new checkbox will appear. Agree the term and vola the error is fixed.
Upvotes: 4
Reputation: 61
in my case i forgot to add follwing dependancies
//firebase
implementation 'com.google.firebase:firebase-core:18.0.2'
implementation 'com.google.firebase:firebase-firestore:22.1.2'
implementation 'com.google.firebase:firebase-auth:20.0.3'
implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
implementation 'com.google.firebase:firebase-storage:19.2.2'
implementation 'com.firebaseui:firebase-ui-storage:3.3.1'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.firebase:firebase-messaging:21.0.1'
Upvotes: 0
Reputation: 1
In my case, I have used packages with irregular versions. So when I updated my version to match with my old project which has non-conflicting packages it worked.
Upvotes: 0
Reputation: 1
Remove SHA1 key from firebase. in my case, I had added the SHA1 key for google authentication. Removing the SHA1 key fixed issues with phone verification. Add SHA1 key when creating appbunle for production(in Emulator only google needs SHA1 but after appbudle both authentications will require the key).
Upvotes: 0
Reputation: 101
I had the same issue and tried all the solution but did not work.
In my case, my firebase project was not there in the Google Cloud (https://console.cloud.google.com/). The projects that were there in google cloud were different.
To solve this I first created a project in https://console.cloud.google.com/ and enabled Android Device Verification API. After that created a Firebase project using "Add Firebase to one of your existing Google Cloud projects" and selected my existing https://console.cloud.google.com/ project.
Upvotes: 2
Reputation: 191
In my case i added SHA256 key to my Firebase project and re install the google-service.json. And also i enabled Android Device Check APi.
Upvotes: 3
Reputation: 49
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
Upvotes: 4
Reputation: 709
Ensure you have enabled Android Device Check API and you have added your SHA256 to the Firebase Console.
Upvotes: 34