问题
Build file '/Users****/android/golf/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 resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72.
Required by:
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:aaptcompiler:4.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.lint:lint-gradle-api:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:gradle-api:4.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > androidx.databinding:databinding-compiler-common:4.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools.build:builder-model:4.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:sdk-common:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:common:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools.build:manifest-merger:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools.analytics-library:tracker:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.lint:lint-gradle-api:27.1.0 > com.android.tools.lint:lint-model:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:sdklib:27.1.0 > com.android.tools:repository:27.1.0
unspecified:unspecified:unspecified > com.android.tools.build:gradle:4.1.0 > com.android.tools.build:builder:4.1.0 > com.android.tools:sdk-common:27.1.0 > com.android.tools.analytics-library:shared:27.1.0
> Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.72/kotlin-stdlib-jdk8-1.3.72.pom'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.72/kotlin-stdlib-jdk8-1.3.72.pom'.
> Connect to repo.maven.apache.org:443 [repo.maven.apache.org/127.0.0.1, repo.maven.apache.org/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
最近Gradle又开始编译失败了,从日志上可以看出是下载不下来,每年总有那么一段时间要出这个问题,至于为什么就不知道了(因为xgbm)
想快速解决就直接科学上网,但是科学上网目前一般都要收点费用,毕竟天下免费的午餐越来越少了。
也试过其他的一些办法,比如把build.gradle中换成阿里云的源,
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
google()
mavenCentral()
但是也是不管用,可能部分项目是管用的吧,我项目是flutter的,里面有很多插件,每个插件都有自己的build.gradle文件,可能是这个原因,不管怎么把,总之是没有用。
以下是我最终的解决办法。
在本机的.gradle文件夹下创建一个init.gradle(本人是mac系统,这种方式可能不适合win系统的,win系统的好像是在.gradle文件夹下中init.d文件夹下创建init.gradle)并写入以下内容
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
}



