Could not resolve all artifacts for configuration ':classpath'.

从Github上拉了一个项目,没法运行,按照正常逻辑

1、先更改 rootProject 下 build.gradle 文件中的

classpath 'com.android.tools.build:gradle:x.x.x'  // 版本和你新建项目一致

2、在改 gradle-wrapper.properties 文件中的 distributionUrl 值 ,同样与新建项目值对应

执行上面步骤后,按道理应该是可以了,但是还是报错

A problem occurred configuring root project 'xxxxxxx'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.2.1.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:3.2.1.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
               > Connect to repo.jfrog.org:443 [repo.jfrog.org/35.153.64.121, repo.jfrog.org/52.72.179.201] failed: Connection timed out: connect

估计是项目太老了

对比了一下新项目,在 rootProject 下 build.gradle 文件中的 更改如下

buildscript {
    repositories {
        jcenter()
        mavenLocal()   // 添加
        google()    // 添加
    }
    //......
    }
}


allprojects {
    repositories {
        jcenter()
        mavenLocal()  // 添加
        google()  // 添加
    }
}

在对应的位置添加代码重新 rebulid 一下就可以了,如果遇到上面问题可以尝试一下,不一定适用所有的项目,祝好!

转载于:https://www.jianshu.com/p/5a2f8020f8c6

猜你喜欢

转载自blog.csdn.net/weixin_33912638/article/details/91165135