在 ChromeOS 上安装和配置 Flutter 开发环境
系统要求
要在 Chromebook 上安装并运行 Flutter,你的设备必须在设置的 开发者 选项卡中启用内置的 Linux 环境。
所需的磁盘空间大小会根据你启用的目标平台而变化。我们建议你将 Linux 环境的磁盘大小从默认的 10GB 增大到 32GB 或更大,以容纳 Android Studio 和其他工具。
获取 Flutter SDK
-
安装 Flutter 所需的核心开发工具:
$ sudo apt install clang cmake ninja-build pkg-config libgtk-3-dev
这会下载用于编译 ChromeOS 应用所需的编译器工具链。
-
从 GitHub 的 Flutter repo 下载 Flutter,在你的主目录使用以下命令:
$ git clone https://github.com/flutter/flutter.git -b stable
-
将
flutter
工具添加到环境变量中:$ echo PATH="$PATH:`pwd`/flutter/bin" >> ~/.profile $ source ~/.profile
你现在已经准备好运行 Flutter 命令了!
运行 flutter doctor
运行以下命令以查看是否还有缺失的依赖需要安装,你需要安装这些依赖以完成设置(要看到详细输出,请添加 -v
标识):
$ flutter doctor
该命令将检查你的环境情况并显示汇报在命令行窗口中。 Dart SDK 已经绑在 Flutter 中了;你无需单独再安装 Dart。仔细检查你是否还有需要安装的东西,或者要执行的任务(在该文字中提示的)。
例如:
[-] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html
上面的部分描述了如何执行这些任务,并完成设置流程。
当你已经安装了全部缺失的依赖之后,请再次运行 flutter doctor
命令,以验证你是否是真的全部正确设置完毕了。
Configuring web app support
On ChromeOS, you do development work in a Linux container. However, the Chrome browser itself is part of the parent ChromeOS operating system, and Flutter doesn’t have a means to call it with the required parameters.
Track this issue at Issue 121462: Improve the web debugging experience on Chromebooks.
Instead, the best approach is to manually install a second copy of Chrome in the Linux container. You can do that with the following steps:
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb
Android 设置
安装 Android Studio
-
下载并安装 Android Studio。
-
启动 Android Studio,并前往 ‘Android Studio Setup Wizard’,这将会帮你安装最新版本的 Android SDK,Android SDK 命令行工具,以及 Android SDK 构建工具,等一系列你在构建 Android 应用时会需要用到的组件。
-
从欢迎对话框中,选择 More Actions -> SDK Manager。在 SDK 工具标签页中,选择 Android SDK Command-line Tools (latest) 来安装额外的必要工具。
-
同意 Android 许可协议(Android licenses)。
$ flutter doctor --android-licenses
Deploy to your Chromebook
To deploy apps directly to your Chromebook, you need to do the following:
- Enable ADB in Settings. Note that this requires you to reboot your device once.
- In the Terminal, run
flutter devices
. If prompted, authorize access to the Android container. Verify thatflutter devices
lists your ChromeOS device as a recognized device.
设置你的 Android 设备
在 Android 设备上运行或测试你的 Flutter 之前,需要确保 Android 设备运行在 4.1(API 级别 16)或者更高的版本。
-
在你的设备上启动开发者选项以及 USB 调试工具。详细步骤请查看 Android 文档。
-
通过 USB 数据线连接你的手机与电脑。在 Chromebook 上,你可能会看到 “USB device detected”(USB 设备已连接)的通知。如果你的 Android 设备上出现点击 “Connect to Linux”(连接到 Linux)的提示,请授权计算机访问你的设备。
-
在命令行运行
flutter devices
命令以验证 Flutter 能够识别你的 Android 设备连接。默认情况下,flutter 使用基于adb
工具的 Android SDK 版本。如果你想要 Flutter 运行并安装在不同的 Android SDK 中的话,你必须将ANDROID_SDK_ROOT
环境变量设置为该 SDK 的安装目录。
下一步
Set up your preferred editor.