开发环境搭建
这是我的系统配置参数:
参数名 | 参数值 |
---|---|
OS | Mac 10.13 |
Flutter
开发环境用于开发(废话),它是由4个部分组成的。java
环境, android studio
的环境,xcode
编辑器和flutter
的SDK
。
首先开发flutter
当然需要flutter
的官方SDK
才能配置flutter
环境。但flutter
代码的开发和调试需要android
或ios
的模拟器或真机,这个
直接调试的能力或真机或模拟都是由android studio
或xcode
提供支持的。而androi studio
是又是依赖于java
。
综上。凑齐flutter
的SDK
, java
, android studio
和xcode
,开发环境就成了。
先安装flutter
的SDK
这是下载穿梭门,根据自己的情况下载自己系统对应的版本。下载后直接解压并打开。打开后的目录
下载的版本是flutter_macos_2.2.1-stable
大概是这样的:
.
├── AUTHORS
├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── PATENT_GRANT
├── README.md
├── SECURITY.md
├── analysis_options.yaml
├── bin
│ ├── cache
│ ├── dart
│ ├── dart.bat
│ ├── flutter
│ ├── flutter.bat
│ └── internal
├── dartdoc_options.yaml
├── dev
...
见着没?在bin
目录下在flutter
和dart
这2个文件就是flutter
和dart
的启动文件了。只要把这个目录加入环境变量中,让flutter
和dart
这个2个启动文件能直接在命令行中直接这一步就算完成了。类unix
的系统比如mac
或linux
,则
使用的是bash
则在~/.bashrc
中加入,如:
$ echo PATH=$PAHT:flutter目录/bin >> ~/.bashrc // 使用的是bash则,环境变量加入个人配置文件名为.bashrc
$ source ~/.bahsrc // 重新加载个人配置使新的环境变量生效
// 或zsh的则
$ echo PATH=$PAHT:flutter目录/bin >> ~/.zshrc // 使用的是zsh则,环境变量加入个人配置文件名为.zshrc
$ source ~/.zshrc // 重新加载个人配置使新的环境变量生效
最后在命令行中输入flutter
,出现以下输出:
$ flutter
Manage your Flutter app development.
Common commands:
flutter create <output directory>
Create a new Flutter project in the specified directory.
flutter run [options]
Run your Flutter application on an attached device or in an emulator.
Usage: flutter <command> [arguments]
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.
Available commands:
analyze Analyze the project's Dart code.
assemble Assemble and build Flutter resources.
attach Attach to a running app.
bash-completion Output command line shell completion setup scripts.
build Build an executable app or install bundle.
channel List or switch Flutter channels.
clean Delete the build/ and .dart_tool/ directories.
config Configure Flutter settings.
create Create a new Flutter project.
devices List all connected devices.
doctor Show information about the installed tooling.
downgrade Downgrade Flutter to the last active version for the current channel.
drive Run integration tests for the project on an attached device or emulator.
emulators List, launch and create emulators.
format Format one or more Dart files.
gen-l10n Generate localizations for the current project.
install Install a Flutter app on an attached device.
logs Show log output for running Flutter apps.
precache Populate the Flutter tool's cache of binary artifacts.
pub Commands for managing Flutter packages.
run Run your Flutter app on an attached device.
screenshot Take a screenshot from a connected device.
symbolize Symbolize a stack trace from an AOT-compiled Flutter app.
test Run Flutter unit tests for the current project.
upgrade Upgrade your copy of Flutter.
Run "flutter help <command>" for more information about a command.
Run "flutter help -v" for verbose help output, including less commonly used options.
这样flutter
的SDK
安装的这一步就算完成了。 下一步接着安装java
和android studio
安装java
SDK 和 android statio
为什么要安装这个呢?flutter
在android
环境下调试需要android stutio
而它又依赖java
的jDK,所以2个都要安装.
java下载穿越门
android stutio 下载穿越门
安装完后呢,如果要把android studio
作为编辑器来用,还要安装下flutter
插件; 在 perference > pluging
搜索flutter
并安装。
回头打开新的终端,输入:
$ java // 有相关提示说明java开发环境可以了
Usage: java [options] <mainclass> [args...]
(to execute a class)
or java [options] -jar <jarfile> [args...]
(to execute a jar file)
or java [options] -m <module>[/<mainclass>] [args...]
java [options] --module <module>[/<mainclas
...
$ flutter doctor // 检验flutter 是否能正常工作
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on Mac OS X 10.13.6 17G14033 darwin-x64, locale en-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✗] 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
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
以上的提示说明了flutter
的android
的开发环境完成了。而xcode
就是flutter
的ios
开发调试环境还需要安装xcode
才行。
安装flutter
的xcode
开发环境
这个很简单,直接在商店搜索xcode
安装就行