参考文档:
https://flutterchina.club/setup-macos/
https://segmentfault.com/a/1190000014845833
1、首先安装flutterSDK,因为国内镜像的原因可能需要更换下镜像信息(镜像更新关注:https://flutter.dev/community/china)
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
git clone -b dev https://github.com/flutter/flutter.git
export PATH="PATH"
cd ./flutter
flutter doctor
flutter doctor 会帮助检测所需要的工具是否齐全
注意如果出现flutter命令失效 需要从新写入flutter bin路径信息
安装成功时候回显示:
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.io ║
║ ║
║ The Flutter tool anonymously reports feature usage statistics and crash ║
║ reports to Google in order to help Google contribute improvements to ║
║ Flutter over time. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://www.google.com/intl/en/policies/privacy/ ║
║ ║
║ Use "flutter config --no-analytics" to disable analytics and crash ║
║ reporting. ║
╚════════════════════════════════════════════════════════════════════════════╝
问题:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.4.6, on Mac OS X 10.14.4 18E226, 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](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](https://flutter.io/setup/#android-setup) for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
You may also want to add it to your PATH environment variable.
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
✗ Brew can be used to install tools for iOS device development.
Download brew at [https://brew.sh/](https://brew.sh/).
[!] Android Studio (not installed)
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
appledeMacBook-Pro-41:flutter apple$
这里来解决我的问题
问题1 Android toolchain - develop for Android devices
这里显然是安卓开发工具没有安装的问题,所以我们去下载java JDK和安卓studio 因为教程很多,所以这里只简单描述了
1、安装java JDK
下载java sdk https://www.oracle.com下载jdk 无脑安装,然后.bash_profile环境变量配置(根据你自己的环境变量配置信息来)
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home PATH=PATH:. CLASSPATH=JAVA_HOME/lib/dt.jar:. export JAVA_HOME export PATH export CLASSPATH
注意source .bash_profile让配置生效,然后java -v 查看版本信息
appledeMacBook-Pro-41:~ apple$ java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
appledeMacBook-Pro-41:~ apple$
如上输出 则说明你安装jdk成功
2、安装android studio
下载http://www.android-studio.org/ 选择Mac版本 然后无脑式下一步安装 注意配置
选择安装标准版本,但是此处回关联安卓SDK下载配置。也可以手动去下载配置安卓sdk信息,如果查找有问题需要制定安卓HOME路径
这里列举下flutter的所有路径信息:(可以对照自己的路径进行修改)
export PATH=/Users/用户名/Documents/flutter/flutter/bin:$PATH
export ANDROID_HOME="/Users/用户名/Documents/android_sdk" //android sdk目录,替换为你自己的即可
export PATH={ANDROID_HOME}/tools
export PATH={ANDROID_HOME}/platform-tools
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
问题2就不说了。注意安装brew信息。然后根据brew安装其他需要工具
注意这里https://brew.sh/. brew的安装可能遇到xcode的路径配置信息问题
Error downloading updates.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
这是因为Xcode安装位置变更引起的,我们需要手动变更下安装配置路径
首先查看你的正确路径
xcode-select -p
/Applications/Xcode.app/Contents/Developer
解决1 sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer 最简单的就是强行指定,这方法我没用过。我用的方法二
解决2 获取安装文件 https://raw.githubusercontent.com/Homebrew/install/master/install Mac下touch install文件,复制其中的内容到文件中,然后替换其中的/Library/Developer/CommandLineTools为正确路径,然后保存执行 ruby -e "$(cat install)”安装命令
安装完成再一次运行出现错误信息:
appledeMacBook-Pro-41:~ apple$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.4.6, on Mac OS X 10.14.4 18E226, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[!] Android Studio (version 3.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
! Doctor found issues in 3 categories.
appledeMacBook-Pro-41:~ apple$
问题1 按照要求运行
输入 flutter doctor --android-licenses,接下来所有的输入 y 就可以了
再次flutter doctor 问题解决部分 但是还有剩下的如下:
appledeMacBook-Pro-41:~ apple$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.4.6, on Mac OS X 10.14.4 18E226, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[!] Android Studio (version 3.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
这问题是安卓studio插件问题 打开安卓studio 配置上选择插件
[图片上传失败...(image-811353-1624439961629)]
打开android studio, 打开plugins检索flutter(注意这里需要翻墙有时候)
检索结果安装
安装完成重新启动安卓studio
再次flutter doctor
appledeMacBook-Pro-41:~ apple$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v1.4.6, on Mac OS X 10.14.4 18E226, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
[!] Connected device
! No devices available
appledeMacBook-Pro-41:~ apple$
如此配置已经完成了!!