[英]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))
然后你需要这样做:
android>app>src>main>res>values>style.xml
<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.