更改配置flutter build apk时,目标文件“lib/main.dart”未找到。

3

大家好,我想知道如何更改目标 Flutter 构建 apk,因为控制台上出现了“找不到目标文件”的错误:

(base) dendimuhmd@mbp-dendimuhmd makanyuk % flutter build apk --release            
Target file "lib/main.dart" not found.

文件夹结构


为什么不把你的 main.dart 文件移动到 lib 文件夹中呢? - Usama Karim
2个回答

2

您可以使用-t来更改目标。

应用程序在设备上运行的主要入口文件。 如果省略了“--target”选项,但在命令行上提供了文件名,则会使用该文件名。(默认为“lib\main.dart”)

针对您的情况

flutter build apk  -t .\lib\src\main.dart

非常感谢!!很好。 - dendi
在我的情况下,它的工作方式是这样的:flutter build apk -t lib\src\main.dart - Esmaeil Ahmadipour

0

您的main.dart文件位于lib/src文件夹中。为了正常工作,它需要在lib文件夹中。Flutter VS代码扩展网站的文档中提到了以下内容。

Flutter入口点应该在lib/main.dart启动配置

以下是网站上可能的配置。

"configurations": [
    {
        // A name for the launch config. This will show in the dropdown on the Run side bar.
        "name": "Current File (release mode)",

        // This should always be "dart" for Dart/Flutter apps.
        // This selects the Dart debugger.
        "type": "dart",

        // This can be "launch" to start an app, or "attach" to attach to an existing app.
        "request": "launch",

        // The directory to start running the app from.
        "cwd": "/foo/bar",

        // The entry script to execute when running the app.
        // Set to a "web" in a Dart web app to run in web move.
        // Set to "test" in an app with tests to run all tests.
        "program": "bin/main.dart",

        // Any custom environment variables to set when running the app with this
        // launch config.
        "env": {
            "RELEASE_MODE": true
        }

        // Arguments to be passed to the Dart or Flutter app.
        "args": [
            "--dart-define", "MY_VAR=foo"
        ],

        // "debugConsole" or "terminal". If set to "terminal", will run in the built-in
        // terminal and will support reading from `stdin`. However some other debug
        // features may be limited.
        "console": "debugConsole",

        // Set to run a Flutter app on a specific device, ignoring the device selected
        // in the status bar.
        "deviceId": "iphone",

        // "debug", "profile" or "release".
        "flutterMode": "debug",

        // Allows running Flutter tests on a real device instead of the default headless
        // flutter-tester device.
        "runTestsOnDevice": false,

        // If codeLens is defined, this launch configuration can be launched from custom
        // CodeLens links in the editor (see the page linked above for more info).
        "codeLens": {

            // This array sets where custom CodeLens links will be rendered:
            // - run-test: Above test functions as a Run link
            // - debug-test: Above test functions as a Debug link
            // - run-test-file: Above main functions in test files as a Run link
            // - debug-test-file: Above main functions in test files as a Debug link
            // - run-file: Above main functions in bin/tool/lib files as a Run link
            // - debug-file: Above main functions in bin/tool/lib files as a Debug link
            "for": [ "run-test", "run-test-file", "debug-test", "debug-test-file" ],

            // If specificed, the custom CodeLens will only appear for files that begin
            // with this path.
            "path": "test/integration_tests",

            // Text for the custom CodeLens. If not specified, will use the name field
            // from the parent launch configuration. The string "${debugType}" here will
            // be replaced with "run" or "debug" depending on the rendered position
            // (see the for field above).
            "title": "${debugType} (release)"
        },
    }
]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接