'Can't find main.dart as entrypoint, how to connect Android project to the main.dart file?

Please don't mark as a duplicate. I have tried to read this Flutter : Target file "lib/main.dart" not found but I have found no answer, because what I ask will be little different

so I have this error when I run my Flutter App through the Android project (from Android Studio), I mean for some reason I did not run the project through the Flutter project (not from VS Code). I have no issue If run my Flutter app through VS Code

this is the error

Error: Error when reading 'lib/main.dart': No such file or directory import 'package:mobile/main.dart' as entrypoint

so basically the Android Studio can't find the main.dart.

I implement Flavor on my Flutter, so I have several main functions such as main_production.dart, main_staging.dart and main_development.dart instead of normal main.dart . thats why the system can't find the entry point.

In iOS Xcode, I can set the main entry point through Flutter Target like this

enter image description here

but now I am confused, how to connect my Android project to the several main function (my dart files)



Solution 1:[1]

In android studio, open action menu with (cmd+shift+a on mac and ctrl+shift+a on windows/linux) and select Edit configurations

enter image description here

Then, using a plus sign at the top, add a new flutter run config

enter image description here

And specify an appropriate entrypoint and flavor:

enter image description here

All that's left is to run the new config using either of the green buttons at the top (run or debug)

enter image description here

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