當我開始在 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!
uj5u.com熱心網友回復:
Flutter 框架需要一個 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://www.uj5u.com/gongcheng/362203.html
