[Flutter] 無法執行專案的版本問題

Steven_唐
Jan 17, 2023

最近在複習Kodeco(已改名的Raywenderlich)還有一些官方的專案時會調整pubspec.ymal內的Dart SDK 版本讓專案可以順利跑起來。

不過有時候就會遇到一些有點惱人的問題,就是無法正常執行專案然後跑出一大串訊息。最常看到的報錯就是CocoaPod、Ruby以及gradle報錯的訊息。

常見的報錯訊息
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20230117-90598-1sjgbn0.rb extconf.rb checking for ffi.h...
*** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

還有一段的內容是這樣的:

Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. 
Check the mkmf.log file for more details. You may need configuration options.

在除錯的過程中漸漸意識到好像維持原本專案內的版本就不太會有這種問題。可是我又還不想升級版本,該怎麼辦呢?這時候就可以用到Sidekick版本控制工具:

GitHub — fluttertools/sidekick: A simple app to make Flutter development more delightful

下載完成想要的版本後開始設定專案的Flutter SDK路徑,如果是使用Mac電腦的話,點擊進入到下載好的SDK檔案夾後按著option鍵會出現目前所在位置。

接著在下方顯示的地方點擊滑鼠右鍵,選取複製路徑。

複製完成後回到Android Studio Preferences設定路徑,這樣就完成啦!

VS Code也可以設定路徑,但自己覺得android studio直接改比較快因此這裡就不示範~,有興趣可以參考連結:Configuration | Flutter Version Management (fvm.app)

--

--