MacBook M1 Flutter環(huán)境搭建的實(shí)現(xiàn)步驟
最近入手了Apple M1,MacBook Air,由于之前未使用蘋果系列產(chǎn)品,并且Flutter官方和各項(xiàng)配套的軟件環(huán)境也還沒有成熟,導(dǎo)致搭建環(huán)境時碰到了不少坑,這里總結(jié)記錄一波,來看文檔的同學(xué),有不懂的地方直接發(fā)評論或者消息就好
一、基礎(chǔ)環(huán)境搭建
git:
我是裝完homebrew,git就裝好了,homebrew的安裝方法按照這個來的:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
但是后面發(fā)現(xiàn)這個安裝方法會有一些問題,不過不影響我們使用Flutter,不放心的同學(xué)可以去找其他方法安裝git
Flutter SDK:
國內(nèi)的網(wǎng)絡(luò)環(huán)境下,先配置兩個環(huán)境變量,最好是~/.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
執(zhí)行命令 flutter precache 或者 flutter doctor時會報錯,因?yàn)闆]有在命令行執(zhí)行安裝rosetta的命令,詳細(xì)的錯誤信息可以去下面的github地址查看
還少了一步操作,我第一天的晚上就卡在這兒了,最后去github提了issue,得到了一位老哥的提點(diǎn)
https://github.com/flutter/flutter/issues/74511#issue-792217747
終端執(zhí)行命令
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
隨后再執(zhí)行flutter命令正常,繼續(xù)按著官方的安裝文檔走,環(huán)境變量一定要配,不然以后在終端無法直接使用flutter命令
CocoaPods:
Flutter官方文檔給出的安裝方式是命令行運(yùn)行命令
sudo gem install cocoapods
但是這樣后期跑帶插件的ios應(yīng)用,需要用到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 方式運(yùn)行終端執(zhí)行命令才行
打開 訪達(dá) -> 應(yīng)用程序 -> 實(shí)用工具 -> 終端 -> 右鍵 -> 顯示簡介 -> 選中使用 Rosetta 打開
然后重新啟動終端,執(zhí)行
sudo gem install cocoapods sudo gem install ffi
二、安裝IDE
我安裝了IDEA,Xcode和AndroidStudio
IDEA:
個人習(xí)慣使用IDEA做開發(fā),社區(qū)版即可,而且已經(jīng)對M1版本做了適配(題外話,mac體驗(yàn)果然好,打開IDEA的速度簡直起飛)
下載地址:https://www.jetbrains.com/idea/download/
安裝這里說個笑話,因?yàn)闆]用過mac,安裝都不會,后面才知道安裝是點(diǎn)擊安裝文件之后在出現(xiàn)的界面里把程序拖到Applications里😭
使用IDEA開發(fā)Flutter需要安裝Dart和Flutter插件
Xcode:
ios開發(fā)必備(即使你不用ta來寫代碼),我安裝只是讓ta用來配置各項(xiàng)環(huán)境,省心(工具界的工具人?),裝完一定記得要運(yùn)行一次
官方下載地址:appstore搜索安裝即可,比較大,時間會長一點(diǎn)
安裝完之后運(yùn)行命令,做IOS開發(fā)的相關(guān)設(shè)置
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch sudo xcodebuild -license
AndroidStudio:
裝這個只是為了讓他把安卓的環(huán)境都準(zhǔn)備好(又一個工具界的工具人),跟著安裝步驟一直點(diǎn)就好了,不過M1芯片的現(xiàn)在還沒法直接用AS附帶的安卓模擬器,真機(jī)調(diào)試把,windows下用過AS的老哥應(yīng)該都很熟了
使用AS開發(fā)Flutter需要安裝Dart和Flutter插件
三、跑一個app試試
按照官方文檔來就行,隨便用一個第三方依賴包,可以檢測出CocoaPods是否正常安裝
這個是我之前自己在windows上寫的一個小應(yīng)用,只用了 shared_preferences這個包
運(yùn)行flutter pub get獲取依賴包
開啟IOS模擬器,運(yùn)行
最終效果:
到此這篇關(guān)于MacBook M1 Flutter環(huán)境搭建的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)M1 Flutter環(huán)境搭建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android 實(shí)現(xiàn)秒轉(zhuǎn)換成時分秒的方法
這篇文章主要介紹了Android 實(shí)現(xiàn)秒轉(zhuǎn)換成時分秒的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05Android中PopupWindow彈出式窗口使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android中PopupWindow彈出式窗口的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-09-09Flutter實(shí)現(xiàn)簡單的內(nèi)容高亮效果
內(nèi)容高亮并不陌生,特別是在搜索內(nèi)容頁面,可以說四處可見,這篇文章主要為大家介紹了如何使用Flutter實(shí)現(xiàn)簡單的內(nèi)容高亮效果,需要的可以參考下2023-08-08Android實(shí)現(xiàn)錄音功能實(shí)現(xiàn)實(shí)例(MediaRecorder)
本篇文章主要介紹了Android實(shí)現(xiàn)錄音的實(shí)例代碼(MediaRecorder),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07Android中Binder詳細(xì)學(xué)習(xí)心得
這篇文章主要介紹了Android中Binder詳細(xì)學(xué)習(xí)心得,并分析了Binder的詳細(xì)用法,需要的朋友參考下吧。2018-01-01Android中的webview監(jiān)聽每次URL變化實(shí)例
這篇文章主要介紹了Android中的webview監(jiān)聽每次URL變化實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android編程實(shí)現(xiàn)自定義toast示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)自定義toast,結(jié)合簡單實(shí)例形式分析了自定義布局toast核心實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2017-01-01Android自定義ViewGroup實(shí)現(xiàn)可滾動的橫向布局(2)
這篇文章主要介紹了Android自定義ViewGroup實(shí)現(xiàn)可滾動的橫向布局,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12Android開發(fā)筆記之:Log圖文詳解(Log.v,Log.d,Log.i,Log.w,Log.e)
本篇文章是對Android中的Log進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05