参照官网教程(这里)下载解压,以及设置环境变量便可。java
若是你是中国用户(固然了,咱们都是),参考这篇文章Using Flutter in China,设置一下中国的镜像。android
好比我用的是zsh,那个人设置以下:shell
export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
而后使用flutter doctor
检查一下环境,个人以下:macos
android studio
是绿勾勾,是由于我已经安装过Flutter插件了lutter doctor --android-licenses
,而后一路Y就行。安装官网的这篇文章使用AS建立项目,可是你会发现,卡在下面这个页面好久api
google了好久,获得一个答案,很暴力。maven
Waiting for another flutter command to release the startup lock...
错,解决办法是rm flutter/bin/cache/lockfile
在编译项目的时候,你会发现,又卡住了,以下图所示:gradle
广大网友们也踩过这些坑,google一通,无外乎以下:ui
修改android/build.gradle下的仓库地址google
repositories { // google() // jcenter() maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public'} } allprojects { repositories { // google() // jcenter() maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public'} } }
修改flutter安装目录下./packages/flutter_tools/gradle/flutter.gradle
文件,也是改一下仓库地址url
buildscript { repositories { //google() //jcenter() maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public'} } dependencies { classpath 'com.android.tools.build:gradle:3.5.0' } }
Gradle task 'assembleDebug' 结束后又报下面的错误
* What went wrong: Execution failed for task ':flutter:javaPreCompileDebug'. > Could not resolve all files for configuration ':flutter:debugCompileClasspath'. > Could not find io.flutter:flutter_embedding_debug:1.0.0-5b952f286fc070e99cf192775fa5c9dfe858b692. Required by: project :flutter > Could not find io.flutter:arm64_v8a_debug:1.0.0-5b952f286fc070e99cf192775fa5c9dfe858b692. Required by: project :flutter > Could not find io.flutter:x86_debug:1.0.0-5b952f286fc070e99cf192775fa5c9dfe858b692. Required by: project :flutter > Could not find io.flutter:x86_64_debug:1.0.0-5b952f286fc070e99cf192775fa5c9dfe858b692. Required by: project :flutter
我参考csdn这篇文章,修改了下图这几个文件:
# 父路径是/opt/flutter/packages/flutter_tools/gradle aar_init_script.gradle flutter.gradle resolve_dependencies.gradle
将https://storage.googleapis.com/download.flutter.io
换成http://download.flutter.io
(也能够是https://storage.flutter-io.cn/download.flutter.io
),修改内容以下图:
至此,终于编译成功了。
Performing hot reload... Syncing files to device Pixel 2... Reloaded 1 of 495 libraries in 584ms.