Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.(因Gradle代理设置问题导致)

获取 kotlin-gradle-plugin 失败问题

  • 现象
  • 原因
  • 解决
  • 思考

现象

在AndroidStudio中新建一个项目时出现:

A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.
     Required by:
         project :
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'. Received status code 400 from server: Bad Request
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.
         > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'.
            > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'. Received status code 400 from server: Bad Request

无法成功编译项目。

原因

在MyApplication项目的错误信息中有这样的信息:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.
     Required by:
         project :
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'. 
            Received status code 400 from server: Bad Request
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.
         > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'.
            > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.60/kotlin-gradle-plugin-1.3.60.pom'.
             Received status code 400 from server: Bad Request

注意看信息中的提示内容:Received status code 400 from server: Bad Request
从这里可以知道,应该是网络的问题,没有办法从网上获取 .pom 文件。

原因已经找到了,就是:网络有问题。
但是网络到底哪里出了问题,还需要进一步的调查:

  • 将url复制到浏览器中访问发现,这个.pom文件是可以正常下载的。这说明,我们的网络环境应该是没问题的。那么就可以知道,问题出在Gradle或者AndroidStudio的网络环境配置方面。
  • 打开AndroidStudio的 HttpProxy界面:
    Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.(因Gradle代理设置问题导致)_第1张图片
    发现并无异常。
  • 查看本地Gradle的全局属性配置文件gradle.properties
    Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.(因Gradle代理设置问题导致)_第2张图片
    发现配置了代理。毫无疑问,这个代理服务器是不好用的。因为这个明显看出来是更新AndroidSDK时用的国内镜像代理,跟Gradle没啥关系。

解决

删除gradle.properties 文件中的代理配置,同步工程,问题解决。
Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60.(因Gradle代理设置问题导致)_第3张图片

思考

通过这个问题的分析过程,我得到的启示是:遇到问题要把思路捋清,找对原因并解决,而不是盲目的去网上搜索答案。有的时候自己一步一步去发现问题解决问题的速度可能要比直接去搜索答案更快,而且于此同时还锻炼了自己思考问题、分析问题、解决问题的能力。

你可能感兴趣的:(Android,android,android,studio)