When I start debugging the flutter project in Android Studio, shows error like this:
Launching lib/main_stable.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
.dart_tool/flutter_build/generated_main.dart:8:8: Error: Error when reading 'lib/main.dart': No such file or directory
import 'package:reddwarf_dict/main.dart' as entrypoint;
^
.dart_tool/flutter_build/generated_main.dart:72:18: Error: Getter not found: 'main'.
if (entrypoint.main is _UnaryFunction) {
^^^^
.dart_tool/flutter_build/generated_main.dart:73:17: Error: Getter not found: 'main'.
(entrypoint.main as _UnaryFunction)(args);
^^^^
.dart_tool/flutter_build/generated_main.dart:75:17: Error: Getter not found: 'main'.
(entrypoint.main as _NullaryFunction)();
^^^^
FAILURE: Build failed with an exception.
* Where:
Script '/Users/dolphin/apps/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1005
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/dolphin/apps/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 10s
Exception: Gradle task assembleDebug failed with exit code 1
And I check the debugging config. It did not treated the main.dart
as a entrypoint:
why did this happen and what should I do to fix it? This is the flutter environment info:
$ ~/apps/flutter/bin/flutter doctor ‹ruby-2.7.2›
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.2.3 20D91 darwin-x64, locale
en-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.2)
[✓] VS Code (version 1.62.2)
[✓] Connected device (3 available)
! Error: xiaoqiang 的 iPhone is not connected. Xcode will continue when
xiaoqiang 的 iPhone is connected. (code -13)
• No issues found!
CodePudding user response:
The flutter framework requires a main.dart file. Make a main.dart file and call the widget from ur main_stable.dart
import 'package:flutter/material.dart';
import ''; //import main_stable.dart here
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: GameScreen(), //replace this with the main widget from main_stable.dart, make sure it is a Scaffold(cause best practices exist)
);
}
}