When I perform a flutter run I get an error
Target file "lib/main.dart" not found.
Why is this happening and how can I fix this ?
Once you have created your project, you will see the “lib” folder where the “main. dart” file is located. Most importantly, once you have created a project and developed the application, Flutter expects the “main. dart” file to exist.
2- The first Dart example with Android Studio First, create the MyFirstDartProject folder. Secondly, on Android Studio, open the folder you have just created. Then create a new file: File > New > File > MyFirstDart.
To compile in release mode, we just need to add the --release flag to the flutter run command and have a physical device connected. Although we can do so, we typically do not use the flutter run command with the --release flag.
You can run any file from any DIR provided that you set the target file path, example:
flutter run -t lib/main_dev.dart
OR
flutter run lib/dev/main_dev.dart
UPDATE (2020 February 5th)
It is however not advisable to remove main.dart from your project.
I'm sure most of you found this link because you are setting up / configuring your app to accommodate for different environments e.g. dev, stg, beta and prod.
Example:
main_dev.dart:
void main() async { dynamic configuredApp = AppConfig( appName: 'Flutter', flavorName: 'development', appVersion: 1.0, apiBaseUrl: 'https://dev-api.example.com/' ); runApp(App(configuredApp)); }
main.dart
class App extends StatefulWidget { final dynamic configuredApp; App(this.configuredApp); @override _AppState createState() => _AppState(); }
As it turns out some build steps will fail in Android Studio mostly Gradle related if you don't have a main.dart file and method main() {} referenced inside this file.
More info / solutions below related to flutter build error: finished with non-zero exit value 1
An alternative to flutter run -t lib/main_dev.dart
in VS Code with the debugger tool.
.vscode/launch.json
"configurations": [ { "name": "Flutter", "request": "launch", "type": "dart", // "args": ["--enable-software-rendering"] // "flutterMode": "profile", //debug //release "program": "${workspaceFolder}/lib/main_dev.dart" } ]
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With