首页 技术 正文
技术 2022年11月15日
0 收藏 331 点赞 3,353 浏览 4793 个字

参考:

  1.入门: 在macOS上搭建Flutter开发环境 系统要求

  2.mac配置环境变量

1.打开终端

2.clone flutter

命令:

git clone -b beta https://github.com/flutter/flutter.git

3.打开(或创建) .bash_profile

1.打开

终端输入:

open -e ~/.bash_profile

如果不能成功打开,那就创建

2.创建

1.进入当前用户的home目录(默认就是)

cd ~    或
cd /Users/用户名

4.更新环境变量

打开bash_profile就是为了可以永久的更新环境变量,一劳永逸。请看解释和注意后根据自己的需要来将代码添加到打开的bash_profile。

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

解释: 由于一些flutter命令需要联网获取数据,如果您是在国内访问,由于众所周知的原因,直接访问很可能不会成功。 上面的PUB_HOSTED_URLFLUTTER_STORAGE_BASE_URL是google为国内开发者搭建的临时镜像。你也可以不设置,如果你能翻墙的话。如果不能的话可以直接复制上面的代码

export PATH= PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH

注意:PATH_TO_FLUTTER_GIT_DIRECTORY 为你flutter的路径,比如在当前用户路径里。如果不确定,可以点击mac上面菜单的”前往” –> “个人”,然后在此文件夹里找是否有flutter文件夹。如果有的话你的应该这样写:

export PATH= /Users/用户名/flutter/bin:$PATH

然后输入以下命令更新刚刚配置的环境变量:

source .bash_profile

然后输入以下命令,通过运行flutter/bin命令验证目录是否在已经在PATH中:

echo $PATH

如果看到有flutter那就是配置好了

注意: 如果你使用终端是zsh,终端启动时 ~/.bash_profile 将不会被加载,解决办法就是修改 ~/.zshrc ,在其中添加:source ~/.bash_profile

5.运行 flutter doctor

输入下面这个命令,来看还有没有要安装的依赖项:

flutter doctor

我的话一开始是这个

mac flutter 创建过程及遇到的问题提示flutter版本太低

让我更新flutter,我不想看到warning所以立马更新了。

flutter upgrade

错误1:

然后就看x了,这是我第一个打叉的地方

[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.

这是让我安装android studio并且设置好$ANDROID_HOME这个环境变量。

于是我便按照提示打开https://developer.android.com/studio/index.html,并且下载安装了android studio。

安装后最好运行一下android studio,好安装andriod sdk。运行好根据界面提示点下一步,如果没有sdk会提示安装,只要点就行了。记得查看下安装路径,一般路径都是在当前用户的Library文件夹里。

安装好sdk后,可以把android studio关了。

然后打开bash_profile

open -e .bash_profile

在bash_profile里加上

export ANDROID_HOME="/Users/用户名/Library/Android/sdk" //android sdk目录,替换为你自己的
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

更新配置

source .bash_profile

然后运行

flutter doctor

看这一项还报错不。ok还是有报错,报错如下:

[!] Android toolchain - develop for Android devices (Android SDK 28.0.2)
✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

根据提示运行:

flutter doctor --android-licenses

然后根据提示一直y,y到结束为止。

错误2:

这是我第二个打叉的地方

[!] iOS toolchain - develop for iOS devices
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
For more info, see https://flutter.io/platform-plugins
To install:
brew install cocoapods
pod setup

依旧是根据提示,我去App Store安装了xcode。

安装好后根据之前的错误信息运行:

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

然后:

brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
brew install cocoapods
pod setup

进行到这我报错了:

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progressCloning into 'master'...
remote: Counting objects: 2353094, done.
remote: Compressing objects: 100% (450/450), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

弄个加速器就可以了。我用的云墙netfits,有试用,试用够下载了。如果有更好的加速器欢迎留言。

再运行doctor

flutter doctor

ios还有报错:

[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
✗ Missing Xcode dependency: Python module "six".
Install via 'pip install six' or 'sudo easy_install six'.

按照提示输入’pip install six’ 或 ‘sudo easy_install six’。然后再运行doctor,我这里ios没有报错了。就剩错误3里的报错。

错误3:

[✓] Android Studio (version 3.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.

android studio里还少了两个插件。我们打开andriod studio。

1.点击preferences

mac flutter 创建过程及遇到的问题 

2.搜索plugins

mac flutter 创建过程及遇到的问题 3.搜索fluttermac flutter 创建过程及遇到的问题 

4.点击安装

mac flutter 创建过程及遇到的问题 

有弹框提示要安装dart,同意。等安装好后重启andriod studio。

错误4

<!–
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures; color: #9fa01c}
span.s2 {font-variant-ligatures: no-common-ligatures}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #b42419}
–>

[!] Xcode – develop for iOS and macOS (Xcode 11.2.1)

    CocoaPods not installed.

        CocoaPods is used to retrieve the iOS and macOS platform side’s plugin

        code that responds to your plugin usage on the Dart side.

        Without CocoaPods, plugins will not work on iOS or macOS.

        For more info, see https://flutter.dev/platform-plugins

      To install:

        sudo gem install cocoapods

根据提示输入一下命令:

sudo gem install cocoapods

1.安装dart(官网

brew tap dart-lang/dart
brew install dart

参考:https://www.jianshu.com/p/603649a02956

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,909
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,434
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,249
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,060
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,692
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,730