背景
当我们安装好Android Studio之后,系统会自动检测Android SDK,如果没有安装会自动推荐安装,但是有时会出现安装失败的情况。
现象及解决方案
1.当我们打开Android SDK Manager会自动检测系统环境,在Android SDK Manager Log中会有以下提示,大致意思是SSL证书认证不通过(红色加粗字体所示)。
Fetching http://dl.google.com/android/repository/addons_list-2.xml
Fetched Add-ons List successfully
Fetching URL: http://dl.google.com/android/repository/repository-11.xml
Done loading packages.
Fetching URL: https://dl.google.com/android/repository/repository-11.xml
Failed to fetch URL https://dl.google.com/android/repository/repository-11.xml, reason: SSLPeerUnverified peer not authenticated
Done loading packages.
2.打开Android SDK Manager Setting设置项(Tools->Options),如下图所示,勾选Force https://...sources to be fetched using http://...配置项。
通过Packages->Reload重新加载,在Android SDK Manager Log中会有以下提示,大致意思是连接http://dl.google.com服务器失败(红色加粗字体所示)。
Fetching http://dl.google.com/android/repository/addons_list-2.xml
Fetched Add-ons List successfully
Fetching URL: http://dl.google.com/android/repository/repository-11.xml
Done loading packages.
Fetching http://dl.google.com/android/repository/addons_list-2.xml
Failed to fetch URL http://dl.google.com/android/repository/addons_list-2.xml, reason: Connection to http://dl.google.com refused
Fetched Add-ons List successfully
Fetching URL: http://dl.google.com/android/repository/repository-11.xml
Failed to fetch URL http://dl.google.com/android/repository/repository-11.xml, reason: HttpHostConnect Connection to http://dl.google.com refused
Done loading packages.
Fetching URL: http://dl.google.com/android/repository/repository-11.xml
Failed to fetch URL http://dl.google.com/android/repository/repository-11.xml, reason: HttpHostConnect Connection to http://dl.google.com refused
Done loading packages.
3.修改主机的配置文件,打开c:\windows\system32\drivers\etc\hosts文件,如下图所示在最后添加
203.208.46.146 www.google.com
74.125.113.121 developer.android.com
203.208.50.33 dl.google.com
108.177.125.91 dl-ssl.google.com
通过Packages->Reload重新加载,在Android SDK Manager Log中会有以下提示,这就代表连接服务器成功,可以正常下载Android SDK工具。
Fetching URL: https://dl.google.com/android/repository/repository-11.xml
Validate XML: https://dl.google.com/android/repository/repository-11.xml
Parse XML: https://dl.google.com/android/repository/repository-11.xml
Found SDK Platform Android R Preview, revision 2
Found SDK Platform Android 10, API 29, revision 4
Found SDK Platform Android 9, API 28, revision 6
Found SDK Platform Android 8.1.0, API 27, revision 3
Found SDK Platform Android 8.0.0, API 26, revision 2...
4.有时因为连接服务器的IP地址会改变,造成连接谷歌服务器失败。此时我们可以通过多个地点ping[dl.google.com]服务器-网站测速-站长工具该网址搜索
"www.google.com"/"developer.android.com"/"dl.google.com"/"dl-ssl.google.com"服务器的IP地址。
5.查询方法
将"www.google.com"/"developer.android.com"/"dl.google.com"/"dl-ssl.google.com"服务器输入搜索框中,下面就会输出可连接的IP地址。