简体   繁体   中英

Local authentication problem in release apk flutter

I have faced this issue recently. The local authentication would work flawlessly on flutter run and --release, --profile. But when I make the APK and then install it, the local auth does not work, the app crashes. There is no error in the app when i run the same app but when the cable is connected to my computer.

Here, the function call begins,

onPressed: () {
                              bool enable = preferences.getBool('bioAuth');
                              if (enable == null || enable == false) {
                                showSnack('Biometric Auth not Enabled...');
                              } else {
                                biometricLogin(
                                    context: context, mainCol: mainCol);
                              }

                            },

Here is the biometricLogin Function.

void biometricLogin({context, mainCol}) async {
bool authenticated =
    await checkBiometric(context: context, mainCol: mainCol);

if (authenticated == null || authenticated == false) {
  showSnack('BioAuth not valid...');
} else {
  bool isGoogle = preferences.getBool('googleSignIn');
  bool isApple = preferences.getBool('appleSignin');
  if (isGoogle) {
    showSnack('Logging in...');
    User user = await _auth.signInWIthGoogleCreds();
    print(user);
    if (user == null) {
      showSnack('Try logging in through Google again...');
    }
  } else if (isApple) {
    showSnack('Logging in...');
    User user = await _auth.signInWIthAppleCreds();
    print(user);
    if (user == null) {
      showSnack('Try logging in through Apple again...');
    }
  } else {
    User user;
    showSnack('Logging in...');
    var email = preferences.getString('email');
    var password = preferences.getString('pass');
    user = await _auth.signIn(email, password);
    if (user != null) {
      await preferences.setBool('loggedIn', true);
    } else {
      showSnack('Something went wrong');
    }
  }
}

}

And here is checkBiometrics function.

Future<bool> checkBiometric({context, mainCol}) async {
if (bioAuth == null || bioAuth == false) {
  showSnack('Biometrics not Enabled');
  return false;
} else {
  try {
    canCheckBiometrics = await auth.canCheckBiometrics;
    if (!mounted) return false;
    List<BiometricType> availableBiometrics;
    availableBiometrics = await auth.getAvailableBiometrics();
    bool authenticated = false;
    if (Platform.isIOS) {
      const iosStrings = const IOSAuthMessages(
          cancelButton: 'cancel',
          goToSettingsButton: 'settings',
          goToSettingsDescription: 'Please set up your Touch ID.',
          lockOut: 'Please re-enable your Touch ID');
      if (availableBiometrics.contains(BiometricType.face) ||
          availableBiometrics.contains(BiometricType.fingerprint)) {
        authenticated = await auth.authenticateWithBiometrics(
          localizedReason: "Please authenticate to login",
          useErrorDialogs: true,
          iOSAuthStrings: iosStrings,
          stickyAuth: true,
        );
      } else
        authenticated = false;
    } else {
      authenticated = await auth.authenticateWithBiometrics(
        localizedReason: 'Touch your finger on the sensor to login',
        useErrorDialogs: true,
        stickyAuth: true,
      );
    }
    return authenticated;
  } catch (e) {
    showSnack("error using biometric auth: $e");
  }
  setState(() {
    authenticated = authenticated ? true : false;
  });
  return authenticated;
}

}

As far as I understand. The app doesnot goes ahead of checkBiometrics, because it crashes just by pressing the button.

go to

android\app\proguard-rules.pro

add following line

-keep class androidx.lifecycle.DefaultLifecycleObserver

On Android, you can check only for the existence of fingerprint hardware prior to API 29 (Android Q). Therefore, if you would like to support other biometrics types (such as face scanning) and you want to support SDKs lower than Q, do not call getAvailableBiometrics. Simply call authenticate with biometricOnly: true. This will return an error if there was no hardware available.

check this out

If you receive this error: Exception has occurred. PlatformException (PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null)) Exception has occurred. PlatformException (PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null))

Then you need to do this:

  1. Go to android>app>src>main>res>values>style.xml
  2. Change the <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> to <style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM