Moeinh77
Moeinh77

Reputation: 377

Gradle is taking a long time to build

All of a sudden my gradle build has become really really slow seams like its doing some extra work that it didn't used to do here is a picture from build: unavailable

as you can see there are a lot of tasks here it used to be build in like 10 seconds now it takes minutes to build whats wrong with it? it writes things in the bottom bar like resolving some libraries for kotlin and doing something related to caching "variant attribute matching cache" here is the picture :unavailable

i was trying to activate the annotation processor that it happend here is my gradle codes:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.moein.volley_download_kotlin"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        javaCompileOptions{
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
     }
     buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
      }
    }

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

        implementation 'com.tonyodev.fetch2downloaders:fetch2downloaders:2.0.0-RC21'
        implementation 'com.android.volley:volley:1.1.0'

        implementation 'com.google.dagger:dagger:2.13'
        annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
        annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
    }

and the other code:

buildscript {
    ext.kotlin_version = '1.2.30'

    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

Upvotes: 1

Views: 7871

Answers (2)

Nolequen
Nolequen

Reputation: 4255

The "Improve the Performance of Gradle Builds" guide offers various strategies to optimize Gradle build performance.

Here are a few of the most effective ones, in my opinion, that might help in your case:

Use parallel execution

By default, Gradle runs tasks one-by-one. To execute tasks from different subprojects in parallel use the flag:

$ gradle <task> --parallel

or add the following setting to the gradle.properties file to execute tasks in parallel by default:

org.gradle.parallel=true

Enable the build cache to reuse outputs from previous builds

By default, Gradle does not utilize the build cache. To enable it, use the following:

$ gradle <task> --build-cache

or:

org.gradle.caching=true

in gradle.properties

Build cache can be configured in settings.gradle.

Increase the heap size

By default, Gradle allocates 512MB of heap space for the build. You can increase this allocation using a property:

org.gradle.jvmargs=-Xmx2048M

in gradle.properties file.

What else?

You can inspect your build to identify and fix performance bottlenecks.

Upvotes: 0

abdul rehman
abdul rehman

Reputation: 260

  • In gradle setting check work offline.
  • Clean and rebuild your project.
  • In gradle.properties in Gradle scripts directory(i.e., ~/.gradle/gradle.properties), add

        org.gradle.parallel=true
        org.gradle.daemon=true
    

This settings have helped me a lot.

Upvotes: 1

Related Questions