Repository navigation
Android - LocalAuth Plugin getEnrolledBiometrics throws when no Activity is available #174191
Copy link
Copy link
Closed
flutter/packages
#9981Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: local_authPlugin for local authentificationPlugin for local authentificationpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Description
What package does this bug report belong to?
local_auth
What target platforms are you seeing this bug on?
Android
Have you already upgraded your packages?
Yes
Dependency versions
pubspec.lock
local_auth:
dependency: transitive
description:
name: local_auth
sha256: "434d854cf478f17f12ab29a76a02b3067f86a63a6d6c4eb8fbfdcfe4879c1b7b"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
local_auth_android:
dependency: transitive
description:
name: local_auth_android
sha256: "316503f6772dea9c0c038bb7aac4f68ab00112d707d258c770f7fc3c250a2d88"
url: "https://pub.dev"
source: hosted
version: "1.0.51"
local_auth_darwin:
dependency: transitive
description:
name: local_auth_darwin
sha256: "0e9706a8543a4a2eee60346294d6a633dd7c3ee60fae6b752570457c4ff32055"
url: "https://pub.dev"
source: hosted
version: "1.6.0"
local_auth_platform_interface:
dependency: transitive
description:
name: local_auth_platform_interface
sha256: "1b842ff177a7068442eae093b64abe3592f816afd2a533c0ebcdbe40f9d2075a"
url: "https://pub.dev"
source: hosted
version: "1.0.10"
local_auth_windows:
dependency: transitive
description:
name: local_auth_windows
sha256: bc4e66a29b0fdf751aafbec923b5bed7ad6ed3614875d8151afe2578520b2ab5
url: "https://pub.dev"
source: hosted
version: "1.0.11"
Steps to reproduce
- Start a headless flutter engine
- Call
getEnrolledBiometrics - Throws Nullpointer when accessing Activity
Expected results
Returns some error code so that we can handle the error in case it's a headless flutter engine
Actual results
PlatformException: PlatformException(java.lang.NullPointerException: Attempt to invoke virtual method 'int androidx.biometric.BiometricManager.canAuthenticate(int)' on a null object reference, NullPointerException, Cause: null, Stacktrace: java.lang.NullPointerException: Attempt to invoke virtual method 'int androidx.biometric.BiometricManager.canAuthenticate(int)' on a null object reference
at io.flutter.plugins.localauth.LocalAuthPlugin.getEnrolledBiometrics(LocalAuthPlugin.java:86)
at io.flutter.plugins.localauth.Messages$LocalAuthApi.lambda$setUp$3(Messages.java:770)
at io.flutter.plugins.localauth.Messages$LocalAuthApi$$ExternalSyntheticLambda3.onMessage(D8$$SyntheticClass:0)
at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:261)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
Code sample
Code sample
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final auth = LocalAuthentication();
try {
final biometrics = await auth.getAvailableBiometrics();
print("Found $biometrics");
} catch (e) {
print("Error $e"); //never called, the app is terminated and crashes
}
}Screenshots or Videos
No response
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
~ > fvm flutter doctor -v
┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available! │
│ │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
[✓] Flutter (Channel stable, 3.29.3, on macOS 15.6 24G84 darwin-arm64, locale en-US) [2.8s]
• Flutter version 3.29.3 on channel stable at /Users/julianbissekkou/fvm/versions/3.29.3
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ea121f8859 (4 months ago), 2025-04-11 19:10:07 +0000
• Engine revision cf56914b32
• Dart version 3.7.2
• DevTools version 2.42.3
[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.5s]
• Android SDK at /Users/julianbissekkou/Library/Android/sdk
• Platform android-36, build-tools 35.0.0
• Java binary at: /Users/julianbissekkou/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [2.3s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16E140
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [114ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.3) [113ms]
• Android Studio at /Users/julianbissekkou/Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
[✓] IntelliJ IDEA Community Edition (version 2025.1.4.1) [111ms]
• IntelliJ at /Users/julianbissekkou/Applications/IntelliJ IDEA Community Edition.app
• Flutter plugin version 86.0.2
• Dart plugin version 251.27812.12
[✓] Network resources [1,219ms]
• All expected network resources are available.
! Doctor found issues in 1 category.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listp: local_authPlugin for local authentificationPlugin for local authentificationpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyAndroid applications specificallyteam-androidOwned by Android platform teamOwned by Android platform teamtriaged-androidTriaged by Android platform teamTriaged by Android platform team
Activity
stuartmorgan-g commentedon Aug 21, 2025
In the short term we should return an empty array, as that's consistent with the other handling of no activity in this plugin, but longer term we should have an exception for this when we fix #113687
[local_auth] Adopt structured errors, and remove `useErrorDialogs` (f…
github-actions commentedon Oct 30, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[local_auth] Adopt structured errors, and remove `useErrorDialogs` (f…