M1安装 Flutter

670 阅读2分钟

安装 Homebrew

Homebrew 中文网

ARMHomebrew需要安装在/opt/homebrew路径下,早期的时候需要手动创建目录执行命令,目前使用最新脚本不需要手动操作。

/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
安装上个步骤也会有提醒的 让你执行操作 
echo $SHELL
  • /bin/bash => bash => .bash_profile
  • /bin/zsh => zsh => .zprofile

如果遇到环境变量无效问题,建议回过头来查看终端类型,再做正确的设置。

macOS Catalina(10.15.x) 版开始,Mac使用zsh作为默认Shell,使用.zprofile,所以对应命令:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

如果是macOS Mojave 及更低版本,并且没有自己配置过zsh,使用.bash_profile

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"

image.png

下载Xcode 下载AndroidStudio

在AppStore下载Xcode即可

安卓下载地址

安装Cocopods

# 2020年cocopods安装-[!] CDN: trunk Repo update failed

查看镜像

gem source -l

替换

删除镜像 添加 https://gems.ruby-china.com/

gem sources --remove https://rubygems.org/ 
gem sources -a https://gems.ruby-china.com/

安装

sudo gem install cocoapods -n /usr/local/bin
cd git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk


如果比较慢 换下一个

cd git clone https://gitee.com/mirrors/CocoaPods-Specs.git ~/.cocoapods/repos/trunk

但因为m1芯片与ruby不兼容,所以使用pod search AFN会报错。这时你找到你的命令行应用程序(默认的终端,或者我用的iTerm),右键应用->显示简介,找到有个选项"使用Rosetta打开”,勾选它。然后重启终端后执行:

image.png

sudo gem install ffi

pod search AFN

安装JDK

jdk

image.png

image.png

默认安装默认地方

安装fvm

  1. 先安装dart
  2. 安装fvm

下载dart-sdk

export PATH="$PATH":"$HOME/dart-sdk/bin"

变量生效

source .zshrc

查看版本

dart --version

下载fvm

// 下载
dart pub global activate fvm
// 使用
fvm
//查看所以可安装的flutter版本
fvm releases
下载flutter
fvm install 2.10.4
切换global
fvm global 2.10.4

配置环境变量

命令

export PATH="$PATH":"$HOME/.pub-cache/bin"
export PATH="$PATH":"$HOME/fvm/default/bin"
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

source .zshrc

查看配置

flutter doctor

androidstuio配置

image.png