7

Steps how I implemented.

As advised, I implemented all the way. It was quite good in debug mode. Unfortunately its not working in release mode even I added my debug and release sha1 keys in firebase console.

Step 1. Coding part is here

final PhoneVerificationCompleted verificationCompleted =
    (PhoneAuthCredential user) {
  successMessage('Your phone number verified successfully!');
  _loginNotifier.validate();
};

 final PhoneVerificationFailed verificationFailed = (FirebaseAuthException authException) {
  errorMessage('Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}');
  print(
      'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}');
};

 final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
    (String verificationId) {
  this._verificationId = verificationId;
  print("time out");
};

 firebaseAuth = FirebaseAuth.instance;
firebaseAuth.verifyPhoneNumber(
    phoneNumber: '+$_phoneWithCC',
    timeout: const Duration(seconds: 60),
    verificationCompleted: verificationCompleted,
    verificationFailed: verificationFailed,
    codeSent: codeSent,
    codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);

Step 2: Here is the firebase console sha1 keys for debug and release mode

Added all three different sha1 keys but still not working:(

Error I am getting:

As I said, in debug mode all good as expected But in release mode, after initiating the otp function, immediately PhineVerificationFailed with null message and null code.

If still anything I missed please advice. Thanks all

IamVariable
  • 408
  • 6
  • 23
  • so can you try downloading the new google-services.json after you added the sha1 and replace it with the old one. – Krish Bhanushali Aug 29 '20 at 06:07
  • Yes @KrishBhanushali I did.. so wired :( – IamVariable Aug 29 '20 at 09:00
  • in release mode, immediately i am getting called verificationFailed function. my bad, the data from verificationFailed function is null :( – IamVariable Aug 30 '20 at 08:53
  • keytool -list -v -keystore PATH_JKS_FILE -alias XXX this is how I got my release SHA1 key -FYI – IamVariable Aug 30 '20 at 08:56
  • Hi, when you say 'release' are you releasing to the play store (and using google app signing)? If so you need to use the play store sha fingerprint (not your local machines one you build with): See my answer here: https://stackoverflow.com/questions/57840495/flutter-firebase-google-login-not-working-after-building-apk-file/59743742#59743742 – Jan Aug 31 '20 at 05:27
  • Yes, you can see in the image, i added playstore sha1 too https://i.stack.imgur.com/f9ZCP.png – IamVariable Aug 31 '20 at 05:28
  • 2
    @MuthuS Have you added permissions in your manifest file for internet ? That solved my issues in release mode. – Suthura Sudharaka Aug 31 '20 at 17:30
  • Yes, i did.. Since all other API's are working.. – IamVariable Sep 01 '20 at 01:28
  • Have you checked this? https://stackoverflow.com/q/36999751/4729203 – wonsuc Sep 07 '20 at 01:39

4 Answers4

6

Apart from SHA1 - you also need SHA256 thumbprint for release apk.
I faced similar issue for firebase google authentication.
Can you add SHA256 thumbprint to firebase project console and try again ?

abhijat_saxena
  • 705
  • 5
  • 20
  • ok lemme try, between, why the failed message and code is null? did my implementation is correct? – IamVariable Sep 01 '20 at 07:01
  • 1
    https://ibb.co/rvZPgtK after added sha-256 release and debug keys then downloaded the json file and rebuild the app then i am getting the same error:( – IamVariable Sep 01 '20 at 07:07
  • between, how to get SHA1 for release mode.. keytool -list -v -keystore PATH_JKS_FILE -alias XXX is this correct?? @abijith – IamVariable Sep 02 '20 at 21:21
  • open cmd inside your android folder, then run the following command - ./gradlew signingReport link - https://stackoverflow.com/questions/51845559/generate-sha-1-for-flutter-app – abhijat_saxena Sep 02 '20 at 21:37
0

After adding SHA1 you have to reinstall your app from Google Play.

Mr Random
  • 1,992
  • 7
  • 20
0

Besides adding sha256 and SHA1, you need to add your email in the Firebase console. See the attached image.

enter image description here

Akram
  • 2,158
  • 1
  • 17
  • 24
0

For my case I was just missing the 'Andoid Device Verification' API for my Firebase project from Google Cloud.

https://console.cloud.google.com/apis/library/androidcheck.googleapis.com?project={put_your_project_name_here}