在Android Studio中,通过设置腾讯镜像和代理解决无法下载gradle和gradle.plugin等组件的问题

发布于:2024-12-18 ⋅ 阅读:(89) ⋅ 点赞:(0)

诸神缄默不语-个人CSDN博文目录

这个出现在刚打开项目的时候,下载一堆必要的组件……

无法下载gradle的报错信息是:Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-8.9-bin.zip'. Reason: java.net.SocketTimeoutException: Read timed out

无法下载gradle.plugin和其他一大堆的报错信息是:(这个报错信息只是无法下载gradle.plugin,但其实这一步AS会同时下载一大堆组件)

Build file 'D:\codes\ascodes\daily_timer\build.gradle.kts' line: 2

Plugin [id: 'com.android.application', version: '8.7.2', apply: false] was not found in any of the following sources:

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '8.7.2', apply: false] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:8.7.2')
  Searched in the following repositories:
    Google
    MavenRepo
    Gradle Central Plugin Repository
	at org.gradle.plugin.use.resolve.internal.PluginResolutionResult.getFound(PluginResolutionResult.java:112)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolvePluginRequest(DefaultPluginRequestApplicator.java:192)
	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:97)

后面的略,总之有很长的重复内容。

解决方案是:

  1. 其实这几个网站国内都能上,只要网络是正常的,就可以考虑直接等着,反复重试反复重试……
  2. 在gradle/wrapper/gradle-wrapper.properties文件中,将distributionUrl改成https\://mirrors.cloud.tencent.com/gradle/gradle-8.9-all.zip
  3. 设置代理:在C:\Users\用户名.gradle\gradle.properties文件中,增加如下内容:
    systemProp.http.proxyHost=127.0.0.1
    systemProp.https.proxyHost=127.0.0.1
    systemProp.https.proxyPort=7890
    systemProp.http.proxyPort=7890
    
    bro我相信大家都已经对7890这个端口号十分熟悉了,我就不用讲解这个代理是从哪里冒出来的了吧!

大家熟悉的设置镜像方法对这么新的组件好像基本没啥用,腾讯和阿里好像都没有这么新的组件……大概是降本增效给降得没有本来维护镜像了吧。


网站公告

今日签到

点亮在社区的每一天
去签到