3

My project , uses kotlin and when I want to use Local_auth plugin , I get the error below:

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

what the example of local_auth says , is:

package io.flutter.plugins.localauthexample;

import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.localauth.LocalAuthPlugin;

public class MainActivity extends FlutterFragmentActivity {
  // TODO(bparrishMines): Remove this once v2 of GeneratedPluginRegistrant rolls to stable. https://github.com/flutter/flutter/issues/42694
  @Override
  public void configureFlutterEngine(FlutterEngine flutterEngine) {
    flutterEngine.getPlugins().add(new LocalAuthPlugin());
  }
}

and

package io.flutter.plugins.localauthexample;

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

public class EmbeddingV1Activity extends FlutterFragmentActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GeneratedPluginRegistrant.registerWith(this);
  }
}

but the problem is that I don't know kotlin and I don't know how to create my kotlin file.

also , I guess (I am not sure) that , it can be a bug of flutter in its new release.

4 Answers4

10

Change the MainActivity.kt file's code to this

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

class MainActivity: FlutterFragmentActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }
}
anymeshsingh
  • 261
  • 1
  • 11
7

Open MainActivity.kt and change 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);
    }
}

For more information, check out:

https://gist.github.com/akifarhan/f70a2c777651f2ea61a15eb92a5939c1

akifarhan
  • 1,101
  • 10
  • 26
2

I fixed mine by changing FlutterActivity to FlutterFragmentActivity in:

/android/app/src/main/kotlin/../MainActivity.kt
Boken
  • 4,825
  • 10
  • 32
  • 42
Deimos
  • 21
  • 2
  • I am getting build error "'configureFlutterEngine' overrides nothing" FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details I am unable to find Gradle log file location. So, can't attach here. – Plasmatiger Jul 02 '20 at 12:19
0

Open MainActivity.kt and replace all FlutterActivity by FlutterFragmentActivity.

Refer: Android Integration

Pasindu Jayanath
  • 892
  • 10
  • 27