Andorid Stdio 在 加载gradle时特别慢 的解决办法

Andorid Stdio 在 加载gradle时特别慢 的解决办法

问题描述

在进行RK3566 Android 的定制中 遇到一个问题,在使用android stdio开发客制版浏览器的时候,在加载gradle时特别慢,半个多小时还没加载完,最终在网上找到了解决方法,记录一下。

Andorid Stdio 在 加载gradle时特别慢 的解决办法_第1张图片

解决方案如下

使用阿里提供的仓库进行下载依赖包。阿里仓库网站,包含jcenter、maven、Google仓库,网站是 https://developer.aliyun.com/mvn/guide。

在计算机的c盘的用户目录下找到.gradle,在文件夹内新建文件init.gradle 文件。目录结构如下

在init.gradle加入如下代码,并保存

  • gradle.projectsLoaded {
        rootProject.allprojects {
            buildscript {
                repositories {
                    def JCENTER_URL = 'https://maven.aliyun.com/repository/public'
                    def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
                    def NEXUS_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://jcenter.bintray.com/')) {
                                project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
                                println("buildscript ${repo.url} replaced by $JCENTER_URL.")
                                remove repo
                            }
                            else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                                project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
                                println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
                                remove repo
                            }
                            else if (url.startsWith('https://repo1.maven.org/maven2')) {
                                project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                                println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
                                remove repo
                            }
                        }
                    }
                    jcenter {
                        url JCENTER_URL
                        allowInsecureProtocol = true
                    }
                    google {
                        url GOOGLE_URL
                        allowInsecureProtocol = true
                    }
                    maven {
                        url NEXUS_URL
                        allowInsecureProtocol = true
                    }
                }
            }
            repositories {
                def JCENTER_URL = 'https://maven.aliyun.com/repository/public'
                def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
                def NEXUS_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://jcenter.bintray.com/')) {
                            project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
                            println("buildscript ${repo.url} replaced by $JCENTER_URL.")
                            remove repo
                        }
                        else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                            project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
                            println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
                            remove repo
                        }
                        else if (url.startsWith('https://repo1.maven.org/maven2')) {
                            project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                            println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
                            remove repo
                        }
                    }
                }
                jcenter {
                    url JCENTER_URL
                    allowInsecureProtocol = true
                }
                google {
                    url GOOGLE_URL
                    allowInsecureProtocol = true
                }
                maven {
                    url NEXUS_URL
                    allowInsecureProtocol = true
                }
            }
        }
    }
    
    

然后再把android stdio 重启后发现之前慢吞吞的下载 已经像是吃了菠菜的大力水手一样给力了。

最终结果

Andorid Stdio 在 加载gradle时特别慢 的解决办法_第2张图片

最后将android stdio 重启后发现之前慢吞吞的加载,已经像是吃了菠菜的大力水手一样给力了。

学艺不精,有什么问题希望各位大佬指正。

参考链接

https://blog.csdn.net/u014687242/article/details/121132481

你可能感兴趣的:(android)