'Android build suddenly taking 10-15 minutes
I upgraded my gradle build tool to com.android.tools.build:gradle:7.0.4.
Since then my builds are taking 10-15 instead of seconds.
Also, I have updated my gradle itself. This is my gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
I am totally stuck. I have performed a clean and an invalidate cache to no avail.
One of the places it seems to get stuck is on
kaptGenerateStubsDebugKotlin
The relevant sections of my project level build.gradle:
buildscript {
ext.kotlin_version = "1.7.0"
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.google.gms:google-services:4.3.10'
classpath "io.realm:realm-gradle-plugin:6.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
}
}
Build analyser (the two biggest)
Solution 1:[1]
If you clean and invalidate caches, then gradle needs to rebuild those to complete the build. Once you have completed the build once, without making any further code changes, rebuild again.
When you rebuild this time, look at the list of tasks that were carried out. They should mostly report UP-TO-DATE. Some may say NO-SOURCE. Any that don't are tasks that needed to run.
This build should inevitably be quicker than the last.
You can then use either a gradle build scan or Android Studio build analyzer and see further details of what task needed to re-run.
Using build analyzer you can see some reasoning as to why the task needed to run.

I've seen lots of different reasons for tasks needing to run. Obviously if some source code changes, then it needs to recompile, but even things like changing the target device in Android Studio can be enough to trigger rebuilding.
Hope this helps you to understand what gradle is doing. Based on the details you have given in the question, there is not enough to determine the actual reason though.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris |



