前言
最近又捡起flutter.以前写的demo一运行,还出现了许多问题.重新捋一遍
说真的,这flutter和android stuido越升级问题越多.以前可没这么多问题.
建议:
当你跑不起来又没什么报错信息的时候,建议用android stuido直接打开flutter工程中的android目录跑一下.报错会比较完全.
一:需要下载的
1.android studio或者vscode开发工具(最好是用Mac.不然没法写iOS)
2.Flutter SDK 下载地址
如果网站打不开就直接这样下

或者这里下载
二:需要配置的环境变量:
1.JAVA_HOME:

2.ANDROID_HOME:

3.PATH中要添加环境变量:

以上路径仅供参考.
4.NO_PROXY
这个对于部分电脑,需要添加,否则不能热发布

5.PUB_HOSTED_URL
https://pub.flutter-io.cn
6.FLUTTER_STORAGE_BASE_UR
https://storage.flutter-io.cn
一些问题解决办法:
1.运行后白屏,一直没反应
如果你的android studio
版本是4.0
以上,建议换回3.5
这个其实不是android studio的问题.是flutter插件的问题.我试过用vscode也存在这个问题.
3.5
对应的Flutter
插件版本是v44

问题解决.
2:Could not find an option named "androidx". Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.
创建flutter项目报个上面错误信息,flutter sdk 版本过低,下载最新版试试,
比如v1.20.4
3:Finished with error: Gradle task assembleDebug failed with exit code 1
不用犹豫.直接打开android目录跑一下,报错会比较全面.


4:Could not find an option named "androidx". Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.
查资料说是flutter版本过低,但其实升级并没什么用
5:导入他人项目.记得先clean一下
flutter clean
6:Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
这个问题是网络问题,下不了依赖包.具体原因是因为HTTPS的问题.
Android studio需要添加证书,但是操作有点没法,而且好像没啥用.
我的做法:

修改这个
build.gradle
文件
附上代码
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
maven { url 'http://maven.aliyun.com/repository/google'}
maven { url 'http://maven.aliyun.com/repository/jcenter'}
maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
jcenter { url 'http://jcenter.bintray.com' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
maven { url 'http://maven.aliyun.com/repository/google'}
maven { url 'http://maven.aliyun.com/repository/jcenter'}
maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
jcenter { url 'http://jcenter.bintray.com' }
}
}
网友评论