如何解决发布 apk flutter 中的本地认证问题
我最近遇到了这个问题。本地身份验证可以在 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。