Flutter Project: MainActivity.java is missing Flutter Project: MainActivity.java is missing flutter flutter

Flutter Project: MainActivity.java is missing


If you are here because you are following the steps for setting up firebase_messaging, you can look at this answer and just create the Application.kt file (instead of Java) next to your MainActivity.kt file. Here it is:

package com.example.yourappimport io.flutter.app.FlutterApplicationimport io.flutter.plugin.common.PluginRegistryimport io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallbackimport io.flutter.plugins.GeneratedPluginRegistrantimport io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingServiceclass Application : FlutterApplication(), PluginRegistrantCallback {    override fun onCreate() {        super.onCreate()        FlutterFirebaseMessagingService.setPluginRegistrant(this);    }    override fun registerWith(registry: PluginRegistry?) {        io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));    }}


flutter create -a java .

Try this command. with '.' at end. It represent current project directory.apply this command from project root folder.This command will try to recreate android project with java (this will setup your MainActiviy.java). It won't affect currently setup manifest or any other firebase related setup.


You can simply create the class file MainActivity.java with the Java code and delete the Kotlin one. It should work:

public class MainActivity extends FlutterActivity {  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    GeneratedPluginRegistrant.registerWith(this);  }}