打开项目后突然发现编译不了了,提示大量jar包无法下载
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'name-of-the-project'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:4.1.1.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:4.1.1.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.1/gradle-4.1.1.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.1/gradle-4.1.1.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.google.gms:google-services:4.3.4.
Required by:
project :
> Could not resolve com.google.gms:google-services:4.3.4.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.google.firebase:firebase-crashlytics-gradle:2.4.1.
Required by:
project :
> Could not resolve com.google.firebase:firebase-crashlytics-gradle:2.4.1.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-crashlytics-gradle/2.4.1/firebase-crashlytics-gradle-2.4.1.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-crashlytics-gradle/2.4.1/firebase-crashlytics-gradle-2.4.1.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
点击连接后有些包可以下载,有些不能下载,所以怀疑是仓库出了问题,可以暂时替换成阿里云镜像仓库即可。
修改 build.gradle 如下
buildscript {
repositories {
maven {
url 'https://maven.aliyun.com/repository/google'
}
maven {
url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
url 'https://maven.aliyun.com/repository/public'
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// 其他构建脚本依赖
}
}
allprojects {
repositories {
maven {
url 'https://maven.aliyun.com/repository/google'
}
maven {
url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
url 'https://maven.aliyun.com/repository/public'
}
}
}