前言
最近又撿起flutter.以前寫(xiě)的demo一運(yùn)行,還出現(xiàn)了許多問(wèn)題.重新捋一遍
說(shuō)真的,這flutter和android stuido越升級(jí)問(wèn)題越多.以前可沒(méi)這么多問(wèn)題.
建議:
當(dāng)你跑不起來(lái)又沒(méi)什么報(bào)錯(cuò)信息的時(shí)候,建議用android stuido直接打開(kāi)flutter工程中的android目錄跑一下.報(bào)錯(cuò)會(huì)比較完全.
一:需要下載的
1.android studio或者vscode開(kāi)發(fā)工具(最好是用Mac.不然沒(méi)法寫(xiě)iOS)
2.Flutter SDK 下載地址
如果網(wǎng)站打不開(kāi)就直接這樣下
或者這里下載
二:需要配置的環(huán)境變量:
1.JAVA_HOME:
2.ANDROID_HOME:
3.PATH中要添加環(huán)境變量:
以上路徑僅供參考.
4.NO_PROXY
這個(gè)對(duì)于部分電腦,需要添加,否則不能熱發(fā)布
5.PUB_HOSTED_URL
https://pub.flutter-io.cn
6.FLUTTER_STORAGE_BASE_UR
https://storage.flutter-io.cn
一些問(wèn)題解決辦法:
1.運(yùn)行后白屏,一直沒(méi)反應(yīng)
如果你的android studio
版本是4.0
以上,建議換回3.5
這個(gè)其實(shí)不是android studio的問(wèn)題.是flutter插件的問(wèn)題.我試過(guò)用vscode也存在這個(gè)問(wèn)題.
3.5
對(duì)應(yīng)的Flutter
插件版本是v44
問(wèn)題解決.
2:Could not find an option named "androidx". Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.
創(chuàng)建flutter項(xiàng)目報(bào)個(gè)上面錯(cuò)誤信息瓢姻,flutter sdk 版本過(guò)低秋柄,下載最新版試試,
比如v1.20.4
3:Finished with error: Gradle task assembleDebug failed with exit code 1
不用猶豫.直接打開(kāi)android目錄跑一下,報(bào)錯(cuò)會(huì)比較全面.
4:Could not find an option named "androidx". Run 'flutter -h' (or 'flutter -h') for available flutter commands and options.
查資料說(shuō)是flutter版本過(guò)低,但其實(shí)升級(jí)并沒(méi)什么用
5:導(dǎo)入他人項(xiàng)目.記得先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
這個(gè)問(wèn)題是網(wǎng)絡(luò)問(wèn)題,下不了依賴包.具體原因是因?yàn)镠TTPS的問(wèn)題.
Android studio需要添加證書(shū),但是操作有點(diǎn)沒(méi)法,而且好像沒(méi)啥用.
我的做法:
修改這個(gè)
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' }
}
}