编译OSS Android SDK出错,javax.net.ssl.SSLException: Received fatal alert: protocol_version

在编译OSS Jar时按照官方步骤操作如下:

# clone工程
$ git clone https://github.com/aliyun/aliyun-oss-android-sdk.git

# 进入目录
$ cd aliyun-oss-android-sdk/oss-android-sdk/

# 执行打包脚本,要求jdk 1.7
$ ../gradlew releaseJar

# 进入打包生成目录,jar包生成在该目录下
$ cd build/libs && ls

 

结果编译报错:

root@host:/home/develop/aliyun-oss-android-sdk/oss-android-sdk# ../gradlew releaseJar
Downloading https://services.gradle.org/distributions/gradle-3.3-all.zip

Exception in thread "main" java.lang.RuntimeException: javax.net.ssl.SSLException: Received fatal alert: protocol_version
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
    at org.gradle.wrapper.Install.createDist(Install.java:47)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
    at org.gradle.wrapper.Download.download(Download.java:45)
    at org.gradle.wrapper.Install$1.call(Install.java:60)
    at org.gradle.wrapper.Install$1.call(Install.java:47)
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
    ... 3 more

 

这是因为 jdk1.7 默认使用的是TLS1.0,

使用  curl -v https://services.gradle.org  可以看到网站使用的是 TLS1.2

 

root@host:/home/develop/aliyun-oss-android-sdk/oss-android-sdk# curl -v https://services.gradle.org
* Rebuilt URL to: https://services.gradle.org/
*   Trying 104.18.190.9...
* Connected to services.gradle.org (104.18.190.9) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 592 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_ECDSA_AES_128_GCM_SHA256
*      server certificate verification OK
*      server certificate status verification SKIPPED
*      common name: gradle.org (matched)
*      server certificate expiration date OK
*      server certificate activation date OK
*      certificate public key: EC
*      certificate version: #3
*      subject: C=US,ST=CA,L=San Francisco,O=Cloudflare\, Inc.,CN=gradle.org
*      start date: Wed, 25 Dec 2019 00:00:00 GMT
*      expire date: Fri, 09 Oct 2020 12:00:00 GMT
*      issuer: C=US,ST=CA,L=San Francisco,O=CloudFlare\, Inc.,CN=CloudFlare Inc ECC CA-2
*      compression: NULL
* ALPN, server accepted to use http/1.1
> GET / HTTP/1.1
> Host: services.gradle.org
> User-Agent: curl/7.47.0
> Accept: */*

 

解决办法 使用jdk1.8编译

 

posted @ 2020-03-20 10:54  九月彭于晏  阅读(2370)  评论(0编辑  收藏  举报