前阵子动手配置了Flutter的开发环境,把搭建过程记录了下来,比较简单,希望对新手有帮助。
搭建步骤如下(已具备Android Studio的开发环境):
1、 在Android Studio中先下载安装好Flutter和Dart的插件,然后下载Flutter的SDK。
推荐去官网下载,速度并不慢,网址:https://flutter.io/setup-macos/
2、解压zip,放在你需要放的路径下就行,配置环境变量时需要该路径。同时在AS中打开Preferences,搜索Dart和Flutter,配置好Dart SDK的路径,在解压的flutter/bin/cache/dart-sdk中。
升级flutter sdk版本:下载mac os最新版本,解压,修改环境变量并更换,同上2的步骤。
遇到警告:
Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options.
JoJodeMBP:flutter_app zhoujuan$ flutter packages upgrade
Warning! The 'flutter' tool you are currently running is from a different Flutter repository than the one last used by this package. The repository from which the 'flutter' tool is currently
executing will be used instead.
running Flutter tool: /Users/zhoujuan/AndroidDevelop/flutter-enviroment/flutter
previous reference : /Users/zhoujuan/Downloads/Android-develop/flutter
This can happen when you have multiple copies of flutter installed. Please check your system path to verify that you are running the expected version (run 'flutter --version' to see which
flutter is on your path).
解决:flutter packages upgrade 更新一下即可。注意更新前需要先运行which flutter查看flutter path路径是否正确,运行flutter --version 查看当前使用版本是否正确。
3、在终端打开open -e .bash_profile ,配置环境变量:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=${PATH}:解压后的flutter的路径/flutter/bin:$PATH
更换环境变量:
source .bash_profile 或者 . ~/.bash_profile
4、运行 flutter doctor,查看是否需要安装其它依赖项来完成安装:具体可以参考官网:https://flutterchina.club/setup-macos/
该命令检查您的环境并在终端窗口中显示报告。Dart SDK已经在捆绑在Flutter里了,没有必要单独安装Dart。 仔细检查命令行输出以获取可能需要安装的其他软件或进一步需要执行的任务(以粗体显示)
按照上面提示,安装相关缺少的其他软件:
我做了下面的操作:
(1)运行 flutter doctor --android-licenses ,一路选择yes即可
(2)Android Studio中安装flutter插件,重启Android Studio。
再运行 flutter doctor检测如下,ios相关的东西,不安装也可以新建flutter项目了,同时可以在Android设备和iphone模拟器上跑。
(3)下面是处理ios相关的命令时的操作,过程中会报很多Error。解决办法:HomeBrew 安装工具遇到的权限相关的问题、CocoaPods安装流程与使用
简单点说就是卸载了HomeBrew,然后重新安装,就可以执行相关的brew命令了。
在终端执行卸载命令:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
然后执行安装命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
上述操作可能还会报下面的错误,可参考homerew安装Connection refused即可解决。
curl: (7) Failed to connect to raw.githubusercontent.com port 443:Connection refused
! Doctor found issues in 1 category.
JoJodeMacBook-Pro:~ zhoujuan$ brew install --HEAD libimobiledevice
Error: Another active Homebrew update process is already in progress.
Please wait for it to finish or terminate it to continue.
==> Installing dependencies for libimobiledevice: autoconf, automake, libtool, pkg-config, sphinx-doc, gdbm, openssl, readline, sqlite, python@2, libxml2, libplist, libtasn1, libusb and usbmuxd
==> Installing libimobiledevice dependency: autoconf
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.mojave.bottle.4.tar.gz
######################################################################## 100.0%
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
==> Downloading https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
######################################################################## 100.0%
Error: An exception occurred within a child process:
Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar
JoJodeMacBook-Pro:~ zhoujuan$ brew install ideviceinstaller
Error: Another active Homebrew update process is already in progress.
Please wait for it to finish or terminate it to continue.
==> Installing dependencies for ideviceinstaller: libplist, libtasn1, openssl, libusb, usbmuxd, libimobiledevice and libzip
==> Installing ideviceinstaller dependency: libplist
==> Downloading https://homebrew.bintray.com/bottles/libplist-2.0.0.mojave.bottle.tar.gz
######################################################################## 100.0%
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
==> Installing dependencies for libplist: pkg-config, sphinx-doc, gdbm, openssl, readline, sqlite, python@2 and cython
==> Installing libplist dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.mojave.bottle.tar.gz
######################################################################## 100.0%
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
######################################################################## 100.0%
Error: An exception occurred within a child process:
Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar
JoJodeMacBook-Pro:~ zhoujuan$ brew install ios-deploy
Error: Another active Homebrew update process is already in progress.
Please wait for it to finish or terminate it to continue.
==> Downloading https://homebrew.bintray.com/bottles/ios-deploy-1.9.3.mojave.bottle.tar.gz
######################################################################## 100.0%
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
==> Downloading https://github.com/ios-control/ios-deploy/archive/1.9.3.tar.gz
==> Downloading from https://codeload.github.com/ios-control/ios-deploy/tar.gz/1.9.3
######################################################################## 100.0%
==> Downloading https://github.com/ios-control/ios-deploy/commit/9b23447e.diff?full_index=1
######################################################################## 100.0%
==> Patching
==> Applying 9b23447e.diff
patching file ios-deploy.xcodeproj/project.pbxproj
Error: An exception occurred within a child process:
Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar
JoJodeMacBook-Pro:~ zhoujuan$ brew install cocoapods
Error: Another active Homebrew update process is already in progress.
Please wait for it to finish or terminate it to continue.
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.5.3.mojave.bottle.tar.gz
######################################################################## 100.0%
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
==> Downloading https://github.com/CocoaPods/CocoaPods/archive/1.5.3.tar.gz
==> Downloading from https://codeload.github.com/CocoaPods/CocoaPods/tar.gz/1.5.3
######################################################################## 100.0%pod setup
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
######################################################################## 100.0%
Error: An exception occurred within a child process:
Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar
安装过程中遇到的问题,基本就是输入flutter doctor检查时,缺少安装的一些软件,安装错误提示,输入对应的命令行安装即可,如果安装失败什么的,自行百度基本都能解决,下面贴出部分本人安装时的命令行执行过程:
Last login: Thu May 30 15:32:08 on ttys000
JoJodeMacBook-Pro:~ zhoujuan$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E226, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
✗ libimobiledevice and ideviceinstaller are not installed. To install with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[✓] Android Studio (version 3.0)
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
JoJodeMacBook-Pro:~ zhoujuan$ brew update
Already up-to-date.
JoJodeMacBook-Pro:~ zhoujuan$ brew install --HEAD usbmuxd
Warning: usbmuxd HEAD-60109fd_1 is already installed and up-to-date
To reinstall HEAD_1, run `brew reinstall usbmuxd`
JoJodeMacBook-Pro:~ zhoujuan$ brew link usbmuxd
Warning: Already linked: /usr/local/Cellar/usbmuxd/HEAD-60109fd_1
To relink: brew unlink usbmuxd && brew link usbmuxd
JoJodeMacBook-Pro:~ zhoujuan$ brew install --HEAD libimobiledevice
Updating Homebrew...
==> Cloning https://git.libimobiledevice.org/libimobiledevice.git
Updating /Users/zhoujuan/Library/Caches/Homebrew/libimobiledevice--git
==> Checking out branch master
Already on 'master'
Your branch is up to date with 'origin/master'.
HEAD is now at 4727a86 common: Update socket.c to match the one from libusbmuxd
==> ./autogen.sh
==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/libimobiledevi
==> make install
/usr/local/Cellar/libimobiledevice/HEAD-4727a86_3: 67 files, 1MB, built in 56 seconds
Removing: /Users/zhoujuan/Library/Caches/Homebrew/libimobiledevice--1.2.0_3.mojave.bottle.tar.gz... (279.8KB)
JoJodeMacBook-Pro:~ zhoujuan$ brew install ideviceinstaller
Updating Homebrew...
Warning: ideviceinstaller 1.1.0_4 is already installed and up-to-date
To reinstall 1.1.0_4, run `brew reinstall ideviceinstaller`
JoJodeMacBook-Pro:~ zhoujuan$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E226, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
[✓] Android Studio (version 3.0)
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
JoJodeMacBook-Pro:~ zhoujuan$
都安装成功后的截图:
安装完成后就可以打开Android Studio新建Flutter工程了,可以跨平台运行在Android设备和ios模拟器中: