flutter搭建mac开发环境

flutter搭建mac开发环境, 前期准备,至少20G+的硬盘空间,否则xcode都安装不了, 以前也搭建过mac环境,不过cocoapads版本比较老 跳转

  1. clone flutter最新版本
  2. 安装xcode
  3. 升级ruby到最新版本(通过rbenv), 再安装cocoapods
  4. flutter doctor验证安装完成

下载代码, 进入安装目录,执行一下./bin/flutter主文件

$ git clone https://github.com/flutter/flutter.git
$ cd flutter
$ ./bin/flutter

安装xcode
从appstore下载会提示磁盘空间不足,这里改从下面链接下载
mac版本与xcode版本对应,下载对应xcode版本
由于mac系统12.7.4的版本,安装对应xcode也并非最新版本
一步一步安装xcode,完成后,显示占用空间23G, 后

增加flutter到系统环境变量

$ echo 'export PATH=$PATH:/Users/apple/Flutter/bin' >> ~/.bash_profile
$ source ~/.bash_profile
$ flutter --version
Framework • revision 638e47146d (13 hours ago)2024-03-23 15:16:54 -0400
Engine • revision 7aa8521e64
Tools • Dart 3.4.0 (build 3.4.0-266.0.dev) • DevTools 2.34.0-dev.12
$ flutter doctor
...略
[!] Xcode - develop for iOS and macOS (Xcode 14.2)
    ✗ 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 see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[] Chrome - develop for the web
...略

这里提示CocoaPods not installed,开始安装cocoapods, 使用gem安装

$ gem which cocoapods
ERROR:  Can't find Ruby library file or shared library cocoapods

以下未添加sudo

$ gem install cocoapods
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

以下未安装最新版本ruby

ERROR:  Error installing cocoapods:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c

安装最新版本raby (注意: 此处使用brew前面不要添加sudo)…不过这里最好通过rbenv安装,省得后面还得重新安装-_-!!!

$ brew reinstall ruby
...略
==> Reinstalling ruby
==> Pouring ruby--3.1.1.monterey.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/3.1.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib"
  export CPPFLAGS="-I/usr/local/opt/ruby/include"

For pkg-config to find ruby you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

设置ruby的系统环境变量

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile

再使用gem安装cocoapods

$ gem install -n /usr/local/bin cocoapods
...略
Done installing documentation for rexml, nanaimo, colored2, claide, CFPropertyList, atomos, xcodeproj, ruby-macho, nap, molinillo, gh_inspector, fourflusher, escape, cocoapods-try, netrc, cocoapods-trunk, cocoapods-search, cocoapods-plugins, cocoapods-downloader, cocoapods-deintegrate, ffi, ethon, typhoeus, public_suffix, fuzzy_match, concurrent-ruby, httpclient, algoliasearch, addressable, tzinfo, i18n, connection_pool, activesupport, cocoapods-core, cocoapods after 33 seconds
35 gems installed
// 安装完成
$ pod --version
1.15.2

最后验证结果,

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel master, 3.21.0-13.0.pre.25, on macOS 12.7.4 21H1123 darwin-x64, locale zh-Hans-CN)
...略
[] Xcode - develop for iOS and macOS (Xcode 14.2)
[] Chrome - develop for the web
[!] Android Studio (not installed)
[] VS Code (version 1.85.2)
[] Connected device (2 available)
[!] Network resources
...略

最后,到此就flutter的mac环境搭建就完成

  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值