经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » iOS » 查看文章
MAC安装Flutter
来源:cnblogs  作者:墨隐于非  时间:2019/9/27 13:02:31  对本文有异议

系统环境要求

Flutter因为是新出的框架,所以对系统还是有一定的要求的。

  • MacOS(64-bit)
  • 磁盘空间:大于700M,如果算上Android Studio等编辑工具,尽量大于3G。
  • 命令号工具:bash、mkdir、rm、git、curl、unzip、which、brew 这些命令在都可以使用。

下载Flutter SDK包

官网链接:https://flutter.io/setup-macos/

直接在 Get the Flutter SDK 中下载当前最新的SDK

配置环境变量

压缩包下载好以后,找个位置进行解压。这个位置很重要,因为下面配置环境变量的时候要用到。我配置到了当前用户目录文件夹。

  1. 打开终端工具,使用vim进行配置环境变量,命令如下:
  1. vim ~/.bash_profile
  1. 在打开的文件中增加一行代码
  1. export PATH=/Users/用户名/flutter/bin:$PATH

提示:这行命令你要根据你把压缩包解压的位置来进行编写,写的是你的路径,很有可能不跟文章一样。

  1. 配置文件完成后,使用 source 命令重新加载一下,具体命令如下:
  1. source ~/.bash_profile
  1. 使用命令检查是否安装成功,具体命令如下:
  1. flutter -h

出现flutter可用命令提示后,表示安装成功。

检查开发环境

我们安装好了Flutter,但是还不具备开发环境。开发还需要很多软件和插件的支持,那到底需要哪些插件和软件那?我们可以使用Flutter为我们提供的命令来进行检查:

  1. flutter doctor

显示结果:

  1. [?] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
  2. [?] Android toolchain - develop for Android devices
  3. ? Unable to locate Android SDK.
  4. Install Android Studio from: https://developer.android.com/studio/index.html
  5. On first launch it will assist you in installing the Android SDK components.
  6. (or visit https://flutter.io/setup/#android-setup for detailed instructions).
  7. If Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
  8. You may also want to add it to your PATH environment variable.
  9. [!] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
  10. ? libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
  11. brew update
  12. brew install --HEAD usbmuxd
  13. brew link usbmuxd
  14. brew install --HEAD libimobiledevice
  15. brew install ideviceinstaller
  16. ? ios-deploy not installed. To install:
  17. brew install ios-deploy
  18. [!] Android Studio (not installed)
  19. [!] VS Code (version 1.36.1)
  20. ? Flutter extension not installed; install from
  21. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
  22. [!] Connected device
  23. ! No devices available

注意:带?的就必须安装,带??的就可以暂时忽略。
VS Code是我之前就安装的,如果没有安装是不会出现下面这个带?信息的

  1. [!] VS Code (version 1.36.1)
  2. ? Flutter extension not installed; install from
  3. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

所以,这个暂时可以先忽略

解决带?的问题

1、Android环境

1.1 安装 Android Studio

打开 Android Studio, 打开 plugins ,安装 flutter

完成后

  1. [?] Android toolchain - develop for Android devices
  2. ? Unable to locate Android SDK.
  3. Install Android Studio from: https://developer.android.com/studio/index.html
  4. On first launch it will assist you in installing the Android SDK components.
  5. (or visit https://flutter.io/setup/#android-setup for detailed instructions).
  6. If Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
  7. You may also want to add it to your PATH environment variable.
  8. .
  9. .
  10. .
  11. [!] Android Studio (not installed)

转变为

  1. [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
  2. ? Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
  3. .
  4. .
  5. .
  6. [?] Android Studio (version 3.4)
1.2 执行 flutter doctor --android-licenses同意相关协议

此处 N 多信息,都是相关协议文件,一路 y 即可。

  1. .
  2. .
  3. .此处 N 多信息,都是相关协议文件,一路 y 即可。
  4. .
  5. .
  6. ---------------------------------------
  7. Accept? (y/N): y
  8. All SDK package licenses accepted

完成后

  1. [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
  2. ? Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

转变为

  1. [?] Android toolchain - develop for Android devices (Android SDK version 28.0.3)

2、iOS环境

  1. [!] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
  2. ? libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
  3. brew update
  4. brew install --HEAD usbmuxd
  5. brew link usbmuxd
  6. brew install --HEAD libimobiledevice
  7. brew install ideviceinstaller
  8. ? ios-deploy not installed. To install:
  9. brew install ios-deploy

在安装iOS环境时,就碰到一些坑

2.1 坑1:/usr/local is not writable.

看到这个提示,我们第一时间就是想着修改读写权限

当你执行sudo chown -R $(whoami) /usr/local进行修改时,系统会有如下提示:

  1. Operation not permitted

现在问题就卡住了,因为执行brew update之类的命令,需要对/usr/local进行写入操作。但是操作用户无法像对普通文件夹操作一样,通过chown获得write权限。由于/usr/local是系统文件夹,macOS限制了对其的操作权限。

苹果从 OS X El Capitan 10.11 系统开始使用了 Rootless 机制,可以将该机制理解为一个更高等级的系统的内核保护措施,系统默认将会锁定 /system/sbin/usr 这三个目录。

在终端输入

  1. csrutil status

收到系统提示

  1. System Integrity Protection statusenabled

说明rootless默认打开,此时无法通过sudo命令,对/system/sbin/usr 这三个目录进行修改。

打开、关闭Rootless机制
  • 重启Mac
  • 开机时后按下 Command+R,进入恢复模式。
  • 在上面的菜单实用工具中找到并打开 Terminal
  • 输入如下命令:
  1. csrutil disable

此时rootless已经关闭,退出恢复模式,正常进入系统。在终端输入

  1. csrutil status

系统提示

  1. System Integrity Protection statusdisabled

rootless已关闭
可通过 sudo chown -R $(whoami) /usr/local 进行权限修改
开启rootless
在恢复模式的Terminal输入如下命令:

  1. csrutil enable

建议修改完成之后,为了系统安全,将rootless重新开启。

2.2 坑2:缺少 autoconfautomakelibtool

本以为修改文件权限后就会一帆风顺,可惜天不遂人愿。看大牛的播客都是一次过,到自己这里就问题比较多。??

发现问题,解决问题。
一顿度娘,找到的都是使用url去下载一个.tar.gz的包,然后解压,安装。
然并卵啊,还是一顿报错,头大

随后,还是使用brew进行的安装,一次搞定

  1. brew install autoconf
  2. brew install automake
  3. brew install libtool

最后,我终于成功了!美滋滋??

  1. Doctor summary (to see all details, run flutter doctor -v):
  2. [?] Flutter (Channel stable, v1.7.8+hotfix.3, on Mac OS X 10.14.5 18F132, locale
  3. zh-Hans-CN)
  4. [?] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
  5. [?] Xcode - develop for iOS and macOS (Xcode 10.2.1)
  6. [?] iOS tools - develop for iOS devices
  7. [?] Android Studio (version 3.4)
  8. [!] VS Code (version 1.36.1)
  9. ? Flutter extension not installed; install from
  10. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
  11. [?] Connected device (1 available)
  12. ! Doctor found issues in 1 category.

原文链接:http://www.cnblogs.com/gfxxbk/p/11597097.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号