Firebase SignIn error only in android release mode

Viewed 51

I have phone sign in with Firebase in my flutter app and it all works perfectly in debug mode both iOS and Android but when in release mode it throws an error only on Android device (physical). iOS still works perfect in release mode.

[+9626 ms] E/flutter (21573): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'String'
[        ] E/flutter (21573): #0      MethodChannelFirebaseAuth.verifyPhoneNumber.<anonymous closure> (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:655)
[        ] E/flutter (21573): #1      _RootZone.runUnaryGuarded (dart:async/zone.dart:1593)
[        ] E/flutter (21573): #2      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
[        ] E/flutter (21573): #3      _DelayedData.perform (dart:async/stream_impl.dart:515)
[        ] E/flutter (21573): #4      _PendingEvents.handleNext (dart:async/stream_impl.dart:620)
[        ] E/flutter (21573): #5      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591)
[        ] E/flutter (21573): #6      _microtaskLoop (dart:async/schedule_microtask.dart:40)
[        ] E/flutter (21573): #7      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)
[        ] E/flutter (21573): 

This is my function

 Future verifyPhoneNumber() async {
    
      try {
        await FirebaseAuth.instance.verifyPhoneNumber(
          phoneNumber: _telNumberController.text,
          verificationCompleted: (PhoneAuthCredential credential) async {
            print('COMPLETED');
          
          },
          verificationFailed: (FirebaseAuthException e) {
            print('FAILED');
          },
          codeSent: (
            String verificationId,
            int? resendToken,
          ) {
            print('CODE SENT');
          },
          codeAutoRetrievalTimeout: (String verificationId) {},
        );
      } catch (e) {
        print(e);
      }
    }

Its passing the phone number correctly but even not reaching any print - neither for verificationCompleted nor verificationFailed

any ideas why can I get this behavior?

UPD: I found out that my release SHA1 and SHA256 were different from the debug ones so I added them to Firebase, downloaded new google-services.json file, run flutter clean but.. the problem persists. I believe it has something to do with re-Captcha that the app can't perform in release mode.

UPD2 I also added SHA keys from Google Play Store. So now I have debug, release and Google Play SHA1 and SHA256. But still have the same error and still it works perfect in debug but not in release

UPD3 found that it happens when I change in build.gradle from

signingConfig signingConfigs.debug

to

signingConfig signingConfigs.release

So something is wrong with the release signinConfig I do

  1. Create an upload keystore with this command ~keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload~

  2. Create key.properties in android folder

    storePassword=***
    keyPassword=***
    keyAlias=upload
    storeFile=/Users/amarchuk/upload-keystore.jks~
  1. Configure signing in gradle this code before the android block
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }
  1. And inside the android block
signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }

What can be wrong?

0 Answers
Related