MacBook M1 Flutter环境搭建的实现步骤

最近入手了Apple M1,MacBook Air,由于之前未使用苹果系列产品,并且Flutter官方和各项配套的软件环境也还没有成熟,导致搭建环境时碰到了不少坑,这里总结记录一波,来看文档的同学,有不懂的地方直接发评论或者消息就好

一、基础环境搭建

 git:

我是装完homebrew,git就装好了,homebrew的安装方法按照这个来的:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

但是后面发现这个安装方法会有一些问题,不过不影响我们使用Flutter,不放心的同学可以去找其他方法安装git 

Flutter SDK:

国内的网络环境下,先配置两个环境变量,最好是~/.zshrc和~/.bash_profile两个文件都配上,配完source一下

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

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

下载安装直接按照官方文档来:https://flutter.cn/docs/get-started/install/macos

执行命令 flutter precache 或者 flutter doctor时会报错,因为没有在命令行执行安装rosetta的命令,详细的错误信息可以去下面的github地址查看

还少了一步操作,我第一天的晚上就卡在这儿了,最后去github提了issue,得到了一位老哥的提点

https://github.com/flutter/flutter/issues/74511#issue-792217747

终端执行命令

/usr/sbin/softwareupdate --install-rosetta --agree-to-license

随后再执行flutter命令正常,继续按着官方的安装文档走,环境变量一定要配,不然以后在终端无法直接使用flutter命令

CocoaPods:

Flutter官方文档给出的安装方式是命令行运行命令

sudo gem install cocoapods

但是这样后期跑带插件的ios应用,需要用到Cocoapods时就会报错

### Error

LoadError - dlsym(0x7ff8aa0382f0, Init_ffi_c): symbol not found - /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi_c.bundle

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi.rb:6:in `rescue in <top (required)>'

/Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/lib/ffi.rb:3:in `<top (required)>'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/Library/Ruby/Gems/2.6.0/gems/ethon-0.12.0/lib/ethon.rb:2:in `<top (required)>'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/Library/Ruby/Gems/2.6.0/gems/typhoeus-1.4.0/lib/typhoeus.rb:2:in `<top (required)>'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:74:in `cdn_url?'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:36:in `create_source_with_url'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/sources_manager.rb:21:in `find_or_create_source_with_url'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:178:in `block in sources'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `map'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `sources'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1073:in `block in resolve_dependencies'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1072:in `resolve_dependencies'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:124:in `analyze'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:414:in `analyze'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:239:in `block in resolve_dependencies'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:238:in `resolve_dependencies'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:160:in `install!'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command/install.rb:52:in `run'

/Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command.rb:52:in `run'

/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/bin/pod:55:in `<top (required)>'

/usr/local/bin/pod:23:in `load'

/usr/local/bin/pod:23:in `<main>'

――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

[!] Oh no, an error occurred.

Search for existing GitHub issues similar to yours:

https://github.com/CocoaPods/CocoaPods/search?q=dlsym%280x7ff8aa0382f0%2C+Init_ffi_c%29%3A+symbol+not+found+-+%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.13.1%2Flib%2Fffi_c.bundle&type=Issues

If none exists, create a ticket, with the template displayed above, on:

https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:

https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

Looking for related issues on cocoapods/cocoapods...

Found no similar issues. To create a new issue, please visit:

https://github.com/cocoapods/cocoapods/issues/new

需要使用 Rosetta 方式运行终端执行命令才行

打开 访达 -> 应用程序 -> 实用工具 -> 终端 -> 右键 -> 显示简介 -> 选中使用 Rosetta 打开

然后重新启动终端,执行

sudo gem install cocoapods

sudo gem install ffi

二、安装IDE

我安装了IDEA,Xcode和AndroidStudio

IDEA:

个人习惯使用IDEA做开发,社区版即可,而且已经对M1版本做了适配(题外话,mac体验果然好,打开IDEA的速度简直起飞)

下载地址:https://www.jetbrains.com/idea/download/

安装这里说个笑话,因为没用过mac,安装都不会,后面才知道安装是点击安装文件之后在出现的界面里把程序拖到Applications里😭

使用IDEA开发Flutter需要安装Dart和Flutter插件

Xcode:

ios开发必备(即使你不用ta来写代码),我安装只是让ta用来配置各项环境,省心(工具界的工具人?),装完一定记得要运行一次

官方下载地址:appstore搜索安装即可,比较大,时间会长一点

安装完之后运行命令,做IOS开发的相关设置

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

sudo xcodebuild -runFirstLaunch

sudo xcodebuild -license

AndroidStudio:

官方下载地址:https://redirector.gvt1.com/edgedl/android/studio/install/4.1.2.0/android-studio-ide-201.7042882-mac.dmg

装这个只是为了让他把安卓的环境都准备好(又一个工具界的工具人),跟着安装步骤一直点就好了,不过M1芯片的现在还没法直接用AS附带的安卓模拟器,真机调试把,windows下用过AS的老哥应该都很熟了

使用AS开发Flutter需要安装Dart和Flutter插件

三、跑一个app试试

按照官方文档来就行,随便用一个第三方依赖包,可以检测出CocoaPods是否正常安装

这个是我之前自己在windows上写的一个小应用,只用了 shared_preferences这个包

运行flutter pub get获取依赖包

开启IOS模拟器,运行

最终效果: 

到此这篇关于MacBook M1 Flutter环境搭建的实现步骤的文章就介绍到这了,更多相关M1 Flutter环境搭建内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

以上是 MacBook M1 Flutter环境搭建的实现步骤 的全部内容, 来源链接: utcz.com/p/243780.html

回到顶部