经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » JavaScript » 查看文章
01-mac flutter环境搭建
来源:cnblogs  作者:xccjk  时间:2021/3/1 9:13:52  对本文有异议

mac flutter环境搭建

安装国内镜像

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

下载flutter

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

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

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

运行flutter

  1. 运行flutter doctor

错误详情

  1. Android toolchain - develop for Android devices (Android SDK version 30.0.2)
  2. ? Android licenses not accepted. To resolve this, run: flutter doctor
  3. --android-licenses
  4. [?] Xcode - develop for iOS and macOS
  5. ? Xcode installation is incomplete; a full installation is necessary for iOS
  6. development.
  7. Download at: https://developer.apple.com/xcode/download/
  8. Or install Xcode via the App Store.
  9. Once installed, run:
  10. sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
  11. sudo xcodebuild -runFirstLaunch
  12. ? CocoaPods not installed.
  13. CocoaPods is used to retrieve the iOS and macOS platform side's plugin
  14. code that responds to your plugin usage on the Dart side.
  15. Without CocoaPods, plugins will not work on iOS or macOS.
  16. For more info, see https://flutter.dev/platform-plugins
  17. To install:
  18. sudo gem install cocoapods
  19. [!] Android Studio (version 4.1)
  20. ? Flutter plugin not installed; this adds Flutter specific functionality.
  21. ? Dart plugin not installed; this adds Dart specific functionality.
  22. [!] VS Code (version 1.52.0)
  23. ? Flutter extension not installed; install from
  24. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
  25. [!] Connected device
  26. ! No devices available

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

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

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

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

环境变量配置

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

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

最终的bash_profile文件

  1. // .bash_profile
  2. # HomeBrew
  3. export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
  4. export PATH="/usr/local/bin:$PATH"
  5. export PATH="/usr/local/sbin:$PATH"
  6. export PUB_HOSTED_URL="https://pub.flutter-io.cn"
  7. export FLUTTER_STORAGE_BASE_URL="https://storage.flutter-io.cn"
  8. # name为自己电脑的名称
  9. export PATH="/Users/name/development/flutter/bin:$PATH"
  10. source ~/.bashrc
  11. # HomeBrew END

github查看更多文章

原文链接:http://www.cnblogs.com/sk-3/p/14448971.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号