赞
踩
使用Android Studio Flamingo创建项目时,IDE默认下载Gradle 8.0,但是下载速度特别慢,或者直接下载失败
下载地址:https://services.gradle.org/distributions/gradle-8.0-bin.zip
下载地址:https://downloads.gradle.org/distributions/gradle-8.0-bin.zip
1.打开IDE设置,如下图
2.打开Build, Execution, Deployment -> Build Tools -> Gradle
提示:默认路径是C:\Users\<用户名>\.gradle
提示:其中ca5e32bp14vu59qr306oxotwh目录名称是Android Studio随机生成的,每个人都不一样
提示:有的人在ca5e32bp14vu59qr306oxotwh目录下存在gradle-8.0-bin.zip.part文件,请删除它。
提示:如果ca5e32bp14vu59qr306oxotwh目录下已经存在gradle-8.0-bin.zip.lck文件但是没有gradle-8.0-bin.zip.ok文件,那么可以将gradle-8.0-bin.zip.lck文件复制一份并重命名为gradle-8.0-bin.zip.ok即可
在手动安装Gradle完成后,发现Gradle一直在下载插件
com.android.application.gradle.plugin-8.0.2.pom,最后还报异常
Build file 'D:\work\android\workspace\SunnyWeather\build.gradle' line: 3 Plugin [id: 'com.android.application', version: '8.0.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. * Exception is: org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '8.0.2', apply: false] was not found in any of the following sources: - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:8.0.0') Searched in the following repositories: Google MavenRepo Gradle Central Plugin Repository at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:237) at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.lambda$resolvePluginRequests$3(DefaultPluginRequestApplicator.java:167) ...
1.错误原因
从报错日志看是项目的build.gradle文件的第3行报错了,如下图所示:
报的错误是找不到插件[id: ‘com.android.application’, version: ‘8.0.2’, apply: false]
2.原因分析
在国内访问Google的仓库、Maven中央仓库以及Gradle-Plugin仓库不稳定
3.解决
3.1添加国内镜像仓库,比如阿里云
在settings.gradle文件的pluginManagement闭包中的repositories闭包中添加以下代码用来添加阿里云镜像仓库
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/google' }
提示:pluginManagement闭包中的repositories闭包中添加的仓库用来下载插件
dependencyResolutionManagement闭包中的repositories闭包中添加的仓库用来下载依赖的jar包
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
3.2修改插件版本
由于阿里云仓库没有com.android.application版本为8.0.2的插件,所以需要修改插件版本为8.0.0
提示:如果org.jetbrains.kotlin.android版本为1.8.20的插件下载不下来,可以将版本改为1.8.0
3.3重新编译项目
阿里云仓库网址:https://developer.aliyun.com/mvn/guide
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。