初學(xué)Flutter,按照官網(wǎng)提示搭建完環(huán)境,新建一個(gè)first_flutter_app, 開開信心的Run,然后報(bào)錯(cuò)了:
Error running Gradle
* 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.
看到這個(gè)錯(cuò)誤 一臉蒙蔽,都是按照操作來走的,沒啥問題,不過可以定位到 肯定是gradle那里出問題。網(wǎng)上搜了下,發(fā)現(xiàn)項(xiàng)目的gradle 文件里面:
buildscript {
repositories {
// 需要翻墻下載
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
// 需要翻墻下載
google()
jcenter()
}
}
下載某些文件是需要翻墻才可以下載,所以我們?cè)谶\(yùn)行的時(shí)候會(huì)報(bào)錯(cuò)。修改如下:
用阿里云的鏡像文件 解決無法翻墻下載的問題
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' }
}
}
這時(shí)候你以為修改完了嗎? 沒有還需要修改Flutter 下邊的 gradle文件,
打開Flutter sdk目錄,找到如下地址:
flutter? ? ?packages? ? ?flutter_tools? ? ?gradle
打開 flutter.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'
}
}
這個(gè)時(shí)候在運(yùn)行項(xiàng)目,可以正確運(yùn)行了。