Ubuntu18.04安装Flutter开发环境

说明

本文是在Ubuntu18.04新装系统下安装的flutter环境,基本踩到很多坑.

1.安装vscode,安装完成后再装flutter的基本插件,比如Flutter,Flutter Widget Snippets等插件.

2.flutter 环境变量

改变用户环境变量,主文件夹下面用Ctrl + H打开隐藏文件并打开.bashrc文件将下面内容加入到最后

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn\
复制代码

3.安装Flutter SDK

结合Flutter中文官网将下载的Flutter SDK放到某文件夹下, 比如/home/name/development/文件夹.

export PATH=/home/name/development/flutter/bin:$PATH
对应官网的
export PATH=`pwd`/flutter/bin:$PATH
只是路径不一样,路径需要更改为下载的本地Flutter SDK路径
复制代码

export PATH=/home/name/development/flutter/bin:$PATH
复制代码

放到环境变量中, 文件路径和下载的本地Flutter SDK路径一致

4.运行 flutter doctor

这个时候如果提示Unable to find git in your PATH.请安装git.如果运行 flutter doctor正常会出现类似于下面的内容.

[-] Android toolchain - develop for Android devices
    • Android SDK at /Users/obiwan/Library/Android/sdk
    ✗ Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
    • Try re-installing or updating your Android SDK,
      visit https://flutter.io/setup/#android-setup for detailed instructions.
复制代码

5.安装Android Studio

安装Android Studio主要目的是为了使用安卓虚拟机,具体安装详情可以参考React Native官网和Android Studio官网.

6.androidStudio 环境变量

装完Android Studio后主文件夹下会多出 Android SDK的文件路径. 并将以下内容放到用户环境变量中,注意第一行的文件路径要和实际路径对应.

export ANDROID_HOME=/home/name/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
复制代码

7.再次运行 flutter doctor,会提示需要安装的其他软件或进一步需要执行的任务,具体按照提示运行安装命令.最后安装成功的项至少需要以下内容.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.2.1, on Linux, locale zh_CN.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK  
    version 28.0.3)
[!] Android Studio (version 3.3)
    ✗ Flutter plugin not installed; this adds Flutter specific
      functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.33.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.
复制代码

7.Android Studio配置虚拟机.

打开Android Studio,打开AVD Manager,点击create virtual devices,创建虚拟设备,创建的设备有基于ARM,x86,x86_64的虚拟设备.基于ARM的虚拟设备相当卡,所以不要选择ARM.

8.安装KVM.

vscode创建一个flutter项目,按F5,选择运行的虚拟设备,发现提示错误:x86虚拟设备需要安装kvm.因为x86需要虚拟机支持.

检查本机是否满足虚拟机要求:

$ egrep -c '(vmx|svm)' /proc/cpuinfo
4
复制代码

安装kvm

$ sudo apt-get install qemu-kvm
$ sudo adduser yourname kvm
$ sudo apt-get install libvirt-bin ubuntu-vm-builder bridge-utils
$ sudo adduser yourname libvirtd
复制代码

如果提示adduser:"libvirtd"组不存在。则需要添加"libvirtd"组后再运行"$ sudo adduser yourname libvirtd".

$ sudo addgroup libvirtd
复制代码

检查是否安装成功

$ sudo virsh -c qemu:///system list
 Id    Name                           State
----------------------------------------------------
复制代码

最后再次运Flutter项目,运行成功后就可以自己玩了.

转载于:https://juejin.im/post/5cb45264e51d456e720778f3

你可能感兴趣的:(移动开发,运维,嵌入式)