Error running Gradle 錯誤
這個錯誤是在重裝環境後出現的,重裝並創建第一個項目後flutter run的時候爆出了這個錯,* Error running Gradle:
ProcessException: Process "xxx/first_flutter_app/android/gradlew" exited abnormally:
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Build file 'xxx/first_flutter_app/android/app/build.gradle' line: 25
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all files for configuration 'classpath'.
> Could not find lint-gradle-api.jar (com.android.tools.lint:lint-gradle-api:26.1.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/lint/lint-gradle-api/26.1.2/lint-gradle-api-26.1.2.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Command: xxx/first_flutter_app/android/gradlew app:properties
Finished with error: Please review your Gradle project setup in the android/ folder.
從這裏面當時並沒看出來是什麼問題,但可以確定gradle出的問題,後來網上查了下發現是下載文件時候需要翻牆,否則有些文件就下載不了出現了這個問題。
解決辦法有兩個
- 第一個是翻牆這肯定是不方便的。
- 第二個解決辦法就是使用阿里雲的鏡像文件。
下面介紹第二種解決辦法,首先找到Android中的gradle文件,將代碼改爲下面格式
buildscript {
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.2.1'
}
}
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' }
}
}
第二步就是修改flutter sdk中的flutter.gradle文件,具體路徑爲fluttersdk目錄▸ packages ▸ flutter_tools ▸ gradle 這個文件的修改有兩種類型
第一種:
repositories{
google()
gcenter()
}
這種就按下面方式修改
repositories{
//google()
//gcenter()
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'}
}
還有一種情況
repositories {
jcenter()
maven {
url 'https://dl.google.com/dl/android/maven2'
}
這種就按下面方式修改
repositories {
//jcenter()
// maven {
// url 'https://dl.google.com/dl/android/maven2'
// }
maven{
url 'https://maven.aliyun.com/repository/jcenter'
}
maven{
url 'http://maven.aliyun.com/nexus/content/groups/public'
}
}
這樣就可以解決這個問題了