I've been using a handful of flutter plugins recently. Many worked perfectly, but I stumbled across frustrating errors several times, generally resulting in giving up the plugins.
Here is the last one I got, with schedule_notifications :
E/flutter (24758): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (24758): MissingPluginException(No implementation found for method getIconResourceId on channel schedule_notifications_app)
E/flutter (24758): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:278:7)
E/flutter (24758): <asynchronous suspension>
E/flutter (24758): #1 _MyAppState._getIconResourceId (<my path>/sandbox/lib/main.dart:67:40)
E/flutter (24758): <asynchronous suspension>
E/flutter (24758): #2 _MyAppState.initState (<my path>/sandbox/lib/main.dart:24:7)
E/flutter (24758): #3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3751:58)
E/flutter (24758): #4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5)
E/flutter (24758): #5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14)
E/flutter (24758): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12)
E/flutter (24758): #7 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:857:16)
E/flutter (24758): #8 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:828:5)
E/flutter (24758): #9 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:774:17)
E/flutter (24758): #10 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2222:19)
E/flutter (24758): #11 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:773:13)
E/flutter (24758): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:662:7)
E/flutter (24758): #13 runApp (package:flutter/src/widgets/binding.dart:704:7)
E/flutter (24758): #14 main (<my path>/sandbox/lib/main.dart:8:16)
E/flutter (24758): #15 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
E/flutter (24758): #16 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
D/libGLESv2(24758): DTS_GLAPI : DTS is not allowed for Package : <my package>
D/libGLESv1(24758): DTS_GLAPI : DTS is not allowed for Package : <my package>
D/ViewRootImpl(24758): ViewPostImeInputStage processPointer 0
D/ViewRootImpl(24758): ViewPostImeInputStage processPointer 1
There are many examples of similar questions on SO and GitHub (see the end of my post), but the only thing ever suggested to fix them is "use flutter clean
, flutter upgrade
, flutter packages get
and then flutter run
". Sometimes it may be enough, but not always - in my particular case, I still get the exact same error.
Noticeably, if I clone the whole GitHub repository of the plugin and run the example from within this directory, it does work well. But if I try to re-create the example project, it does not, so I take it I'm missing something, but what ?
Here are the steps I followed to re-create the example :
Create a new Flutter project in Android Studio
Add the dependency schedule_notifications: ^0.1.8 in pubspec.yaml
Click on the Flutter commands Packages get
and Packages upgrade
in Android Studio
Click on the popup Get packages
in Android Studio when it appeared
Paste the code from https://github.com/serralvo/schedule_notifications/blob/master/example/lib/main.dart in my main.dart
file
Change the line import 'package:schedule_notifications_example/time_picker.dart';
into import 'time_picker.dart';
to resolve the error I got from Android Studio
Create a file time_picker.dart
next to main.dart
and paste in it the code from https://github.com/serralvo/schedule_notifications/blob/master/example/lib/time_picker.dart
Execute the project in Android Studio and get the aforementioned error
Launch the Flutter console and go in the directory of my project
Execute the commands flutter clean
, flutter upgrade
, flutter packages get
in the console
Execute the command flutter run
in the console and still get the same error
So, what is going on exactly ? What could produce this behavior with some plugins, for some developers or some projects ? What am I doing wrong ?
Examples of similar questions :
MissingPluginException(No implementation found for method init on channel plugins.flutter.io/google_sign_in)
Flutter: google_sign_in plugin MissingPluginException
MissingPluginException while using plugin for flutter
Flutter Test MissingPluginException
Flutter MissingPluginException error
Flutter: Unhandled exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
https://github.com/flutter/flutter/issues/10912
After spending 12 hrs of a continuous effort to solve this in a flutter android project... finally solved - inspired by "@rahulserver" solution as follows
Just merge the following code in "MainActivity.java"
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this.getFlutterEngine());
}
Note: The MainActivity extends FlutterActivity
I fixed this by modifying the Android build a little.
android/app/build.gradle
android {
// other config stuff here
buildTypes {
release {
signingConfig signingConfigs.release
// Add these 2 lines
minifyEnabled false
shrinkResources false
}
}
}
I think this prevents some build optimisations, which break the plugin registration somehow...
In my case, I had removed this line(by mistake) from MainActivity.kt
(inside the onCreate
hook)
GeneratedPluginRegistrant.registerWith(this)
Probably a mistake, but cost me a lot of time. Hope helps someone.
When you add new plugin, you need to re-build the application, the hot re-start doesn't build the application and your newly added is not included in your project unless built again.
Alright, I'm posting what I found in case it could help somebody in the future. But I'm still interested in further explanations.
So, to make the schedule_notifications plugin work, I had to open the file MainActivity.java
in the example project. There, I noticed some lines which were not present in my own project :
MethodChannel methodChannel = new MethodChannel(getFlutterView(), "schedule_notifications_app");
methodChannel.setMethodCallHandler(new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("getIconResourceId")) {
result.success(R.mipmap.ic_launcher);
}
}
});
When I copied and pasted those lines in my own MainActivity.java
file (with the right imports), my project finally worked.
You'll notice that in main.dart
, we have these lines :
static const _platform = const MethodChannel('schedule_notifications_app');
and
iconResourceId = await _platform.invokeMethod('getIconResourceId');
Those are linked to the new lines in MainActivity.java
. That's where the issue came from.
Performing those steps result in making the plugins work, but I'm unsure if it is good or awful practice. And in case it really is what we are supposed to do, I must say it is quite not obvious ! I think that at least the plugins installation docs should explain it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With