美文网首页Flutter技术
AS工程:kotlin plugin无法加载的问题

AS工程:kotlin plugin无法加载的问题

作者: 清风白露青苔 | 来源:发表于2020-06-08 15:07 被阅读0次

    自己在编译AS工程时发现kotlin plugin插件一直无法正常加载,经过收索查找后解决,再次记录分享下,希望能帮助到大家

    编译问题

    > 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
    也有可能是:
    request timeout
    SSL peer shut down incorrectly

    不管怎么提示,大部分都是网络有问题,没有办法从网上获取 .pom/jar 文件.

    • 将url复制到浏览器中访问发现,看下.pom/jar文件是否可以正常下载。

    最后的问题可能是:

    正常情况下AS仓库配置为:

      google()
      jcenter()
    

    那么国内由于墙的存在是无法访问国外的地址的,需要翻墙才行,因为国内通道的不稳定,有时候即使翻墙也是不成功的,会报超时,ssl等问题。

    如果翻墙仍然不能解决:
    那就不要翻墙了,这时候我们就需要配置镜像来解决这个问题。
    (为了提高jar包的下载速度也可以配置)配置的方法就是在根build.gradle中添加镜像仓库,一般我们选择阿里的 http://maven.aliyun.com/nexus/content/groups/public/

    buildscript {
        ext.kotlin_version = '1.3.72'
        ext.coroutine_version = '1.0.0'
        repositories {
            google()
            //jcenter()
            maven { url 'https://maven.aliyun.com/repository/google' }
            maven { url 'https://maven.aliyun.com/repository/jcenter' }
            maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.5.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    allprojects {
        repositories {
            google()
            //jcenter()
            maven { url 'https://maven.aliyun.com/repository/google' }
            maven { url 'https://maven.aliyun.com/repository/jcenter' }
            maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
        }
    }
    

    如果发现配置镜像地址后仍然有问题:
    很大可能是由于配置了代理导致的。

    1.打开AndroidStudio的 HttpProxy界面:查看是否有代理配置

    2.查看本地Gradle的全局属性配置文件gradle.properties
    C:\Users\xxx \ .gradle\gradle.properties

    systemProp.https.proxyPort=8580
    systemProp.http.proxyHost=127.0.0.1
    systemProp.https.proxyHost=127.0.0.1
    systemProp.http.proxyPort=8580
    

    如果配置了代理,毫无疑问,这个代理服务器是不好用的。
    删除gradle.properties 文件中的代理配置,同步工程。

    思考总结:
    遇到问题要把思路捋清,分析原因并解决,而不是盲目的去网上搜索答案。锻炼自己思考问题、分析问题、解决问题的能力。

    相关文章

      网友评论

        本文标题:AS工程:kotlin plugin无法加载的问题

        本文链接:https://www.haomeiwen.com/subject/bafrtktx.html