Flutter环境搭建

作者: xmb | 来源:发表于2018-12-18 18:16 被阅读0次

谷歌Flutter官方网站
Flutter中文网
Flutter社区中文资源
Flutter初体验(一)——Mac 安装配置

如果你在国内使用 Flutter,那么你可能需要找一个与官方同步的可信的镜像站点,帮助你的 Flutter 命令行工具到该镜像站点下载其所需的资源。
你需要为此设置两个环境变量:“PUB_HOSTED_URL”和“FLUTTER_STORAGE_BASE_URL”,然后再运行 Flutter 命令行工具,查看设置教程

上海交通大学 Linux 用户组

FLUTTER_STORAGE_BASE_URL: https://mirrors.sjtug.sjtu.edu.cn
PUB_HOSTED_URL: https://dart-pub.mirrors.sjtug.sjtu.edu.cn

Flutter 社区

FLUTTER_STORAGE_BASE_URL: https://storage.flutter-io.cn
PUB_HOSTED_URL: https://pub.flutter-io.cn

export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

注意:我们无法保证这些镜像网站得以长期维护和运行,请慎重选择一些可信的镜像网站。

下载flutter stable:https://flutter.dev/docs/get-started/install/macos

  • 配置永久环境变量:
    1、将下载的flutter包放在/Users/yuanzhiying/Library/
    2、执行命令:
open ~/.bash_profile

如果不存在.bash_profile,则执行cd ~touch .bash_profile来创建一个.bash_profile
3、打开文件,在里面添加上:

# flutter
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=${PATH}:/Users/yuanzhiying/Library/flutter/bin

4、执行

source ~/.bash_profile

5、验证

echo $PATH

6、执行flutter doctor,返回结果

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, 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.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 with Brew:
        brew install ios-deploy
[!] Android Studio (not installed)
[✓] Connected device (1 available)

! Doctor found issues in 3 categories.

按照上面的提示安装不合要求的项目。
7、 iOS toolchain按照命令即可安装成功。
8、安装android-studio
下载android-studio:
https://developer.android.com/studio/index.html (最新版)
dmg包双击安装即可
9、打开android studio,按提示安装Android sdk

WX20181222-001326@2x.png
10、安装Android studio plugin:Flutter dart
搜索不到无法下载,按下面的处理方法:
File->Settings->Apparence & Behavior->System Settings->Updates->use secure connnection 勾去掉
11、Android Studio、IntelliJ IDEA安装Flutter plugin和Dart plugin
先去掉Android studio中updates的Use secure connection的勾选,点击应用apply。
WX20181224-101954@2x.png
plugins中搜索库flutter:
WX20181224-102053@2x.png
WX20181224-102236@2x.png

其他问题解决办法:
一、Android license status unknown

[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    ✗ Android license status unknown.

执行:

flutter doctor --android-licenses

结果:

yuanzhiying:~ yuanzhiying$ flutter doctor --android-licenses
Warning: File /Users/yuanzhiying/.android/repositories.cfg could not be loaded. 
All SDK package licenses accepted.======] 100% Computing updates...  

yuanzhiying:~ yuanzhiying$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2018.1.4)
[✓] Connected device (2 available)

• No issues found!

相关文章

网友评论

    本文标题:Flutter环境搭建

    本文链接:https://www.haomeiwen.com/subject/wholkqtx.html