others-How to add mirrors to android studio gradle script to speed up the build process

1. The purpose of this post

If we can not access google or jcenter gradle repositories, we must wait for a long time for the completion of the grade build in android studio, in this article ,I would demo how to add aliyun mirrors to android studio’s gradle script to speedup the build process.

2. Change your project’s build.gradle

buildscript {

    repositories {

        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/public' }
        
        mavenLocal()

        google()
        jcenter()

    }
    dependencies {
          //change this version according to your project's settings
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

allprojects {
    repositories {

        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    
        mavenLocal()
        google()
        jcenter()
    }
}

3. Other settings

3.1 close your proxy in android studio

Goto Appearance&Behavior -> System Setting -> HTTP Proxy Change it to No Proxy;

3.2 Check your project’s gradle.properties

Check if you have disabled the proxy settings in project’s gradle.properties.

3.3 Clean your project if not work

  • build -> clean project; or
  • file -> invalidate caches / restart