flutter起步时遇到的坑

最近要写app,看很多人用flutter,查了下资料,这个是谷歌出品的框架,谷歌出品必属精品,于是毫无犹豫地就开始搭环境了,但是没想到。。搭环境如此曲折,以此记录一下。

  1. 按照官网步骤,一顿操作下来猛如虎,到flutter doctor的时候就卡住了, 显示如下错误
? Unable to locate Android SDK.Install Android Studio from: [https://developer.android.com/studio/index.html]

这个是Android studio编辑器的错误,无法导入Android sdk,于是从网上下载了sdk放到本地,并在setting中设置路径,如下图所示
flutter起步时遇到的坑
文章图片

这里有个小技巧,developer.android.com在国内无法正常访问。解决方案将android.com替换为android.google.cn即可。
显示如下信息表示当前没有真实设备连上电脑,不用理会~毕竟之后可以用模拟器调试不是~所以这里只是警告而已
[!] Connected device ! No devices available

  1. flutter doctor命令都显示成功之后,满怀期待的打开Android studio,没想到一打开就给我当头一棒,又报错了,报错信息如下
    flutter起步时遇到的坑
    文章图片

    解决方法:
    点cancel,之后点next,在之后的界面会有安装sdk的步骤,耐心等着安装完即可。
  2. 安装Android studio的dart和flutter插件,下载flutter插件的时候提示dart插件下载不了
【flutter起步时遇到的坑】解决方法:
先安装dart插件,再安装flutter插件即可
  1. 创建flutter项目的时候,提示
flutter sdk path not given

解决方法:“File”->“Setting”->“Languages & frameworks”->“Flutter”选择安装路径
  1. flutter启动一直卡在running Gradle task 'assembleDebug'
解决方法:
  1. 修改Gradle的maven的地址,修改为阿里云的镜像地址
  2. 修改项目中android/build.gradle文件,修改之后:
buildscript { ext.kotlin_version = '1.3.50' 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' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }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' } } }rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') }task clean(type: Delete) { delete rootProject.buildDir }

  1. 改Flutter的配置文件, 该文件在Flutter安装目录/packages/flutter_tools/gradle/flutter.gradle
  2. 下载gradle到本地,配置gradle为本地地址(file->setting->gradle)
flutter起步时遇到的坑
文章图片

grade下载地址https://www.jianshu.com/p/d9329117aa2f
  1. 修改gradle.properties(android/gradle/wrapper)
#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=file\:/Users/juan/.gradle/wrapper/dists/gradle-6.0-all.zip

参考资料:
https://blog.csdn.net/u013227399/article/details/103125826
https://blog.csdn.net/jinglinggg/article/details/105383270
https://www.jianshu.com/p/171a9660e1f9
https://www.zhihu.com/question/372649730

    推荐阅读