Android Studio Gradle Sync 报错:Gr

2018-07-27  本文已影响0人  滑稽_e07a

最近在做一个 Android 项目,一次 Gradle Sync 报错:

Gradle sync failed: Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.20/kotlin-gradle-plugin-1.3.20.pom'. Received status code 405 from server: Method Not Allowed

Project 的 Gradle 脚本如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

ext.kotlin_version ='1.3.20'

    repositories {

google()

jcenter()

}

dependencies {

classpath'com.android.tools.build:gradle:3.2.0-alpha01'

        classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

    }

}

allprojects {

repositories {

google()

jcenter()

}

}

task clean(type: Delete) {

deleterootProject.buildDir

}

由于报错是 GET 请求失败,初步怀疑是网络问题,于是把 repositories 块的 google() 注释掉了。

网上搜了一下,说是国内 google 的库访问不了, repositories 块加了这一句:

maven { url"https://dl.google.com/dl/android/maven2/" }

再次 Sync ,又报错:

Gradle sync failed: Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.20/kotlin-gradle-plugin-1.3.20.pom'. Received status code 405 from server: Method Not Allowed

https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.3.20/kotlin-gradle-plugin-1.3.20.pom 用浏览器打开,看到以下信息:

{

  "errors" : [ {

    "status" : 404,

    "message" : "Could not find resource"

  } ]

}

看到 404 错误,于是把原来的链接删了后面一部分,剩下“https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin”,再打开,看到里面有很多版本号,看了一下,里面没有 1.3.20 版本(估计是以前手残把 ext.kotlin_version 设成了 1.3.20 ,本来是 1.2.20 的,导致了上面的 Sync 错误),于是把:

ext.kotlin_version ='1.3.20'

改成:

ext.kotlin_version ='1.2.20'

再 Sync 一下,错误没了。

看来,细节决定成败。于是以后写代码更加细心了。

总之,问题解决了,编程愉快!

上一篇下一篇

猜你喜欢

热点阅读