简体   繁体   English

发布 apk flutter 中的本地身份验证问题

[英]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.本地身份验证可以在 flutter 运行和 --release, --profile 上完美运行。 But when I make the APK and then install it, the local auth does not work, the app crashes.但是当我制作 APK 然后安装它时,本地身份验证不起作用,应用程序崩溃。 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,在这里,function 调用开始,

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.这是生物识别登录 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.这里是 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.该应用程序不会在 checkBiometrics 之前运行,因为它只需按下按钮就会崩溃。

go to go 至

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).在 Android 上,您只能检查 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.因此,如果您想支持其他生物识别类型(例如面部扫描)并且希望支持低于 Q 的 SDK,请不要调用 getAvailableBiometrics。 Simply call authenticate with biometricOnly: true.只需使用 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)) 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 Go 到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"><style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">更改为<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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