前言
最近又撿起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' }
}
}