本文主要是介绍【问题解决】Android Studio Jellyfish新建Kotlin项目后Gradle Sync及Maven下载很慢,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
创建新项目之后,Gradle Sync和Build都很慢,因为下载Gradle和Maven等工具。
代码默认配置
settings.gradle.kts
pluginManagement {repositories {google {content {includeGroupByRegex("com\\.android.*")includeGroupByRegex("com\\.google.*")includeGroupByRegex("androidx.*")}}mavenCentral()gradlePluginPortal()}
}dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {google()mavenCentral()}
}
gradle-wrapper.properties
原本是gradle官网的
#Thu May 23 21:59:57 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
解决方案
1、首先把gradle的地址替换成国内镜像源,会很快下载完gradle
gradle ->wrapper-> gradle-wrapper.properties配置文件
- 原始:https\://services.gradle.org/distributions/gradle-8.6-bin.zip
- 替换成 https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.6-bin.zip
#Thu May 23 21:59:57 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://mirrors.aliyun.com/macports/distfiles/gradle/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-
阿里云镜像 Gradle下载地址(新):macports-distfiles-gradle安装包下载_开源镜像站-阿里云
可以在上述网站复制对应版本的链接,替换到settings.gradle中的distributionUrl。
但还是存在maven很慢的问题,是因为settings.gradle中仓库源配置问题。
2、修改settings.gradle.kts仓库
添加maven在前面
maven { url=uri( "https://maven.aliyun.com/repository/central") }maven { url=uri( "https://maven.aliyun.com/repository/public") }maven { url=uri( "https://maven.aliyun.com/repository/google") }maven { url=uri( "https://maven.aliyun.com/repository/gradle-plugin") }
问题过程记录
软件版本 Android Studio Jellyfish | 2023.3.1
新建项目,New Project -> Empty Activity
填写项目信息选择kt语言后Finish,同步项目环境配置。
同步了好久
两小时都没好
最后还是停掉了,可以看到Maven一直很耗时。
新增url但注释原本的配置会报错
Plugin [id: 'com.android.application', version: '8.4.0', apply: false] was not found in any of the following sources:
* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '8.4.0', 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.4.0')
Searched in the following repositories:
maven(https://maven.aliyun.com/repository/central)
然后去掉原本配置注释,还是会用到service.gradle.org下载很慢
可是第二天电脑重启之后,就sync没问题了,直接都能build成功,就是ide会显示,看着是本地环境路径gradle问题,gradle-wrapper多了很多红线,开机也看到说在C盘User下载gradle之类的。
这篇关于【问题解决】Android Studio Jellyfish新建Kotlin项目后Gradle Sync及Maven下载很慢的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!