I've been working with Android Studio (my current version 1.5) for 2 years. Everything was OK, but when I downloaded Canary (2.1 p5), everything went wrong. Every time I want to create a new project or open a project or sync or import a new lib or dependency, gradle is taking too long to build — nearly 20 min.
I did not do anything, I just downloaded the Canary version and ran it.
Symptoms :
Note: When I disconnect my Internet, gradle will finish as fast as possible
I tried to fix this by these ways:
I've created a new file (file name is gradle.properties
) in C:\Users\username\.gradle
then wrote these lines into it
org.gradle.parallel=true org.gradle.daemon=true
I removed that version then installed my old version which worked OK but the problem was still there :(
Disable / Enable firewall
Disable / Enable AntiVirus (Nod32)
Reinstall Windows OS (8.1)
I've downloaded all versions (1.0.0, ..., 1.5.1, 2.0.0, 2.1)
I've used a proxy
System info:
build.gradle(Project:appName)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
gradle.build(Module:app)
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.example.test.myapplication" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:23.3.0' }
Gradle report after building
Dependencies Duration All dependencies 14m3.43s :app:_releaseCompile 3m30.96s :app:_debugCompile 3m30.73s :app:_debugApk 3m30.69s :app:_releaseApk 3m30.62s :classpath 0.428s :app:_debugAndroidTestCompile 0.001s :app:_debugAndroidTestApk 0s :app:_debugUnitTestApk 0s :app:_debugUnitTestCompile 0s :app:_releaseUnitTestApk 0s :app:_releaseUnitTestCompile 0s :app:releaseWearApp 0s :app:wearApp 0s
After installing android studio 2.0 stable version
Check your Internet connection. If internet speed is very slow gradle build will also take long time to build. I check by change my wifi internet connection with another one good speed connection. Now build time is normal.
One is your RAM, as Gradle Build is a processor bound operation its speed depends on RAM specifications of the machine. Other reason and the most common one is that you have not updated your tools. Update your tools, dependencies, Gradle version. With the new gradle version, my gradle build takes less than a minute.
That is when two or more dependencies require a given dependency but with different versions. Implementation conflicts. That is when the dependency graph contains multiple modules that provide the same implementation, or capability in Gradle terminology.
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 :
classpath 'com.android.tools.build:gradle:2.0.0'
)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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With