首页
Javascript
Html
Css
Node.js
Electron
移动开发
小程序
工具类
服务端
浏览器相关
前端收藏
其他
关于
公司注册

flutter环境安装及各种问题

2019年06月19日 发布 阅读(3940) 作者:Jerman

环境变量

由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中
Linux设置

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

Windows设置
CMD中执行下面两个命令

  1. set PUB_HOSTED_URL=https://pub.flutter-io.cn
  2. set FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

下载Flutter SDK

官网下载:https://flutter.dev/docs/development/tools/sdk/releases#windows
通过git下载

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

下载之后,windows下设置flutter全局变量=>系统变量=>Path

执行flutter命令

进入flutter SDK代码目录,双击flutter_console.bat,显示如下

  1. ######## ## ## ## ######## ######## ######## ########
  2. ## ## ## ## ## ## ## ## ##
  3. ## ## ## ## ## ## ## ## ##
  4. ###### ## ## ## ## ## ###### ########
  5. ## ## ## ## ## ## ## ## ##
  6. ## ## ## ## ## ## ## ## ##
  7. ## ######## ####### ## ## ######## ## ##
  8. WELCOME to the Flutter Console.
  9. ================================================================================
  10. Use the console below this message to interact with the "flutter" command.
  11. Run "flutter doctor" to check if your system is ready to run Flutter apps.
  12. Run "flutter create <app_name>" to create a new Flutter project.
  13. Run "flutter help" to see all available commands.
  14. Want to use an IDE to interact with Flutter? https://flutter.dev/ide-setup/
  15. Want to run the "flutter" command from any Command Prompt or PowerShell window?
  16. Add Flutter to your PATH: https://flutter.dev/setup-windows/#update-your-path
  17. ================================================================================

执行flutter doctor

  1. D:\project\flutter>flutter doctor
  2. ╔════════════════════════════════════════════════════════════════════════════╗
  3. Welcome to Flutter! - https://flutter.dev ║
  4. The Flutter tool anonymously reports feature usage statistics and crash
  5. reports to Google in order to help Google contribute improvements to
  6. Flutter over time.
  7. Read about data we send with crash reports:
  8. https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
  9. See Google's privacy policy: ║
  10. ║ https://www.google.com/intl/en/policies/privacy/ ║
  11. ║ ║
  12. ║ Use "flutter config --no-analytics" to disable analytics and crash ║
  13. ║ reporting. ║
  14. ╚════════════════════════════════════════════════════════════════════════════╝
  15. Doctor summary (to see all details, run flutter doctor -v):
  16. [√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
  17. [X] Android toolchain - develop for Android devices
  18. X Unable to locate Android SDK.
  19. Install Android Studio from: https://developer.android.com/studio/index.html
  20. On first launch it will assist you in installing the Android SDK components.
  21. (or visit https://flutter.dev/setup/#android-setup for detailed instructions).
  22. If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
  23. You may also want to add it to your PATH environment variable.
  24. [!] Android Studio (not installed)
  25. [!] VS Code, 64-bit edition
  26. X Flutter extension not installed; install from
  27. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
  28. [!] Connected device
  29. ! No devices available
  30. ! Doctor found issues in 4 categories.

安装Android Studio

flutter doctor命令结果中看到,Android Studio没有安装,提提示了安装地址https://developer.android.com/studio/index.html (这个地址需要翻墙),或者从这个地址下载http://www.android-studio.org/ (不需翻墙)

Android Studio安装不需再多言,按步就班装就可以了

安装好Android Studio后,再次执行flutter doctor

  1. D:\project\flutter>flutter doctor
  2. Doctor summary (to see all details, run flutter doctor -v):
  3. [√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
  4. [!] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
  5. X Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
  6. [!] Android Studio (version 3.4)
  7. X Flutter plugin not installed; this adds Flutter specific functionality.
  8. X Dart plugin not installed; this adds Dart specific functionality.
  9. [!] VS Code, 64-bit edition
  10. X Flutter extension not installed; install from
  11. https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
  12. [!] Connected device
  13. ! No devices available
  14. ! Doctor found issues in 4 categories.

Android licenses

从上一步的提示中,可以看到

  1. Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

执行下面命令,一直输入y就好了

  1. flutter doctor --android-licenses

安装Flutter plugin

从上上一步,还可以看到报错

  1. Flutter plugin not installed; this adds Flutter specific functionality.
  2. Dart plugin not installed; this adds Dart specific functionality.
  • 打开Android Studio=>Configure=>Plugins

Dart plugin会和Flutter plugin一起安装,提示时,选择Yes即可

显示下图时,表示Flutter plugin已经安装好了,我们这时就可以创建Flutter项目了

安装vs code 的 Flutter extension

打开https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
直接安装

再次执行flutter doctor

如下可见,基本的环境已经全部安装好了

  1. D:\project\flutter>flutter doctor
  2. Doctor summary (to see all details, run flutter doctor -v):
  3. [√] Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
  4. [√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
  5. [√] Android Studio (version 3.4)
  6. [√] VS Code, 64-bit edition
  7. [!] Connected device
  8. ! No devices available
  9. ! Doctor found issues in 1 category.
版权声明:本站文章除特别声明外,均采用署名-非商业性使用-禁止演绎 4.0 国际 许可协议,如需转载,请注明出处