flutter搭建mac开发环境

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

  1. clone flutter最新版本
  2. 安装xcode
  3. 升级ruby到最新版本, 再安装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)

$ 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环境搭建就完成

相关推荐

  1. fluttermac开发环境

    2024-03-25 05:26:01       20 阅读
  2. Flutter——环境MAC版)

    2024-03-25 05:26:01       50 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-25 05:26:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-25 05:26:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-25 05:26:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-25 05:26:01       18 阅读

热门阅读

  1. 为什么Rust语言不支持三元表达式?

    2024-03-25 05:26:01       17 阅读
  2. 设计模式,策略模式

    2024-03-25 05:26:01       20 阅读
  3. ElasticSearch插件安装及配置

    2024-03-25 05:26:01       16 阅读
  4. 设计模式--建造者模式(Builder Pattern)

    2024-03-25 05:26:01       20 阅读
  5. P - Beat

    P - Beat

    2024-03-25 05:26:01      18 阅读
  6. C语言UNIX域套接字CS模型

    2024-03-25 05:26:01       18 阅读
  7. [AIGC] OkHttp:轻松实现网络请求

    2024-03-25 05:26:01       18 阅读
  8. 智能写作利器ChatGPT:提升论文写作效率

    2024-03-25 05:26:01       23 阅读
  9. 数据分析-Pandas分类数据的比较如何避坑

    2024-03-25 05:26:01       19 阅读
  10. 在Flink SQL中使用watermark进阶功能

    2024-03-25 05:26:01       20 阅读