Reputation: 3693
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))
}
}
Upvotes: 2
Views: 17414
Reputation: 91
I run flutter clean
and then, click to sync gradle again in Android Studio.
It worked to me
Upvotes: 2
Reputation: 369
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.
Upvotes: 2