当我开始在Android Studio中调试flutter项目时,显示如下错误:
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
我检查了调试配置。它没有将main.dart
视为入口点:
为什么会发生这种情况,我应该做些什么来修复它?这是颤振环境信息:
$ ~/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!
发布于 2021-11-20 10:44:02
颤动框架需要main.dart文件。创建一个main.dart文件并从您的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)
);
}
}
https://stackoverflow.com/questions/70045112
复制相似问题