Android Studio Gradle 更换阿里云镜像的方法

Radinka ·
更新时间:2024-09-20
· 857 次阅读

使用 Android Studio 开发时经常遇到编译卡住的问题,原因是 Gradle 下载依赖资源过慢。没办法,有长城在,还是得换镜像。

同样,这是个普遍存在的问题,我们希望可以对它进行全局配置。在 .gradle (路径参考 C:\Users\username\.gradle )目录下新增 init.gradle 文件,内容如下:

allprojects{ repositories { def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public' def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter' all { ArtifactRepository repo -> if(repo instanceof MavenArtifactRepository){ def url = repo.url.toString() if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) { project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL." remove repo } if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) { project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL." remove repo } } } maven { url ALIYUN_REPOSITORY_URL url ALIYUN_JCENTER_URL } } buildscript{ repositories { def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public' def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter' all { ArtifactRepository repo -> if(repo instanceof MavenArtifactRepository){ def url = repo.url.toString() if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) { project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL." remove repo } if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) { project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL." remove repo } } } maven { url ALIYUN_REPOSITORY_URL url ALIYUN_JCENTER_URL } } } }

如只需对单个项目进行配置,可以在项目根目录下的 build.gradle 文件中添加如下代码:

maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }

搞定,下载速度飞起~

到此这篇关于Android Studio Gradle 更换阿里云镜像的方法的文章就介绍到这了,更多相关Android Studio Gradle阿里云内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!

您可能感兴趣的文章:Android studio gradle环境变量配置教程详解关于Android Studio中安装和gradle的一些坑为Android Studio编写自定义Gradle插件的教程Android Studio手动配置Gradle的方法Android studio利用gradle打jar包并混淆的方法详解android studio 3.0 gradle 打包脚本配置详解详解Androidstudio3.0 关于Gradle报错的问题(小结)Android Studio3.6设置Gradle Offline Mode的方法解决Android studio3.6安装后gradle Download失败(构建不成功)



Android Studio studio 阿里云 方法 gradle 阿里 镜像 Android

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章
Farrah 2021-06-01
670
Daisy 2020-05-31
604