微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

01-mac flutter环境搭建

mac Flutter环境搭建

安装国内镜像

export PUB_HOSTED_URL=https://pub.Flutter-io.cn
export FlutteR_STORAGE_BASE_URL=https://storage.Flutter-io.cn

下载Flutter

  1. 下载Flutter
  1. 进入你想放置Flutter的目录
cd ~/development
  1. 解压下载文件记住改为你自己下载的版本号,按Y确认即可
unzip ~/Downloads/Flutter_macos_v0.5.1-beta.zip

  1. Flutter添加到path中
export PATH=`pwd`/Flutter/bin:$PATH

此时你会发现,你打开一个新的命令行窗口是,运行Flutter doctor,会报Flutter不存在的错误,是因为环境变量还没全局生效

运行Flutter

  1. 运行Flutter doctor

错误详情

Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ✗ Android licenses not accepted.  To resolve this, run: Flutter doctor
      --android-licenses
[✗] 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:
        sudo gem install cocoapods
[!] Android Studio (version 4.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.52.0)
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.Flutter
[!] Connected device
    ! No devices available

上面的错误信息是告诉你东西未安装完,比如xcode,Android Studio,Android Studio的dart、fultter插件,CocoaPods,VS Code的Flutter插件未安装

  1. xcode安装
  • 在app store搜索xcode,安装即可
  • 运行下面命令
  • 再次运行Flutter doctor会发现关于xcode的错误消失了
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
sudo gem install cocoapods
  1. Android Studio安装

  1. VS Code中Flutter插件安装
  • 打开vscode,点击扩展,输入Flutter,install安装,安装之后重新打开vscode即可

  1. 再次运行Flutter doctor,关于Android Studio相关的错误可能还是有,运行下面的命令
// 注意AndroidStudio版本号
ln -s ~/Library/Application\ Support/Google/AndroidStudio4.1/plugins ~/Library/Application\ Support/AndroidStudio4.1
  1. 再次运行Flutter doctor,下面这样就都正常了

环境变量配置

  • 查看Flutter的环境配置路径path
echo $PATH
// 可以看到Flutter的路径为
/Users/name/development/Flutter/bin:

open ~/.bash_profile
  • 或者vim编辑
vim ~/.bash_profile
  • 如果在编辑bash_profile时发现文件不存在
// 创建bash_profile文件
touch .bash_profile
// 添加国内镜像
export PUB_HOSTED_URL="https://pub.Flutter-io.cn"
export FlutteR_STORAGE_BASE_URL="https://storage.Flutter-io.cn"
// 添加安装路径,上面获取到的
export PATH="/Users/name/development/Flutter/bin:$PATH"
  • 更新环境配置
source ~/.bash_profile
  • 重启编辑器即可,会发现在

最终的bash_profile文件

// .bash_profile
# HomeBrew
export HOMEBREW_BottLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
export PUB_HOSTED_URL="https://pub.Flutter-io.cn"
export FlutteR_STORAGE_BASE_URL="https://storage.Flutter-io.cn"
# name为自己电脑的名称
export PATH="/Users/name/development/Flutter/bin:$PATH"
source ~/.bashrc
# HomeBrew END

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐