美文网首页
AndroidStudio中使用阿里云镜像仓库

AndroidStudio中使用阿里云镜像仓库

作者: 愿随风丶飘雪 | 来源:发表于2020-04-12 15:38 被阅读0次

在Android开发过程中,大家会经常遇到依赖文件下载不下来的情况,这是由于大部分依赖文件是放在过外的服务器上的,由于网络问题,很难下载下来,所以咱们阿里官方给咱们提供了国外文件的镜像给咱们使用

AndroidStudio下载配置镜像的地方是在项目的buidle.gradle中,如下图:

这是AndroidStudio默认的仓库地址:

image-20200412150741803.png
修改为阿里云镜像咱们只需要在这个文件的buildscript的repositories中和allprojects的repositories中加入阿里云镜像地址即可,如下图
image-20200412151349253.png

这时右上角会出现Sync Now 提示,点击这个提示,AndroidStudio会自动重新开始下载编译所需的库文件,现在要做的是等待下载编译完成即可,编译完成效果如下图:

image-20200412151637792.png
另外:如果之前项目就没有编译成功,加入阿里云镜像地址之后,可以点击右上角的:Sync Project按钮来启动编译(也就是那个大象图标)
image-20200412152000809.png
下面是整个buidle.gradle文件,方便大家复制
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        maven {url 'https://maven.aliyun.com/repository/jcenter'}
        maven {url 'https://maven.aliyun.com/repository/google'}
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        //国内最快的镜像源,没有之一
        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' }
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven { url 'https://dl.google.com/dl/android/maven2/' }
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

相关文章

网友评论

      本文标题:AndroidStudio中使用阿里云镜像仓库

      本文链接:https://www.haomeiwen.com/subject/rutbmhtx.html