2

My Activity class extends io.flutter.embedding.android.FlutterActivity so that I can override configureFlutterEngine. When I do so and use sqflite, I get following exception

E/flutter (13585): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)

If switch to io.flutter.app.FlutterActivity, I get no exception, but then I cannot use platform channels that I do in configureFlutterEngine.

I also tried registering through ShimPluginRegistry and get exception as well

D/FlutterActivityAndFragmentDelegate(15175): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(15175): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
W/FlutterEngine(15175): Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@fb01f2a) but could not find and invoke the GeneratedPluginRegistrant.
D/FlutterActivityAndFragmentDelegate(15175): Attaching FlutterEngine to the Activity that owns this Fragment.

This is my Activity class

import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry

class MainActivity: FlutterActivity() {
   override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
         super.configureFlutterEngine(flutterEngine)
         GeneratedPluginRegistrant.registerWith(ShimPluginRegistry(flutterEngine))
     }
}
2
  • Did you try cold restarting your app? Commented Mar 24, 2020 at 21:00
  • Yes, restarted computer, tried different emulator, same thing Commented Mar 24, 2020 at 21:01

2 Answers 2

3

I run flutter clean and then, click to sync gradle again in Android Studio. It worked to me

Sign up to request clarification or add additional context in comments.

Comments

2

First check that the file android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java is available. If it is not created run flutter clean and reinstall your sqflite plugin.

If GeneratedPluginRegistrant.java is created open and check sqflite is added to the plugin list.

flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());

Then import GeneratedPluginRegistrant.registerWith(flutterEngine) at the MainActivity. Implement it at the start of the configureFlutterEngine() function and it works perfectly.

import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity : FlutterActivity() {

    private val CHANNEL = "getEpubs"
    var _eventSink: EventChannel.EventSink? = null

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
        //your event channel calls goes below
}

This registers the generated sqflite plugin access to the database on the device.

(Sorry for the Kotlin code, but you can change it to Java.)

Don't forget to import: io.flutter.plugins.GeneratedPluginRegistrant in your MainActivity.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.