这几天在研究Retrofit 框架的使用,github上下载demo后,导入项目时报错 Error:SSL peer shut down incorrectly ,也是在网上查找了好多博客,最后总结一下这个问题的解决办法,希望对遇到同样问题的朋友们有所帮助:

我使用的Android Studio 版本为2.3.3,开始以为是版本问题,后来经过其他博主的文章发现并不是这个原因造成的。

其中文章最多的答案便是 对照着本地可运行项目的配置参数对应修改 ,但不甚明确,大概猜到需要修改的地方只有两处,即两个.gradle文件,Android Studio 2.3.3 对应的gradle版本最低是3.3,如果没有需要到 http://services.gradle.org/distributions

这个地址去下载对应的版本,然后放在对应的安装AS位置下的Gradle的包下(若不清楚放在哪个位置下,可自行百度),然后还需要在File--Setting 中,如下图做下设置,同样,在该项目的配置中再确定下版本。

 以上都修改完了,再次Builde。

我按照以上步骤修改完,依然还是报错,但是为什么呢,接下来就是需要修改两处的.gradle文件了(是因为Google的一个地址无法访问,所导致出现的这个问题):

我project中的gradle文件

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0"
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.google.com/' }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

只需要把 其中的

 maven {
            url 'https://maven.google.com/'
            name 'Google'
        }

改为

maven {
    url 'https://dl.google.com/dl/android/maven2/'
    name 'Google'
}
再次编译即可解决问题!

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐