无法创建Flutter项目:未指定输出目录选项错误。

4

我正在尝试创建一个新的Flutter项目。我尝试了以下两种方法:

1. flutter create

  1. flutter create --org com.domain.appname

它们都返回了以下内容:

No option specified for the output directory.
Create a new Flutter project.

If run on a project that already exists, this will repair the project,
recreating any files that are missing.

Global options:
-h, --help                  Print this usage information.
-v, --verbose               Noisy logging, including all shell commands
                            executed.
                            If used with "--help", shows hidden options. If used
                            with "flutter doctor", shows additional diagnostic
                            information. (Use "-vv" to force verbose logging in
                            those cases.)
-d, --device-id             Target device id or name (prefixes allowed).
    --version               Reports the version of this tool.
    --suppress-analytics    Suppress analytics reporting when this command runs.

Usage: flutter create <output directory>
-h, --help                   Print this usage information.
    --[no-]pub               Whether to run "flutter pub get" after the project
                             has been created.
                             (defaults to on)
    --[no-]offline           When "flutter pub get" is run by the create
                             command, this indicates whether to run it in
                             offline mode or not. In offline mode, it will need
                             to have all dependencies already available in the
                             pub cache to succeed.
    --[no-]overwrite         When performing operations, overwrite existing
                             files.
    --description            The description to use for your new Flutter
                             project. This string ends up in the pubspec.yaml
                             file.
                             (defaults to "A new Flutter project.")
    --org                    The organization responsible for your new Flutter
                             project, in reverse domain name notation. This
                             string is used in Java package names and as prefix
                             in the iOS bundle identifier.
                             (defaults to "com.example")
    --project-name           The project name for this new Flutter project. This
                             must be a valid dart package name.
-i, --ios-language           The language to use for iOS-specific code, either
                             ObjectiveC (legacy) or Swift (recommended).
                             [objc, swift (default)]
-a, --android-language       The language to use for Android-specific code,
                             either Java (legacy) or Kotlin (recommended).
                             [java, kotlin (default)]
    --platforms              The platforms supported by this project. Platform
                             folders (e.g. android/) will be generated in the
                             target project. This argument only works when
                             "--template" is set to app or plugin. When adding
                             platforms to a plugin project, the pubspec.yaml
                             will be updated with the requested platform. Adding
                             desktop platforms requires the corresponding
                             desktop config setting to be enabled.
                             [ios (default), android (default), windows
                             (default), linux (default), macos (default), web
                             (default)]
-t, --template=<type>        Specify the type of project to create.

          [app]              (default) Generate a Flutter application.
          [module]           Generate a project to add a Flutter module to an
                             existing Android or iOS application.
          [package]          Generate a shareable Flutter project containing
                             only Dart code.
          [plugin]           Generate a shareable Flutter project containing an
                             API in Dart code with a platform-specific
                             implementation for Android, for iOS code, or for
                             both.

-s, --sample=<id>            Specifies the Flutter code sample to use as the
                             "main.dart" for an application. Implies
                             "--template=app". The value should be the sample ID
                             of the desired sample from the API documentation
                             website (http://docs.flutter.dev/). An example can
                             be found at:
                             https://api.flutter.dev/flutter/widgets/SingleChild
                             ScrollView-class.html
    --list-samples=<path>    Specifies a JSON output file for a listing of
                             Flutter code samples that can be created with
                             "--sample".

Run "flutter help" to see global options.

以下是我的flutter doctor输出。
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-arm, locale
    en-LK)
[✓] 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 4.2)
[✓] VS Code (version 1.59.1)
[✓] Connected device (2 available)

• No issues found!

我使用的是MacBook Pro M1芯片的笔记本电脑,这有助于什么。
这里发生了什么?
3个回答

8

我觉得我很傻,提了一个简单的问题,可能是因为工作太久累了。无论如何,我犯了个错误,这里是答案。

flutter create --org com.domain appname

注意appnamecom.domain之间的空格。


3
你忘记添加输出目录了。你需要在--org调用之前放置它:

flutter create . --org....

"."代表当前目录,或者您可以使用以下方式指定路径:

C:/Users/...您的目录路径


抱歉,这也不起作用。它显示“指定了多个输出目录”。也许您可以发布完整的命令以确保无误? - PeakGen
此外,提及输出目录并不是我以前做过的事情,尽管我已经开发了许多Flutter应用程序。 - PeakGen
1
使用点号 . 来指定当前目录对我来说很有效 flutter create . --platforms=windows,macos,linux --org com.packagname尽管如此,我只能为 macos 添加支持;因为它是我当前的操作系统 - Amanda Shafack

0
尝试在终端中输入以下命令:flutter create --org com.domain appname。 当然,你可以将"appname"更改为你想要的文件名。

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