簡體   English   中英

發布 apk flutter 中的本地身份驗證問題

[英]Local authentication problem in release apk flutter

我最近遇到了這個問題。 本地身份驗證可以在 flutter 運行和 --release, --profile 上完美運行。 但是當我制作 APK 然后安裝它時,本地身份驗證不起作用,應用程序崩潰。 當我運行相同的應用程序但將電纜連接到我的計算機時,應用程序中沒有錯誤。

在這里,function 調用開始,

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

                            },

這是生物識別登錄 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');
    }
  }
}

}

這里是 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;
}

}

據我所理解。 該應用程序不會在 checkBiometrics 之前運行,因為它只需按下按鈕就會崩潰。

go 至

android\app\proguard-rules.pro

添加以下行

-keep class androidx.lifecycle.DefaultLifecycleObserver

在 Android 上,您只能檢查 API 29 (Android Q) 之前是否存在指紋硬件。 因此,如果您想支持其他生物識別類型(例如面部掃描)並且希望支持低於 Q 的 SDK,請不要調用 getAvailableBiometrics。 只需使用 biometricOnly: true 調用身份驗證。 如果沒有可用的硬件,這將返回錯誤。

看一下這個

如果您收到此錯誤: 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))

然后你需要這樣做:

  1. Go 到android>app>src>main>res>values>style.xml
  2. <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