Flutter MissingPluginException(No implementation found for method getAll on channel ...) in release app

Viewed 13122

I got the MissingPlugin error. I found quite some posts about the error. But my case is a bit different. First, my project runs fine in simulator, the error only raises when I run my release app on physical Android. Second, this error is not just related to one package. I first got error like MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) After I put the code I found only to handle the issue with shared_preferences. I then got error like MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/package_info) Obviously the error is not just linked to one package like shared_preferences.

Any idea? how can I solve the problem?

4 Answers

This is a classic mistake that allot of people make. What you are trying to do is abstract heavy work to an isolate, however flutter isolates cannot run plugins, other than the api in flutter and the dart sdk directly.

You have a couple of options.

  1. There is a plugin I can recommend, it does not support all flutter (3rd party) plugins, but it's worth a try with yours. https://pub.dev/packages/flutter_isolate

This plugin creates isolates that auto marshal plugin work back to the main isolate, without risking a runtime exception that base flutter isolates will normally throw.

  1. Run only the source code of the heavy process, that you are allowed to run in a base flutter isolate, by only using the flutter & dart sdk apis directly. The rest of the code that depends on plugins, will need to be relayed back to the main isolate, and the UI will have to wait for a result using a FutureBuilder

Tried a few different solution found online, like clean and rebuild. no-shrink etc. None worked for me.

Finally in the build.gradle, I changed

classpath 'com.android.tools.build:gradle:4.0.0' to classpath 'com.android.tools.build:gradle:3.5.1'

after that, the apk size is 50% of the previous and the app loads fine.

So maybe something with the new build tool.

There's absent super.configureFlutterEngine(flutterEngine) on FlutterActivity.

class MainActivity : FlutterActivity() {    
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine) //missing this
     
    }
}

I had a same error on a old flutter app, Running on stable 3.0.2 without null safety. As a result I was using shared_preferences : ^5.4 which worked well in debug, but used to crash the plugin in release mode on Android

Adding

 minifyEnabled false
 shrinkResources false

to android/app/build.gradle fixed the issue

Related