解决gradle依赖库导致build变慢的问题,快速编译!

首先感谢原作者提供方法。

https://www.jianshu.com/p/ab1f5e5f5f5c

看看默认的Google官方依赖:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
由于会用到google的maven仓库,直接导致相关的依赖库无法下载

解决方法:

使用国内的阿里云镜像来代替google的。

mavenCentral镜像仓库地址

http://maven.aliyun.com/nexus/content/groups/public/

jentral镜像仓库地址

http://maven.aliyun.com/nexus/content/repositories/jcenter

google镜像仓库地址

http://maven.aliyun.com/nexus/content/repositories/google

所以将工程的根build.gradle修改如下:

buildscript {
    repositories {
//        mavenCentral()
//        jcenter()
//        google()
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    repositories {
//        mavenCentral()
//        jcenter()
//        google()
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }

你可能感兴趣的:(Android)