Android build gradle is too slow (Dependency Resolution)
Once the initial build has completed try enabling offline Mode from the gradle settings. So that every consecutive builds will not start resolving dependencies, instead it gets from the cache. If you add a new dependency it will prompt you to disable offline mode and rebuild it.
You could optimize the gradle build process ...
Try to put the gradle on offline mode forcing to build without any connection to external repositories, like this:
This helped me a lot, because in my work, all connections are behind a proxy and it increase the build time.
If this is not enough for you, take a time testing the options on the Gradle > Experimental ... Some options may improve you performance:
Note: In newer version of Android studio, View->Tool Windows->Gradle->Toggle button of online/offline
The problem is solved !
After 2 days searching , I got the solution , so I would like to share with all people who may have the same problem. The problem is gradle
can not connect to center repository in some country. When you create a new project or import , your center repository is jcenter()
by default and whenever you want to build or sync or add new external dependency, gradle
is going to connect to https://bintray.com/ but it can not and the building process is going to wait till connect to jcenter()
, so this process might take long time ( +30 min ) , even you can not add new dependency .
Solution :
- Make sure you have latest stable version ( current 2.0.0 )
- Make sure your gradle version is 2.0.0 in build.gradle (
classpath 'com.android.tools.build:gradle:2.0.0'
) - Final step and most important one is change your jcenter() to mavenCentral()
So you can easily add new dependency and sync project under 3sec !
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Have Fun