最近要写app,看很多人用flutter,查了下资料,这个是谷歌出品的框架,谷歌出品必属精品,于是毫无犹豫地就开始搭环境了,但是没想到。。搭环境如此曲折,以此记录一下。
- 按照官网步骤,一顿操作下来猛如虎,到
flutter doctor
的时候就卡住了, 显示如下错误
? Unable to locate Android SDK.Install Android Studio from: [https://developer.android.com/studio/index.html]
这个是Android studio编辑器的错误,无法导入Android sdk,于是从网上下载了sdk放到本地,并在setting中设置路径,如下图所示
文章图片
这里有个小技巧,
developer.android.com
在国内无法正常访问。解决方案将android.com
替换为android.google.cn
即可。显示如下信息表示当前没有真实设备连上电脑,不用理会~毕竟之后可以用模拟器调试不是~所以这里只是警告而已
[!] Connected device
! No devices available
flutter doctor
命令都显示成功之后,满怀期待的打开Android studio,没想到一打开就给我当头一棒,又报错了,报错信息如下
文章图片
解决方法:
点cancel,之后点next,在之后的界面会有安装sdk的步骤,耐心等着安装完即可。- 安装Android studio的dart和flutter插件,下载flutter插件的时候提示dart插件下载不了
先安装dart插件,再安装flutter插件即可
- 创建flutter项目的时候,提示
flutter sdk path not given
解决方法:“File”->“Setting”->“Languages & frameworks”->“Flutter”选择安装路径
- flutter启动一直卡在running Gradle task 'assembleDebug'
- 修改Gradle的maven的地址,修改为阿里云的镜像地址
- 修改项目中
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
}
- 改Flutter的配置文件, 该文件在
Flutter安装目录/packages/flutter_tools/gradle/flutter.gradle
- 下载gradle到本地,配置gradle为本地地址(file->setting->gradle)
文章图片
grade下载地址https://www.jianshu.com/p/d9329117aa2f
- 修改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
推荐阅读
- 回顾 Flutter 2021 重要时刻,奉上虎年红包封面喜迎新年!
- Flutter实现左侧边栏导航
- 如何在 Flutter 创建一个后台任务
- Flutter Convex Bottom 底部导航
- Flutter动态化框架Thresh
- 基于 Riverpod 的 Flutter 状态管理
- Flutter 2022 产品路线图发布
- Flutter 插件库
- Windows Running “flutter pub get“ in XXX卡死
- Flutter之下拉刷新,上拉加载更多