遇到的异常:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\flutter_workspace\chapter4\android\app\build.gradle' line: 26
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not resolve all artifacts for configuration 'classpath'.
> Could not download kotlin-reflect.jar (org.jetbrains.kotlin:kotlin-reflect:1.3.41)
> Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-reflect/1.3.41/kotlin-reflect-1.3.41.jar'.
> Read timed out
* 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 3m 0s
Finished with error: Gradle task assembleDebug failed with exit code 1
二、解决方案:
出问题的位置:Android 项目 build.gradle 中
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
解决方法一:
科学上网
解决方法二:
找到fullter sdk 中这个路径下的文件:D:\tools\flutter\packages\flutter_tools\gradle\flutter.gradle
如下修改代码:
buildscript {
repositories {
google()
//jcenter()
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.5.0'
}
}
Android 项目中的build.gradle中使用的maven仓库也做修改:
maven{
url 'https://maven.aliyun.com/repository/jcenter'
}
maven{
url 'http://maven.aliyun.com/nexus/content/groups/public'
}
or
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'}
重新运行就可以了。