问题描述
我最近遇到了这个问题。本地身份验证可以在 Flutter run 和 --release,--profile 上完美运行。但是当我制作APK然后安装它时,本地身份验证不起作用,应用程序崩溃。当我运行相同的应用程序但电缆连接到我的计算机时,应用程序中没有错误。
onpressed: () {
bool enable = preferences.getBool('bioAuth');
if (enable == null || enable == false) {
showSnack('Biometric Auth not Enabled...');
} else {
biometricLogin(
context: context,mainCol: mainCol);
}
},
这里是 biometricLogin 函数。
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 函数。
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',);
}
return authenticated;
} catch (e) {
showSnack("error using biometric auth: $e");
}
setState(() {
authenticated = authenticated ? true : false;
});
return authenticated;
}
}
据我所知。该应用程序不会领先于 checkBiometrics,因为只需按下按钮它就会崩溃。
解决方法
前往
android\app\proguard-rules.pro
添加以下行
-keep class androidx.lifecycle.DefaultLifecycleObserver