Flutter入门(1)—环境配置

环境配置

一、获取Flutter SDK
1、去flutter官网下载其最新可用的安装包,转到下载页
2、将flutterSDK进行解压【最好放到一个指定的目录下,后面设置path路径还需要用】
3、添加环境变量
cd ~
❯ vim .zshrc

# 将下面的path拷贝到文件最后, esc => :wq! 保存即可
# Flutter Path
export PATH="$PATH:[pwd]/flutter/bin"
# eg: export PATH="$PATH:/Users/xxx/flutter/sdk/flutter/bin"source .zshrc

4、可以通过命令来看一下是否配置成功

❯ flutter  
# 或者
❯ flutter -h

二、检查是否依赖完成

运行以下命令查看是否需要安装其它依赖项来完成安装,根据错误信息进行操作就可以

❯ flutter doctor

输出

Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 1.22.4, on Mac OS X 10.15.6 19G73 darwin-x64, locale zh-Hans-CN)
[] 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.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

[!] Xcode - develop for iOS and macOS (Xcode 12.2)
    ✗ 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
[!] Android Studio (not installed)
[] VS Code (version 1.51.1)

[] Connected device (1 available)

! Doctor found issues in 3 categories.

因为咱们现在都是mac,模拟器我们用xcode就可以了

(一)、安装xcode
1、这个去app store就可以去下载,最好在家下载,或者网络好的地方下载,我在公司下载了用了8个小时左右
2、配置Xcode命令行工具以使用新安装的Xcode版本
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
3、确保Xcode许可协议是通过打开一次Xcode或通过命令,如果有[Y/N]的话,一路Y就可以了,N的话会有问题
sudo xcodebuild -license
4、安装包管理工具
# 通过brew安装(推荐)
brew install cocoapods
brew link --overwrite cocoapods

# 或者通过gem安装
sudo gem install cocoapods

# https://github.com/orta/cocoapods-keys/issues/198#issuecomment-510909030
# https://github.com/CocoaPods/CocoaPods/issues/9602
(二)、配置vsCode
在扩展中安装Flutter插件,并重新启动加载插件
(三)设置ios模拟器
# 打开一个模拟器,确保您的模拟器正在使用64位设备(iPhone 5s或更高版本)
open -a Simulator

三、android studio

1、官网下载IDE
2、打开IDE,安装flutter插件和dart插件
Android Studio -> preperences -> plugins (右侧) markplace 搜索flutter安装即可,会自动提示安装Dart
3、但是运行flutter doctor 会一直显示plugins没有安装上
1、https://github.com/flutter/flutter-intellij/issues/4523
2、https://stackoverflow.com/questions/64395106/update-to-android-studio-4-1-flutter-plugin-and-dart-plugin-not-installed/64417280#64417280

reason:对于android studio文件的路径变了,目前flutter sdk的beta版已修复
answer:1)软链 
				2)切换flutter sdk为beta版
        				flutter channel dev
								flutter upgrade
4、打开Android Studio,新建虚拟机, 第一次会去谷歌下载gradle,这个东西很容下载失败,如果失败,可以多反复试几次
5、下面就和mac的使用方式一样了…

原创不易,自由转载,保留出处!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值