I've just built the local_auth sample and it works (vers. 0.6.3.4).
Here after the steps I've done:
create a new flutter app:
flutter create -a java -t app --project-name mywallet mywallet
Note, I'm using the java language.
- add the dependency to local_auth:
dependencies:
local_auth: ^0.6.3+4
copy the main.dart class from the:
local_auth page
modify the MainActivity.java in this manner:
MainActivity.java
package com.example.mywallet;
import android.os.Bundle;
import io.flutter.app.FlutterFragmentActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.os.Bundle;
import io.flutter.app.FlutterFragmentActivity;
import io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin;
import io.flutter.plugins.localauth.LocalAuthPlugin;
@SuppressWarnings("deprecation")
public class MainActivity extends FlutterFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FlutterAndroidLifecyclePlugin.registerWith(
registrarFor(
"io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin"));
LocalAuthPlugin.registerWith(registrarFor("io.flutter.plugins.localauth.LocalAuthPlugin"));
}
}
Then, modify the android manifest in order to allow the flutter fragment to start:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mywallet">
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<application android:name="io.flutter.app.FlutterApplication" android:label="local_auth_example" android:icon="@mipmap/ic_launcher">
<activity android:name="io.flutter.embedding.android.FlutterFragmentActivity"
android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat.Light"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
<meta-data android:name="flutterEmbedding" android:value="2"/>
</application>
</manifest>
Now, the app is working if you are building it in debug mode, unfortunately in release mode it will take the following exception:
E/AndroidRuntime(27487): FATAL EXCEPTION: main
E/AndroidRuntime(27487): Process: com.example.mywallet, PID: 27487
E/AndroidRuntime(27487): java.lang.IllegalAccessError: Interface androidx.lifecycle.b implemented by class io.flutter.plugins.localauth.AuthenticationHelper is inaccessible (declaration of 'io.flutter.plugins.localauth.AuthenticationHelper' appears in /data/app/com.example.mywallet-t-m1EbOiZo85yTCgTK9tWw==/base.apk)
E/AndroidRuntime(27487): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(Unknown Source:16)
E/AndroidRuntime(27487): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27487): at io.flutter.embedding.engine.h.g.a.a(Unknown Source:25)
E/AndroidRuntime(27487): at io.flutter.embedding.android.FlutterFragmentActivity.g(Unknown Source:0)
In order to avoid this issue, you can add the file:
proguard-rules.pro
in android/app/src with the following line:
-keep class androidx.lifecycle.DefaultLifecycleObserver
Now it works!
Here after my flutter doctor:
~/Projects/mywallet$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.25.0-5.0.pre.93, on Linux, locale it_IT.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc4)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 4.0)
[✓] IntelliJ IDEA Community Edition (version 2020.2)
[✓] VS Code (version 1.51.1)
[✓] Connected device (4 available)
• No issues found!
The simple app was tested on Samsung (with knox) in release mode and on the emulator :
~/Projects/mywallet$ flutter devices
4 connected devices:
SM A307FN (mobile) • RF8M9278QSF • android-arm64 • Android 10 (API 29)
Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
Linux (desktop) • linux • linux-x64 • Linux
Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88