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

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?



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dan Gerchcovich
Solution 2 david weng
Solution 3 Michel_T.