theblitz
theblitz

Reputation: 6881

Latest version of Android gradle plugin causes super-slow build

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.

Upvotes: 5

Views: 4734

Answers (2)

Tran Chien
Tran Chien

Reputation: 629

Add this line to gradle.properties:

kotlin.incremental.useClasspathSnapshot=true

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

Upvotes: -1

theblitz
theblitz

Reputation: 6881

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.

Upvotes: 5

Related Questions