No such module ‘flutterpluginregistrant’

When you encounter the error message “no such module ‘flutterpluginregistrant'” in Flutter, it indicates that the Flutter module ‘FlutterPluginRegistrant’ is not found or cannot be imported properly. This module is required to register any plugins used in your Flutter project.

To resolve this issue, you can follow the steps below:

  1. Make sure you have the necessary dependencies and their versions specified correctly in your project’s pubspec.yaml file. Check if the following dependencies are present:
            plugins:
              flutter_plugin_android_lifecycle: ^2.0.0
          
  2. Run flutter clean command in the terminal/command prompt to clean the build artifacts of your project.
  3. Then you can try running flutter pub get command to fetch and update the missing dependencies.
  4. If the error still persists, you might need to check if you have the required configurations in your project files. Ensure the following steps are done correctly:
    1. Make sure you have a valid MainApplication.java file in the android/app/src/main/java/your/package/name/ directory. This file should extend FlutterApplication and have the necessary import statements like:
                  import io.flutter.app.FlutterApplication;
                
    2. Verify that the MainApplication.java file overrides the onCreate() method and includes the required FlutterPluginRegistrant statement. Example:
                  package your.package.name;
      
                  import io.flutter.app.FlutterApplication;
                  import io.flutter.plugin.common.PluginRegistry;
                  import io.flutter.plugins.GeneratedPluginRegistrant;
                  import com.google.firebase.FirebaseApp;
                  import io.flutter.view.FlutterMain;
      
                  public class MainApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
                    @Override
                    public void onCreate() {
                      super.onCreate();
                      FlutterMain.startInitialization(this);
                      FirebaseApp.initializeApp(this);
                      GeneratedPluginRegistrant.registerWith(this);
                    }
      
                    @Override
                    public void registerWith(PluginRegistry registry) {
                      GeneratedPluginRegistrant.registerWith(registry);
                    }
                  }
                
  5. Finally, rebuild and run your project using the flutter run command to see if the error is resolved.

Same cateogry post

Leave a comment