Flutter安装配置

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

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

官方讲解地址:[url href=’https://flutter.dev/docs/get-started/install/macos#’]flutter.dev[/url]

下载Flutter SDK包

官网链接:https://flutter.io/setup-macos/
由于国内网络限制我们可以通过修改镜像地址来解决, 好在Google良心,专门给我们大陆提供了方案, 终端中一次输入以下命令即可解决

  1. 打开终端工具,使用vim进行配置环境变量,命令如下:命令:vim ~/.bash_profile,打开后在里面添加这两个

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
这里就开始从github上面拉整体项目
执行命令:git clone -b dev https://github.com/flutter/flutter.git,拉取完后,找到Mac位置,把flutter环境配置一下,执行如下命令
export PATH=”$PATH:/User/jacular/flutter/bin”  ,加粗的地方(/User/jacular/)替换成你的路径
配置文件完成后,使用 source 命令重新加载一下

source ~/.bash_profile
检查是否安装成功
flutter -h
接下来,在使用flutter doctor来检查还需要那些插件和软件安装
[] Flutter (Channel stable, v1.2.1, on Mac OS X 10.13.6 17G4015, locale zh-Hans-CN)
[] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.io/setup/#android-setup for detailed instructions).
      If Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
      You may also want to add it to your PATH environment variable.
[!] 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
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
[!] Android Studio (not installed)
[!] VS Code (version 1.36.1)Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
    ! No devices available

注意:带❌的就必须安装,带❗️的就可以暂时忽略
 

解决带❌的问题

1、Android环境

1.1 安装 Android Studio

打开 Android Studio, 打开 plugins ,安装 flutter
完成后

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

转变为

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

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


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

完成后

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

转变为

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)

2、iOS环境

[!] 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
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy

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

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

看到这个提示,我们第一时间就是想着修改读写权限
当你执行sudo chown -R $(whoami) /usr/local进行修改时,系统会有如下提示:

Operation not permitted

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

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

在终端输入

csrutil status

收到系统提示

System Integrity Protection status:enabled

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

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

csrutil disable

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

csrutil status

系统提示

System Integrity Protection status:disabled

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

csrutil enable

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

2.2 坑2:缺少 autoconfautomakelibtool

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

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

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

brew install autoconf
brew install automake
brew install libtool

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

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

 

下载说明:
1、本站所有资源均从互联网上收集整理而来,仅供学习交流之用,因此不包含技术服务请大家谅解!
2、本站不提供任何实质性的付费和支付资源,所有需要积分下载的资源均为网站运营赞助费用或者线下劳务费用!
3、本站所有资源仅用于学习及研究使用,您必须在下载后的24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担!
4、本站站内提供的所有可下载资源,本站保证未做任何负面改动(不包含修复bug和完善功能等正面优化或二次开发),但本站不保证资源的准确性、安全性和完整性,用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都100%无错或无bug!如有链接无法下载、失效或广告,请联系客服处理!
5、本站资源除标明原创外均来自网络整理,版权归原作者或本站特约原创作者所有,如侵犯到您的合法权益,请立即告知本站,本站将及时予与删除并致以最深的歉意!
6、如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
7、如果您喜欢该资源,请支持官方正版资源,以得到更好的正版服务!
8、请您认真阅读上述内容,注册本站用户或下载本站资源即您同意上述内容!
原文链接:https://www.dandroid.cn/6866,转载请注明出处。
0

评论0

显示验证码
没有账号?注册  忘记密码?