5

So, we updated to the latest version of the gradle plugin.

Since then my builds have become super-slow. The main culprit seems to be

compileDebugKotlin

which takes over 5 minutes as can be seen in the analyser enter image description here

The weird thing is that another person is getting much better times with exactly the same setup.

gradle.properties:

    # Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
#org.gradle.jvmargs=-Xmx1Fg536m
# Increase memory allotted to JVM
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8


# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true

#android.enableSeparateAnnotationProcessing=true
android.useAndroidX=true
android.enableJetifier=true
android.injected.testOnly = false
org.gradle.caching=true


org.gradle.daemon=true
# Enable Configure on demand
org.gradle.configureondemand=true

gradle-wrapper.properties

#Wed Jan 12 11:49:46 MSK 2022
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

project level build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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.3'
        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 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://github.com/WickeDev/stetho-realm/raw/master/maven-repo' }
        maven { url 'https://jitpack.io' }

        maven {
            url 'https://maven.wefi.com/repository/wefi-release-repo'
            artifactUrls 'https://maven.wefi.com/repository/wefi-release-repo'
        }
        configurations.all {
            resolutionStrategy {
                force 'org.xerial:sqlite-jdbc:3.34.0'
            }
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Kotlin settings enter image description here

I was using Kotlin plugin 1.6.10 but downgraded to 1.6.0 to match the other guy's version. Still no improvement.

The weird thing is that if we go back to the previous gradle it all works great. Super fast builds.

Edit: I am not asking WHY it is rebuilding that module. That I know. My question is why the build is taking such a ridiculous amount of time.

5
  • 1
    compileDebugKotlin task comes from the kotlin-gradle-plugin, which is not part of the Android Gradle plugin. You can add kotlin.build.report.enable=true, kotlin.build.report.verbose=true, kotlin.build.report.metrics=true to your gradle.properties file, and that should generated more information under $rootProject/build/repor, with breakdown of how time is spent during Kotlin compilation. Commented Feb 19, 2022 at 10:27
  • Problem is that all this gives me is what modules are causing the long build time and why they are being built. That I already know. The question is why something that took a few seconds suddenly takes 10 minutes.
    – theblitz
    Commented Feb 20, 2022 at 16:17
  • So what version were you using before, and which one is causing issues? Also, are you sure it's AGP that is causing your issues and not any other version update you made together?
    – romtsn
    Commented Feb 21, 2022 at 10:51
  • We were using 4.1.1. Try to go back to it also fails now with "unsupported class file major version 60"
    – theblitz
    Commented Feb 21, 2022 at 11:39
  • Tbh, it's hard to investigate, this definitely needs a reproducer from your side and probably worth reporting it to kotlin/google issue tracker if you think the problem is on their site.
    – romtsn
    Commented Feb 22, 2022 at 9:50

2 Answers 2

5

So, after much struggling I finally managed to fix the problem.

First, I made sure to update Kotlin to the latest version. This didn't actual fix it but it pointed me in the right direction. I checked my gradle file some more and noticed I was getting the warning "Kotlin plugin version is not the same as library version".

I found a thread about that here

I removed the following line from all build.gradle files:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

This solved my problem. My builds are now back to a minute or so.

-1

Add this line to gradle.properties:

kotlin.incremental.useClasspathSnapshot=true

Rebuild -> Modify code -> Rebuild to see the effects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.