'Flutter: Missing Plugin Exception Raised when running release builds of android app

Issue

I am currently working on an app which uses multiple packages.

The app works like a charm in both debug and profile modes. But when I get the release build and run it, some features do not work.

The reason is a couple of the plugins are not working as intended. This is what I get in the debug console :

E/flutter (14180): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
E/flutter (14180): 
E/flutter (14180): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

Another case during the same run

E/flutter (14180): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method getStorageDirectory on channel plugins.flutter.io/path_provider)
E/flutter (14180): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157)
E/flutter (14180): <asynchronous suspension>
E/flutter (14180): #1      getExternalStorageDirectory (package:path_provider/path_provider.dart:120)
E/flutter (14180): <asynchronous suspension>
E/flutter (14180): #2      ChatScreenState._init (package:pryzcrybdoctor/Screens/Chats/chat.dart:716)
E/flutter (14180): <asynchronous suspension>
E/flutter (14180): #3      ChatScreenState._prepare (package:pryzcrybdoctor/Screens/Chats/chat.dart:736)
E/flutter (14180): <asynchronous suspension>

I have not used path_provider in my app, it is a transitive dep from a plugin cached_network_image

I got the same exception with permission_handler plugin in this same app, but I removed it to check if permission handler was the issue, but now I can't access camera. The thing that gets me confused is that all these issues only arise in the release mode. Everything works perfectly in debug and release.

Some weird things I noticed...

It seems that some plugin or plugins are still using the "non AndroidX" support libraries. This is because I have to go through the "build debug then build profile and finally then release" cycle to get the release version built. I've read once that this is when Jetifier is working on some plugins that have not fully migrated. So my best guess is that the issue is with some plugin not fully migrated.

What I have tried so far..

  • Rebuilding the app multiple times.
  • flutter clean and then flutter build
  • flutter pub upgrade
  • Build using android studio.
  • Migrate to AndroidX using android studio.

Please let me know if you need more info or logs. Thank you for your time.



Solution 1:[1]

Got the solution to this issue from a Flutter GitHub issue.

Just keeping androidx.lifecycle.DefaultLifecycleObserver is enough.

Add the below line to app/proguard-rules.pro:

-keep class androidx.lifecycle.DefaultLifecycleObserver

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 Jeremy Caney