1

I was trying to signIn with mobile in flutter. Every time I enter the mobile number It show those error messages and exit from the app. I used code from https://firebase.flutter.dev/docs/auth/phone documentation. Code are almost same as documentation.

E/zzf     (31149): Problem retrieving SafetyNet Token: 7:
I/Timeline(31149): Timeline: Activity_launch_request time:483815514
W/ActivityThread(31149): SCHED: com.example.newdevice/.MainActivity [85, r=578ms, a=96ms, w=57017ms]
W/ActivityThread(31149): handleWindowVisibility: no activity for token android.os.BinderProxy@dc5d811
D/ForceDarkHelper(31149): updateByCheckExcludeList: pkg: com.example.newdevice activity: com.google.firebase.auth.internal.RecaptchaActivity@5ed566f
I/chatty  (31149): uid=10315(com.example.newdevice) identical 1 line
D/ForceDarkHelper(31149): updateByCheckExcludeList: pkg: com.example.newdevice activity: com.google.firebase.auth.internal.RecaptchaActivity@5ed566f
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/ample.newdevic(31149): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
......More error message.......

I am using updated version for everything like Java/Flutter/ Firebase sdk. Also I added SHA1 key in Firebase app and enabled phone auth. I also tried both physical and virtual device. But every time same problem.

Dependencies in app level build.gradel file

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:26.2.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'androidx.browser:browser:1.3.0'
    implementation 'com.android.support:multidex:1.0.3'
}

Flutter code portion for mobile verification:

                    FirebaseAuth _auth = FirebaseAuth.instance;
                    await _auth.verifyPhoneNumber(
                        phoneNumber: mobileController.text,
                        verificationCompleted:
                            (PhoneAuthCredential credential) {
                          print(credential);
                        },
                        verificationFailed: (FirebaseAuthException error) {
                          print(error);
                        },
                        codeSent:
                            (String verificationId, int resendToken) async {
                              print('Your otp sent');
                              String smsCode = '123456';

                              PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.credential(verificationId: verificationId, smsCode: smsCode);

                              // Sign the user in (or link) with the credential
                              await _auth.signInWithCredential(phoneAuthCredential);
                            },
                        timeout: const Duration(seconds: 120),
                        codeAutoRetrievalTimeout: (String verificationId) {
                          print(verificationId);
                        }
                      );

I sucked here. Tried almost everything I can.

Nasar
  • 66
  • 1
  • 8
  • Please edit the question to show all relevant code, even if it's "almost the same" as something else. Be sure to explain what about that code does not work the way you expect. – Doug Stevenson Dec 27 '20 at 18:33
  • Thanks for your comments. Flutter code portion is added now. The "codeSent" function never executed. – Nasar Dec 28 '20 at 05:35

2 Answers2

2

Well I overcome the problem using those steps-

  1. In the Google Cloud console, enable the Android DeviceCheck API for your project. (**Note: Select your Firebase project and enable it)

  2. Get SHA-256 fingerprint for for your app.

  3. Go to Settings Page of the Firebase console, select your project and set the SHA-256 fingerprint for your app.

Re-run the app. That solution worked for me. Hope it works for you too.

Nasar
  • 66
  • 1
  • 8
1

Try these steps.

  1. Ofcourse, enable Android Device Verification(API) for your project
  2. You need to add SHA1 and SHA256 hash keys. (NOTE: not debug keys, you need to add release build keys.
  3. To create those release build keys - check this website (https://www.youtube.com/watch?v=S7yyA6SFnjE)
  4. Add those created release build keys to your firebase project and then import your newly downloaded json file into your project.