AndroidStudioGradle更换阿里云镜像的方法-创新互联

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

创新互联科技有限公司专业互联网基础服务商,为您提供雅安移动机房高防服务器租用,成都IDC机房托管,成都主机托管等互联网服务。

同样,这是个普遍存在的问题,我们希望可以对它进行全局配置。在 .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
      }
    }
  }
}

网站名称:AndroidStudioGradle更换阿里云镜像的方法-创新互联
标题路径:https://www.cdcxhl.com/article34/dpgose.html

成都网站建设公司_创新互联,为您提供网站制作网站内链云服务器做网站静态网站网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

小程序开发