更新於 2024/11/19閱讀時間約 3 分鐘

在 MacBook Air M1 上輕鬆安裝 Flutter:完整指南!

安裝Flutter

  1. 下載Flutter (Apple Silicon的版本):https://docs.flutter.dev/get-started/install/macos
  2. 在想安裝Flutter的目錄下解壓縮
$ cd ~Desktop/development
$ unzip ~/Downloads/flutter_macos_3.16.0-stable.zip
  1. 將Flutter加入PATH
    暫時性(關掉terminal就沒了):
$ export PATH="$PATH:`pwd`/flutter/bin"

永久性:

打開或創建`rc` file。
首先先輸入指令`echo $SHELL`查看自己的電腦用哪一種shell。
如果是Bash, 編輯`~/.bash_profile`或者`~/.bashrc`
如果是用Z shell, 則編輯`~/.zshrc`
我的是Z shell,所以編輯`~/.zshrc`
$ nano ~/.zshrc
$ export PATH="$PATH:`pwd`/flutter/bin"
^X存檔離開。
  1. 檢查是否安裝成功(no issue)
$ flutter doctor
  1. 創建專案
$ flutter create my_first_app
  1. 用VS Code開啟專案並選擇模擬器執行程式
    預設專案為一個計數器

其他需安裝軟體

Xcode

App Store->Xcode (需要macOS 13以上)

Android Studio

下載連結:https://developer.android.com/studio?hl=zh-tw

如執行$ flutter doctor有sdk update的問題,移除舊版本,安裝新版本

Cocopods

$ sudo gem install cocoapods

Visual Studio Code

下載連結:https://code.visualstudio.com/download
安裝Extansion:Flutter, Dart


Trouble Shooting

cmdline-tools component is missing

Run `path/to/sdkmanager --install "cmdline-tools;latest"`

Android License status unknown

Run `flutter doctor --android-licenses`

Cocoapod not installed

Run `sudo gem install cocoapods`

ERROR: Error installing cocoapods: There are no versions of cocoapods-downloader (>= 2.0) compatible with your Ruby & RubyGems. Maybe try installing an older version of the gem you're looking for? cocoapods-downloader requires Ruby version >= 2.7.4. The current ruby version is 2.6.10.210.
(macOS Sonoma 14.1.1會遇到這個error)

Solution:

$ sudo gem install drb -v 2.0.5
$ sudo gem install activesupport -v 6.1.7.6
$ sudo gem install cocoapods -v 1.13.0
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.