首页 > 解决方案 > 停留在 Flutter Native Plugin 指南中的第 2b 步

问题描述

所以我正在尝试开始 Flutter Plugin 开发,但我被困在步骤 2b HERE上。

Android Studio 只是显示错误:

Cannot Import Project
The project file specified already exists.

我很确定我已按照说明进行操作:

  1. flutter create --org com.example --template=plugin hello
  2. cd hello/example; flutter build apk

这些步骤都可以正常工作,示例应用程序似乎已构建,然后我进入第 2b 步,Android Studio 显示上述错误。

颤振医生:

[✓] Flutter (Channel dev, 1.20.0-1.0.pre, on Mac OS X 10.13.6 17G13035, locale en-DK)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[!] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.46.1)
[✓] Connected device (1 available)

标签: flutterflutter-plugin

解决方案


简单地打开项目更容易,但要小心使用哪个文件夹。

在 Android Studio 中,在 File>Open 中导航到hello/example/android. 这将打开示例应用程序。gradle 完成同步后,您应该在左侧面板中同时看到示例应用程序(您不会更改)和插件代码(您将更改)。

安装 VS Code 后,请考虑使用它来编辑 Dart 代码。(在开发插件时,尝试将 Android Studio 用于 Dart 代码以及 Java/Kotlin 代码时,我会感到困惑。)在这种情况下,打开顶级文件夹 ( hello)。您需要对hello/lib/hello.dart(插件 API)和hello/example/lib/main.dart(使用 API 的 Flutter 示例应用程序)进行更改。


推荐阅读