Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null)

Getting this error while using local_auth version 0.6.0 It's working fine for iOS but getting this error in android. Already have implemented class MainActivity: FlutterFragmentActivity() but still getting this issue

like image 409
Devansh Vyas Avatar asked Mar 11 '20 11:03

Devansh Vyas


3 Answers

This is what I did to solve this issue.

Change your MainActivity.kt as below:

package com.[your.package]

import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
    }
}

However, after changing this MainActivity.kt, I also faced some other issue with the Theme.AppCompat. Check this out https://gist.github.com/akifarhan/f70a2c777651f2ea61a15eb92a5939c1 for the solution.

like image 138
akifarhan Avatar answered Nov 19 '22 20:11

akifarhan


change your main activity to override FlutterFragmentActivity

import android.os.Bundle
import io.flutter.app.FlutterFragmentActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
   override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      GeneratedPluginRegistrant.registerWith(this)
  }
}

if you are using flutter embedding version 2

import androidx.annotation.NonNull
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
   override fun configureFlutterEngine(@NonNull flutterEngine: 
     FlutterEngine) {
     GeneratedPluginRegistrant.registerWith(flutterEngine)
   }
}
like image 4
Wisdom Ekeh Avatar answered Nov 19 '22 22:11

Wisdom Ekeh


Flutter details

Flutter version 1.22.4 at /Users/macbookpro/Desktop/development/flutter

  • Framework revision 1aafb3a8b9 (4 weeks ago), 2020-11-13 09:59:28 -0800
  • Engine revision 2c956a31c0
  • Dart version 2.10.4
  • local_auth: ^0.6.3+4

If you are using java then change your main activity to this

import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterFragmentActivity{
}
like image 3
Mehtab Avatar answered Nov 19 '22 20:11

Mehtab